use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class SseEventSinkToEventSourceTest method testWithJerseyApi.
@Test
public void testWithJerseyApi() throws InterruptedException {
final WebTarget endpoint = target().path("events");
final EventSource eventSource = EventSource.target(endpoint).build();
transmitLatch = new CountDownLatch(MSG_COUNT);
final CountDownLatch receiveLatch = new CountDownLatch(MSG_COUNT);
final List<Integer> results = new ArrayList<>();
final EventListener listener = inboundEvent -> {
try {
results.add(inboundEvent.readData(Integer.class));
receiveLatch.countDown();
Assert.assertEquals(INTEGER_SSE_NAME, inboundEvent.getName());
} catch (ProcessingException ex) {
throw new RuntimeException("Error when deserializing of data.", ex);
}
};
eventSource.register(listener, INTEGER_SSE_NAME);
eventSource.open();
Assert.assertTrue(transmitLatch.await(5000, TimeUnit.MILLISECONDS));
Assert.assertTrue(receiveLatch.await(5000, TimeUnit.MILLISECONDS));
Assert.assertEquals(10, results.size());
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class SseEventSinkToEventSourceTest method testWithEventSource.
@Test
public void testWithEventSource() throws InterruptedException {
transmitLatch = new CountDownLatch(2 * MSG_COUNT);
final WebTarget endpoint = target().path("events");
final SseEventSource eventSource = SseEventSource.target(endpoint).named("my-sse-eventsource1").build();
final CountDownLatch count1 = new CountDownLatch(3 * MSG_COUNT);
final CountDownLatch count2 = new CountDownLatch(3 * MSG_COUNT);
eventSource.subscribe(new InboundHandler("consumer1", count1));
eventSource.subscribe(new InboundHandler("consumer2", count2));
eventSource.open();
final boolean sent = transmitLatch.await(5 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS);
Assert.assertTrue("Awaiting for SSE message has timeout. Not all message were sent.", sent);
final boolean handled2 = count2.await(5 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS);
Assert.assertTrue("Awaiting for SSE message has timeout. Not all message were handled by eventSource2.", handled2);
final boolean handled1 = count1.await(5 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS);
Assert.assertTrue("Awaiting for SSE message has timeout. Not all message were handled by eventSource1.", handled1);
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class JaxRsInjectedCdiBeanTest method _testPathAndHeader.
public static void _testPathAndHeader(final WebTarget webTarget) {
final WebTarget target = webTarget.path("non-jaxrs-bean-injected");
final Response pathResponse = target.path("path/1").request().get();
assertThat(pathResponse.getStatus(), is(200));
final String path = pathResponse.readEntity(String.class);
assertThat(path, is("non-jaxrs-bean-injected/path/1"));
final Response headerResponse = target.path("header/1").request().header("x-test", "bummer").get();
assertThat(headerResponse.getStatus(), is(200));
final String header = headerResponse.readEntity(String.class);
assertThat(header, is("bummer"));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class PerRequestDependentBeanTest method testGet.
@Test
public void testGet() {
final WebTarget target = target().path("jcdibean/dependent/per-request").queryParam("x", x);
String s = target.request().get(String.class);
assertThat(s, containsString(target.getUri().toString()));
assertThat(s, containsString(String.format("queryParam=%s", x)));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class QualifiedInjectionSetGetTest method testSetGet.
@Test
public void testSetGet() {
final WebTarget factorTarget = target().path("stutter-service-factor");
final WebTarget stutterTarget = target().path("stutter");
factorTarget.request().put(Entity.text("3"));
final String shouldBeTrippled = stutterTarget.queryParam("s", "lincoln").request().get(String.class);
assertThat(shouldBeTrippled, is("lincolnlincolnlincoln"));
factorTarget.request().put(Entity.text("2"));
final String shouldBeDoubled = stutterTarget.queryParam("s", "lincoln").request().get(String.class);
assertThat(shouldBeDoubled, is("lincolnlincoln"));
}
Aggregations