Search in sources :

Example 16 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class HelloWorldTest method testLoggingFilterTargetClass.

@Test
public void testLoggingFilterTargetClass() {
    WebTarget target = target().path(ROOT_PATH);
    target.register(CustomLoggingFilter.class).property("foo", "bar");
    CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
    String s = target.request().get(String.class);
    assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
    assertEquals(1, CustomLoggingFilter.preFilterCalled);
    assertEquals(1, CustomLoggingFilter.postFilterCalled);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 17 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class ExceptionTest method test500StatusCode.

@Test
public void test500StatusCode() {
    startServer(ExceptionResource.class);
    Client client = ClientBuilder.newClient();
    WebTarget r = client.target(getUri().path("500").build());
    assertEquals(500, r.request().get(Response.class).getStatus());
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 18 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class ExceptionTest method test400StatusCode.

@Test
public void test400StatusCode() {
    startServer(ExceptionResource.class);
    Client client = ClientBuilder.newClient();
    WebTarget r = client.target(getUri().path("400").build());
    assertEquals(400, r.request().get(Response.class).getStatus());
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 19 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class LifecycleListenerTest method testReload.

@Test
public void testReload() {
    final ResourceConfig rc = new ResourceConfig(One.class);
    Reloader reloader = new Reloader();
    rc.registerInstances(reloader);
    startServer(rc);
    WebTarget r = ClientBuilder.newClient().target(getUri().path("/").build());
    assertEquals("one", r.path("one").request().get(String.class));
    assertEquals(404, r.path("two").request().get(Response.class).getStatus());
    // add Two resource
    reloader.reload(new ResourceConfig(One.class, Two.class));
    assertEquals("one", r.path("one").request().get(String.class));
    assertEquals("two", r.path("two").request().get(String.class));
}
Also used : ResourceConfig(org.glassfish.jersey.server.ResourceConfig) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 20 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class NoEntityTest method testGet.

@Test
public void testGet() {
    WebTarget r = target("test");
    for (int i = 0; i < 5; i++) {
        Response cr = r.request().get();
        cr.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

WebTarget (javax.ws.rs.client.WebTarget)591 Test (org.junit.Test)489 JerseyTest (org.glassfish.jersey.test.JerseyTest)297 Response (javax.ws.rs.core.Response)278 Client (javax.ws.rs.client.Client)98 ClientConfig (org.glassfish.jersey.client.ClientConfig)45 GenericType (javax.ws.rs.core.GenericType)35 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 List (java.util.List)23 InputStream (java.io.InputStream)22 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)21 ProcessingException (javax.ws.rs.ProcessingException)19 URI (java.net.URI)18 Properties (java.util.Properties)18 TestProperties (org.glassfish.jersey.test.TestProperties)18 MediaType (javax.ws.rs.core.MediaType)15 Invocation (javax.ws.rs.client.Invocation)13 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)13