Search in sources :

Example 6 with Configuration

use of jakarta.ws.rs.core.Configuration in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method checkConfig.

protected void checkConfig(Registrar registrar, Assertable assertable, Object[] registerables) throws Fault {
    Client client = ClientBuilder.newClient();
    Configuration config = client.getConfiguration();
    registeredClassesCnt = config.getClasses().size();
    registeredInstancesCnt = config.getInstances().size();
    logMsg("Already registered", registeredClassesCnt, "classes");
    logMsg("Already registered", registeredInstancesCnt, "instances");
    register(registrar, client, registerables[0]);
    assertable.check1OnClient(client);
    assertable.incrementLocation();
    WebTarget target = client.target("http://tck.cts:888");
    register(registrar, target, registerables[1]);
    assertable.check2OnTarget(target);
    assertable.incrementLocation();
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

Example 7 with Configuration

use of jakarta.ws.rs.core.Configuration 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)

Example 8 with Configuration

use of jakarta.ws.rs.core.Configuration 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 9 with Configuration

use of jakarta.ws.rs.core.Configuration 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 10 with Configuration

use of jakarta.ws.rs.core.Configuration in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getInstancesIsImmutableTest.

/*
     * @testName: getInstancesIsImmutableTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:994; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: Get the immutable set of registered provider instances to be
     * utilized by the configurable instance.
     * 
     * Register a provider ("singleton") instance
     */
@Test
public void getInstancesIsImmutableTest() throws Fault {
    Assertable assertable = new SingleCheckAssertable() {

        @Override
        protected void check(Configurable<?> configurable) throws Fault {
            registerNewProviderInstance(configurable.getConfiguration());
            assertSizeAndLog(configurable.getConfiguration(), 0);
        }

        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");
        }

        void registerNewProviderInstance(Configuration config) {
            try {
                config.getInstances().add(new CallableProvider());
            } 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 : SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) 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) Configurable(jakarta.ws.rs.core.Configurable) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (jakarta.ws.rs.core.Configuration)21 Client (jakarta.ws.rs.client.Client)19 WebTarget (jakarta.ws.rs.client.WebTarget)17 Test (org.junit.jupiter.api.Test)17 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)16 Assertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable)13 SingleCheckAssertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable)13 CallableProvider (ee.jakarta.tck.ws.rs.api.rs.core.configurable.CallableProvider)4 JaxrsCommonClient (ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient)3 Configurable (jakarta.ws.rs.core.Configurable)3 ConfigurableObject (ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject)2 Invocation (jakarta.ws.rs.client.Invocation)2 StringBeanEntityProvider (ee.jakarta.tck.ws.rs.common.provider.StringBeanEntityProvider)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 Response (jakarta.ws.rs.core.Response)1