Search in sources :

Example 16 with WebTarget

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

the class JAXRSClientIT method matrixParamOnTwoSegmentsTest.

/*
   * @testName: matrixParamOnTwoSegmentsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:610; JAXRS:JAVADOC:612;
   * 
   * @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. Note that the matrix parameters are
   * tied to a particular path segment; appending a value to an existing matrix
   * parameter name will not affect the position of the matrix parameter in the
   * URI path.
   * 
   * Create a new instance by appending path to the URI of the current target
   * instance.
   */
@Test
public void matrixParamOnTwoSegmentsTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.matrixParam("matrix1", "segment1");
    assertConfigurationSnapshot(target);
    target = target.path("path");
    assertConfigurationSnapshot(target);
    target = target.matrixParam("matrix2", "segment2");
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, ";matrix1=segment1/path;matrix2=segment2");
    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)

Example 17 with WebTarget

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

the class JAXRSClientIT method resolveTemplateFromEncodedTest.

/*
   * @testName: resolveTemplateFromEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:944;
   * 
   * @test_Strategy: Create a new WebTarget instance by resolving a URI template
   * with a given name in the URI of the current target instance using a
   * supplied encoded value. A template with a matching name will be replaced by
   * the supplied value. Value is converted to String using its toString()
   * method and is then encoded to match the rules of the URI component to which
   * they pertain. All % characters in the stringified values that are not
   * followed by two hexadecimal numbers will be encoded.
   */
@Test
public void resolveTemplateFromEncodedTest() throws Fault {
    WebTarget target = createWebTarget();
    StringBuilder sb = new StringBuilder();
    sb.append(ENCODED);
    target = target.path("{path}").resolveTemplateFromEncoded("path", sb);
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, "/" + ENCODED.replace("%%", "%25%"));
    logMsg("URI", uri, "contains given path parameter");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 18 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(ClientRequestFilter requestFilter, ContextProvider... providers) {
    Client client = ClientBuilder.newClient();
    client.register(requestFilter);
    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 19 with WebTarget

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

the class JAXRSClientIT method requestNoArgTest.

/*
   * @testName: requestNoArgTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:622;
   * 
   * @test_Strategy: Start building a request to the targeted web resource.
   */
@Test
public void requestNoArgTest() throws Fault {
    WebTarget target = createWebTarget();
    Response response = target.request().buildGet().invoke();
    String body = response.readEntity(String.class);
    assertContains(body, URL);
    assertContains(body, MediaType.WILDCARD);
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 20 with WebTarget

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

the class JAXRSClientIT method resolveTemplateTest.

/*
   * @testName: resolveTemplateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:940;
   * 
   * @test_Strategy: Create a new instance by resolving a URI template with a
   * given name in the URI of the current target instance using a supplied
   * value. In case a template name or value is entered a NullPointerException
   * is thrown. 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 resolveTemplateTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.path("{path}").resolveTemplate("path", "lane");
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, "/lane");
    logMsg("URI", uri, "contains given path parameter");
}
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