Search in sources :

Example 61 with WebTarget

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

the class JAXRSClientIT method getPropertyTest.

/*
     * @testName: getPropertyTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:996; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: Get the value for the property with a given name. Set the new
     * configuration property
     */
@Test
public void getPropertyTest() throws Fault {
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            assertPropertyIsSet(client.getConfiguration(), "property0");
            logMsg("Found", client.getConfiguration().getProperty("property0"));
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            assertPropertyIsSet(target.getConfiguration(), "property0");
            assertPropertyIsSet(target.getConfiguration(), "property1");
            logMsg("Found", target.getConfiguration().getProperty("property1"));
        }

        void assertPropertyIsSet(Configuration config, String property) throws Fault {
            assertTrue(config.getProperty(property).equals(property), "config.setProperty() did not set anything: " + getLocation());
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) 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)

Example 62 with WebTarget

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

the class JAXRSClientIT method getPropertyNamesTest.

/*
     * @testName: getPropertyNamesTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:997;
     * 
     * @test_Strategy: Returns an immutable collection containing the property names
     * available within the context of the current configuration instance.
     */
@Test
public void getPropertyNamesTest() throws Fault {
    Assertable assertable = new Assertable() {

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

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

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            int names = config.getPropertyNames().size();
            assertEqualsInt(names, size + registeredPropertiesCnt, "getPropertyNames() is unexpected", getLocation(), "got", names, "properties");
            logMsg("Found", names, "properties");
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) 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)

Example 63 with WebTarget

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

the class JAXRSClientIT method getPropertiesTest.

/*
     * @testName: getPropertiesTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:995; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: Get the immutable bag of configuration properties. Set the
     * new configuration property
     */
@Test
public void getPropertiesTest() throws Fault {
    Assertable assertable = new Assertable() {

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

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

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            int pSize = config.getProperties().size();
            assertEqualsInt(pSize, size + registeredPropertiesCnt, "getConfiguration().getProperties() is not unexpected", getLocation(), "got", pSize, "properties");
            logMsg("Found", pSize, "properties");
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) 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)

Example 64 with WebTarget

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

the class JAXRSClientIT method getClassesTest.

/*
     * @testName: getClassesTest
     * 
     * @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 getClassesTest() throws Fault {
    Assertable assertable = new Assertable() {

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

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

        void assertSizeAndLog(Configuration config, int count) throws Fault {
            assertTrue(config.getClasses().size() == count + registeredClassesCnt, "config.getClasses() return unexcepted size " + getLocation() + " : " + config.getClasses().size());
            logMsg("Found", config.getClasses().size(), "providers");
        }
    };
    Class<?>[] providerClasses = new Class[] { CallableProvider1.class, CallableProvider2.class };
    checkConfig(assertable, providerClasses);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) 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)

Example 65 with WebTarget

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

the class JAXRSClientIT method isRegisteredProviderRegisteredClassTest.

/*
     * @testName: isRegisteredProviderRegisteredClassTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1001; JAXRS:JAVADOC:1002;
     * 
     * @test_Strategy: Check if a particular JAX-RS component instance (such as
     * providers or features) has been previously registered in the runtime
     * configuration context.
     */
@Test
public void isRegisteredProviderRegisteredClassTest() throws Fault {
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            client.register(CallableProvider1.class);
            assertSizeAndLog(client.getConfiguration(), 1);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            target.register(CallableProvider2.class);
            assertSizeAndLog(target.getConfiguration(), 2);
        }

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            assertFalse(config.isRegistered(new CallableProvider()), "CallableProvider is unexpectedly registered");
            assertFalse(config.isRegistered(CallableProvider.class), "CallableProvider is unexpectedly registered");
            switch(size) {
                case 2:
                    assertFalse(config.isRegistered(new CallableProvider2()), "CallableProvider2 is registered " + getLocation());
                    assertTrue(config.isRegistered(CallableProvider2.class), "CallableProvider2.class is NOT registered " + getLocation());
                    logMsg("Found registered CallableProvider2 as expected", getLocation());
                case 1:
                    assertFalse(config.isRegistered(new CallableProvider1()), "CallableProvider1 is registered " + getLocation());
                    assertTrue(config.isRegistered(CallableProvider1.class), "CallableProvider1.class is NOT registered " + getLocation());
                    logMsg("Found registered CallableProvider1 as expected", getLocation());
            }
        }
    };
    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