Search in sources :

Example 11 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 12 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);
    Client client = ClientBuilder.newClient();
    WebTarget r = client.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) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 13 with WebTarget

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

the class LifecycleListenerTest method testStartupShutdownHooks.

@Test
public void testStartupShutdownHooks() {
    final StartStopListener listener = new StartStopListener();
    startServer(new ResourceConfig(One.class).register(listener));
    Client client = ClientBuilder.newClient();
    WebTarget r = client.target(getUri().path("/").build());
    assertThat(r.path("one").request().get(String.class), equalTo("one"));
    assertThat(r.path("two").request().get(Response.class).getStatus(), equalTo(404));
    stopServer();
    assertTrue("ContainerLifecycleListener.onStartup has not been called.", listener.started);
    assertTrue("ContainerLifecycleListener.onShutdown has not been called.", listener.stopped);
}
Also used : ResourceConfig(org.glassfish.jersey.server.ResourceConfig) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 14 with WebTarget

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

the class JdkHttpPackageTest method testJdkHttpPackage.

@Test
public void testJdkHttpPackage() {
    final ResourceConfig rc = new ResourceConfig();
    rc.packages(this.getClass().getPackage().getName());
    startServer(rc);
    WebTarget r = ClientBuilder.newClient().target(getUri().path("/").build());
    assertEquals("test", r.path("packageTest").request().get(String.class));
    assertEquals("test-sub", r.path("packageTest/sub").request().get(String.class));
    assertEquals(404, r.path("wrong").request().get(Response.class).getStatus());
}
Also used : ResourceConfig(org.glassfish.jersey.server.ResourceConfig) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 15 with WebTarget

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

the class HelloWorldTest method testLoggingFilterTargetInstance.

@Test
public void testLoggingFilterTargetInstance() {
    WebTarget target = target().path(ROOT_PATH);
    target.register(new CustomLoggingFilter()).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)

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