Search in sources :

Example 56 with WebTarget

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

the class JAXRSClientIT method resolveTemplateWithBooleanFalseTest.

/*
   * @testName: resolveTemplateWithBooleanFalseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:942;
   * 
   * @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.
   * 
   * if true, the slash ('/') characters in template values will be encoded if
   * the template is placed in the URI path component, otherwise the slash
   * characters will not be encoded in path templates.
   */
@Test
public void resolveTemplateWithBooleanFalseTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.path("{path}").resolveTemplate("path", ENCODED, false);
    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 57 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesFromEncodedReturnsTheSameTargetTest.

/*
   * @testName: resolveTemplatesFromEncodedReturnsTheSameTargetTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:950;
   * 
   * @test_Strategy: A call to the method with an empty parameter map is
   * ignored, i.e. same WebTarget instance is returned.
   */
@Test
public void resolveTemplatesFromEncodedReturnsTheSameTargetTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.path("{path}");
    WebTarget other = target.resolveTemplatesFromEncoded(new TreeMap<String, Object>());
    assertEquals(target, other, "#pathParams did not return the same target when the input map is empty");
    logMsg("#pathParams returned the same traget wehn empty as expected");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 58 with WebTarget

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

the class JAXRSClientIT method getUriBuilderTest.

/*
   * @testName: getUriBuilderTest
   * 
   * @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 getUriBuilderTest() throws Fault {
    WebTarget target = createWebTarget();
    URI uri = target.getUriBuilder().build();
    assertContains(uri.toASCIIString(), URL);
    logMsg("URI", uri, "contains", URL);
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 59 with WebTarget

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

the class JAXRSClientIT method createWebTarget.

protected WebTarget createWebTarget() throws Fault {
    Client client = ClientBuilder.newClient();
    client.register(FILTER);
    WebTarget target = client.target(URL);
    assertConfigurationSnapshot(target);
    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 60 with WebTarget

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

the class JAXRSClientIT method getClassesIsImmutableTest.

/*
     * @testName: getClassesIsImmutableTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:992; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: Get the immutable set of registered provider classes to be
     * instantiated, injected and utilized in the scope of the configured instance.
     * A provider class is a Java class with a jakarta.ws.rs.ext.Provider annotation
     * declared on the class that implements a specific service interface.
     *
     * Register a provider class to be instantiated
     */
@Test
public void getClassesIsImmutableTest() throws Fault {
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            assertSizeAndLog(client.getConfiguration(), 0);
            registerNewProviderInstance(client.getConfiguration());
            assertSizeAndLog(client.getConfiguration(), 0);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            registerNewProviderInstance(target.getConfiguration());
            assertSizeAndLog(target.getConfiguration(), 0);
        }

        void assertSizeAndLog(Configuration config, int count) throws Fault {
            if (config.getClasses().size() == 1)
                logMsg("Found", config.getClasses().iterator().next());
            assertTrue(config.getClasses().size() == count + registeredClassesCnt, "config.getClasses() return unexcepted size " + getLocation() + " : " + config.getClasses().size());
            logMsg("Found", config.getClasses().size(), "providers");
        }

        void registerNewProviderInstance(Configuration config) {
            Class<?> clz = CallableProvider.class;
            try {
                config.getClasses().add(clz);
            } catch (Exception e) {
            // can throw exception or do nothing
            // when adding to this immutable set
            // or it can be a new hard copied set
            }
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) CallableProvider(ee.jakarta.tck.ws.rs.api.rs.core.configurable.CallableProvider) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) 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