View Javadoc

1   package it.com.atlassian.rest.error;
2   
3   import com.atlassian.plugins.rest.common.Status;
4   import com.atlassian.rest.jersey.client.WebResourceFactory;
5   import com.sun.jersey.api.client.UniformInterfaceException;
6   import com.sun.jersey.api.client.WebResource;
7   
8   import static org.junit.Assert.*;
9   
10  import org.junit.Before;
11  import org.junit.Test;
12  
13  import javax.ws.rs.core.Response;
14  
15  public class ErrorPagesTest {
16      private WebResource webResource;
17  
18      @Before
19      public void setUp() {
20          webResource = WebResourceFactory.authenticated();
21      }
22  
23      @Test
24      public void testNotFoundReturns404() {
25          try {
26              webResource.path("somepaththatdoesntexist").get(Object.class);
27              fail("This should have thrown an exception as the page doesn't exists");
28          } catch (UniformInterfaceException e) {
29              assertEquals(Response.Status.NOT_FOUND, e.getResponse().getResponseStatus());
30              assertEquals(Response.Status.NOT_FOUND.getStatusCode(), e.getResponse().getEntity(Status.class).getCode());
31          }
32      }
33  }