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());
}
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));
}
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);
}
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());
}
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);
}
Aggregations