Search in sources :

Example 71 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method resolveTemplatesWithBooleanTrueTest.

/*
   * @testName: resolveTemplatesWithBooleanTrueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:948;
   * 
   * @test_Strategy: Create a new WebTarget instance by resolving one or more
   * URI templates in the URI of the current target instance using supplied
   * name-value pairs. A call to the method with an empty parameter map is
   * ignored, i.e. same WebTarget instance is returned. A snapshot of the
   * present configuration of the current (parent) target instance is taken and
   * is inherited by the newly constructed (child) target instance.
   */
@Test
public void resolveTemplatesWithBooleanTrueTest() throws Fault {
    Map<String, Object> map = new TreeMap<String, Object>();
    map.put("path", new StringBuilder().append("lane"));
    map.put("highway", new StringBuffer().append("route66"));
    map.put("sidewalk", SLASHED);
    WebTarget target = createWebTarget();
    target = target.path("{path}").path("{highway}").path("{sidewalk}");
    target = target.resolveTemplates(map, true);
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, "/lane/route66/" + SLASHED.replace("%", "%25").replace("/", "%2F"));
    logMsg("URI", uri, "contains given path parameters");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) TreeMap(java.util.TreeMap) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 72 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method resolveTemplatesWithBooleanNullNameTest.

/*
   * @testName: resolveTemplatesWithBooleanNullNameTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:948;
   * 
   * @test_Strategy: NullPointerException - if the name-value map or any of the
   * names or values in the map is null.
   */
@Test
public void resolveTemplatesWithBooleanNullNameTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(null, "xyz");
    WebTarget target = createWebTarget();
    try {
        target.path("{path}").resolveTemplates(map, false);
        throw new Fault("NullPointerException has not been thrown");
    } catch (NullPointerException npe) {
        logMsg("NullPointerException has been thrown as expected", npe);
    }
}
Also used : HashMap(java.util.HashMap) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 73 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method resolveTemplatesFromEncodedThrowsNPEForNullValueTest.

/*
   * @testName: resolveTemplatesFromEncodedThrowsNPEForNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:950;
   * 
   * @test_Strategy: NullPointerException - if the name-value map or any of the
   * names or encoded values in the map is null.
   */
@Test
public void resolveTemplatesFromEncodedThrowsNPEForNullValueTest() throws Fault {
    WebTarget target = createWebTarget();
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("path", null);
    try {
        target.path("{path}").resolveTemplatesFromEncoded(map);
        throw new Fault("NullPointerException has not been thrown");
    } catch (NullPointerException npe) {
        logMsg("NullPointerException has been thrown as expected", npe);
    }
}
Also used : HashMap(java.util.HashMap) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 74 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method invokeWithClientRequestFilters.

// ////////////////////////////////////////////////////////////////////
protected Response invokeWithClientRequestFilters(ClientRequestFilter... filters) {
    Client client = ClientBuilder.newClient();
    for (ClientRequestFilter filter : filters) client.register(filter);
    WebTarget target = client.target("http://nourl/");
    Response response = target.request().buildGet().invoke();
    return response;
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

Example 75 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method hasEntityTest.

/*
   * @testName: hasEntityTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:448; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Check if there is an entity available in the request. The
   * method returns true if the entity is present, returns false otherwise.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void hasEntityTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            boolean has = context.hasEntity();
            String entity = String.valueOf(has);
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildInvocation(provider);
    Response response = invoke(invocation);
    String body = response.readEntity(String.class);
    assertContains(body, "false");
    Entity<String> entity = createEntity("TEST");
    WebTarget target = buildTarget(provider);
    invocation = target.request().buildPost(entity);
    response = invoke(invocation);
    body = response.readEntity(String.class);
    assertContains(body, "true");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Aggregations

WebTarget (jakarta.ws.rs.client.WebTarget)96 Test (org.junit.jupiter.api.Test)63 Client (jakarta.ws.rs.client.Client)52 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)27 Response (jakarta.ws.rs.core.Response)24 Configuration (jakarta.ws.rs.core.Configuration)17 URI (java.net.URI)17 Invocation (jakarta.ws.rs.client.Invocation)16 Assertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable)14 SingleCheckAssertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable)14 JaxrsCommonClient (ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient)14 HashMap (java.util.HashMap)8 JdkLoggingFilter (ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter)6 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)5 InboundSseEvent (jakarta.ws.rs.sse.InboundSseEvent)5 SseEventSource (jakarta.ws.rs.sse.SseEventSource)5 ConfigurableObject (ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject)4 LinkedHolder (ee.jakarta.tck.ws.rs.common.util.LinkedHolder)4 Configurable (jakarta.ws.rs.core.Configurable)4 ThrottledClient (jaxrs.examples.client.custom.ThrottledClient)4