Search in sources :

Example 11 with WebTarget

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

the class JAXRSClientIT method buildTarget.

protected static WebTarget buildTarget(ContextProvider... providers) {
    Client client = ClientBuilder.newClient();
    for (ContextProvider provider : providers) client.register(provider);
    WebTarget target = client.target(getUrl());
    return target;
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

Example 12 with WebTarget

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

the class JAXRSClientIT method getUriBuilderIsDetachedTest.

/*
   * @testName: getUriBuilderIsDetachedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:609;
   * 
   * @test_Strategy: Get the URI builder initialized with the URI of the current
   * resource target. The returned URI builder is detached from the target, i.e.
   * any updates in the URI builder MUST NOT have any effects on the URI of the
   * originating target.
   */
@Test
public void getUriBuilderIsDetachedTest() throws Fault {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(URL);
    UriBuilder builder = target.getUriBuilder();
    // The way to affect original target
    client.close();
    URI uri = builder.build();
    assertContains(uri.toASCIIString(), URL);
    logMsg("URI", uri, "contains", URL);
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 13 with WebTarget

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

the class JAXRSClientIT method requestMediaTypeTest.

/*
   * @testName: requestMediaTypeTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:624;
   * 
   * @test_Strategy: Start building a request to the targeted web resource and
   * define the accepted response media types.
   */
@Test
public void requestMediaTypeTest() throws Fault {
    WebTarget target = createWebTarget();
    Response response = target.request(MediaType.APPLICATION_ATOM_XML_TYPE, MediaType.APPLICATION_JSON_TYPE, MediaType.TEXT_XML_TYPE).buildGet().invoke();
    String body = response.readEntity(String.class);
    assertContains(body, URL);
    assertContains(body, MediaType.APPLICATION_ATOM_XML);
    assertContains(body, MediaType.APPLICATION_JSON);
    assertContains(body, MediaType.TEXT_XML);
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 14 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesTest.

/*
   * @testName: resolveTemplatesTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:946;
   * 
   * @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 resolveTemplatesTest() 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", "pavement");
    WebTarget target = createWebTarget();
    target = target.path("{path}").path("{highway}").path("{sidewalk}");
    target = target.resolveTemplates(map);
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, "/lane/route66/pavement");
    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 15 with WebTarget

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

the class JAXRSClientIT method matrixParamTest.

/*
   * @testName: matrixParamTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:610;
   * 
   * @test_Strategy: Create a new instance by appending a matrix parameter to
   * the existing set of matrix parameters of the current final segment of the
   * URI of the current target instance. If multiple values are supplied the
   * parameter will be added once per value.
   */
@Test
public void matrixParamTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.matrixParam("matrix", "arg1", "arg2", "arg3");
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertContains(uri.toASCIIString(), ";matrix=arg1");
    assertContains(uri.toASCIIString(), ";matrix=arg2");
    assertContains(uri.toASCIIString(), ";matrix=arg3");
    logMsg("URI", uri, "contains given matrix params");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) 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