Search in sources :

Example 36 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class ExceptionViewProcessorTest method testResolvingClassExplicitTemplate.

@Test
public void testResolvingClassExplicitTemplate() throws IOException {
    final Invocation.Builder request = target("/").request("application/wrong-media-type");
    Response cr = request.get(Response.class);
    assertEquals(406, cr.getStatus());
    Properties p = new Properties();
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest/WebAppExceptionMapper/406.testp", p.getProperty("path"));
    assertEquals("406", p.getProperty("model"));
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) Properties(java.util.Properties) TestProperties(org.glassfish.jersey.test.TestProperties) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 37 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class ExceptionViewProcessorTest method testAbsoluteExplicitTemplate.

@Test
public void testAbsoluteExplicitTemplate() throws IOException {
    final Invocation.Builder request = target("/does-not-exist").request();
    Response cr = request.get(Response.class);
    assertEquals(404, cr.getStatus());
    Properties p = new Properties();
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest/404.testp", p.getProperty("path"));
    assertEquals("404", p.getProperty("model"));
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) Properties(java.util.Properties) TestProperties(org.glassfish.jersey.test.TestProperties) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 38 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class EventListenerTest method testApplicationEvents.

@Test
public void testApplicationEvents() {
    assertNotNull(applicationEventListener.appEventInitStart);
    assertNotNull(applicationEventListener.appEventInitFinished);
    assertEquals(APPLICATION_NAME, applicationEventListener.appEventInitStart.getResourceConfig().getApplicationName());
    assertNull(applicationEventListener.newRequestEvent);
    final Response response = target().path("resource").request().get();
    assertEquals(200, response.getStatus());
    assertNotNull(applicationEventListener.newRequestEvent);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 39 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class EventListenerTest method testMatchedMethod.

@Test
public void testMatchedMethod() {
    final Response response = target().path("resource").request().get();
    assertEquals(200, response.getStatus());
    assertEquals("get", response.readEntity(String.class));
    assertEquals("[getMethod]", response.getHeaderString("R.RESOURCE_METHOD_START.method"));
    assertEquals("[ok]", response.getHeaderString("R.RESOURCE_METHOD_FINISHED"));
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 40 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class EventListenerTest method testAsyncProcessingWithOneThread.

@Test
public void testAsyncProcessingWithOneThread() throws InterruptedException {
    final Response response = target().path("resource/asyncOneThread").request().get();
    assertEquals(200, response.getStatus());
    assertEquals("async", response.readEntity(String.class));
    int i = 1;
    System.out.println(response.getHeaders());
    assertEquals("[" + i++ + "]", response.getHeaderString("R.REQ_FILTERS_START.order"));
    assertEquals("[" + i++ + "]", response.getHeaderString("R.REQ_FILTERS_FINISHED.order"));
    assertEquals("[" + i++ + "]", response.getHeaderString("R.RESOURCE_METHOD_START.order"));
    assertEquals("[" + i++ + "]", response.getHeaderString("R.RESP_FILTERS_START.order"));
    assertEquals("[" + i + "]", response.getHeaderString("R.RESP_FILTERS_FINISHED.order"));
    final boolean success = applicationEventListener.finishedCalled.await(3 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS);
    Assert.assertTrue(success);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)10205 Test (org.junit.Test)5764 Test (org.testng.annotations.Test)1113 JerseyTest (org.glassfish.jersey.test.JerseyTest)870 Test (org.junit.jupiter.api.Test)701 WebTarget (javax.ws.rs.client.WebTarget)668 Builder (javax.ws.rs.client.Invocation.Builder)638 WebClient (org.apache.cxf.jaxrs.client.WebClient)620 DBUnitTest (org.orcid.test.DBUnitTest)611 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)577 Parameters (org.testng.annotations.Parameters)537 URI (java.net.URI)515 HashMap (java.util.HashMap)508 Path (javax.ws.rs.Path)506 List (java.util.List)465 ArrayList (java.util.ArrayList)419 Produces (javax.ws.rs.Produces)396 IOException (java.io.IOException)393 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)354 GET (javax.ws.rs.GET)348