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   import static org.junit.Assert.*;
8   import org.junit.Before;
9   import org.junit.Test;
10  
11  import javax.ws.rs.core.Response;
12  
13  public class ErrorPagesTest
14  {
15      private WebResource webResource;
16  
17      @Before
18      public void setUp()
19      {
20          webResource = WebResourceFactory.authenticated();
21      }
22  
23      @Test
24      public void testNotFoundReturns404()
25      {
26          try
27          {
28              webResource.path("somepaththatdoesntexist").get(Object.class);
29              fail("This should have thrown an exception as the page doesn't exists");
30          }
31          catch (UniformInterfaceException e)
32          {
33              assertEquals(Response.Status.NOT_FOUND, e.getResponse().getResponseStatus());
34              assertEquals(Response.Status.NOT_FOUND.getStatusCode(), e.getResponse().getEntity(Status.class).getCode());
35          }
36      }
37  }