Search in sources :

Example 26 with WebTarget

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

the class JerseyWebTargetTest method testResolveTemplatesEmptyMap.

@Test
public void testResolveTemplatesEmptyMap() {
    WebTarget wt = target;
    wt = wt.resolveTemplates(Collections.<String, Object>emptyMap());
    assertEquals(target, wt);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 27 with WebTarget

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

the class JerseyWebTargetTest method testResolveTemplatesEncodeSlashEmptyMap.

@Test
public void testResolveTemplatesEncodeSlashEmptyMap() {
    WebTarget wt = target;
    wt = wt.resolveTemplates(Collections.<String, Object>emptyMap(), false);
    assertEquals(target, wt);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 28 with WebTarget

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

the class JerseyWebTargetTest method testResolveTemplateNull1.

@Test(expected = NullPointerException.class)
public void testResolveTemplateNull1() {
    WebTarget wt = target;
    wt.resolveTemplate(null, "", true);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 29 with WebTarget

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

the class ShutdownHookLeakTest method testShutdownHookDoesNotLeak.

@SuppressWarnings("unchecked")
@Test
public void testShutdownHookDoesNotLeak() throws Exception {
    final Client client = ClientBuilder.newClient();
    final WebTarget target = client.target("http://example.com");
    final Collection shutdownHooks = getShutdownHooks(client);
    for (int i = 0; i < ITERATIONS; i++) {
        // Create/Initialize client runtime.
        target.property("Washington", "Irving").request().property("how", "now").buildGet().property("Irving", "Washington");
    }
    System.gc();
    int notEnqueued = 0;
    int notNull = 0;
    for (final Object o : shutdownHooks) {
        if (((WeakReference<JerseyClient.ShutdownHook>) o).get() != null) {
            notNull++;
        }
        if (!((WeakReference<JerseyClient.ShutdownHook>) o).isEnqueued()) {
            notEnqueued++;
        }
    }
    assertThat("Non-null shutdown hook references count should not copy number of property invocation", // 66 % seems like a reasonable threshold for this test to keep it stable
    notNull, is(lessThan(THRESHOLD)));
    assertThat("Shutdown hook references count not enqueued in the ReferenceQueue should not copy number of property invocation", // 66 % seems like a reasonable threshold for this test to keep it stable
    notEnqueued, is(lessThan(THRESHOLD)));
}
Also used : Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 30 with WebTarget

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

the class WebTargetPropertiesTest method testPropagation.

@Test
public void testPropagation() {
    Client c = ClientBuilder.newBuilder().newClient();
    c.property("a", "val");
    WebTarget w1 = c.target("http://a");
    w1.property("b", "val");
    WebTarget w2 = w1.path("c");
    w2.property("c", "val");
    assertTrue(c.getConfiguration().getProperties().containsKey("a"));
    assertTrue(w1.getConfiguration().getProperties().containsKey("a"));
    assertTrue(w2.getConfiguration().getProperties().containsKey("a"));
    assertFalse(c.getConfiguration().getProperties().containsKey("b"));
    assertTrue(w1.getConfiguration().getProperties().containsKey("b"));
    assertTrue(w2.getConfiguration().getProperties().containsKey("b"));
    assertFalse(c.getConfiguration().getProperties().containsKey("c"));
    assertFalse(w1.getConfiguration().getProperties().containsKey("c"));
    assertTrue(w2.getConfiguration().getProperties().containsKey("c"));
    w2.property("a", null);
    assertTrue(c.getConfiguration().getProperties().containsKey("a"));
    assertTrue(w1.getConfiguration().getProperties().containsKey("a"));
    assertFalse(w2.getConfiguration().getProperties().containsKey("a"));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) 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