Search in sources :

Example 1 with Assertable

use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method isRegisteredProviderRegisteredInstanceTest.

/*
     * @testName: isRegisteredProviderRegisteredInstanceTest
     * 
     * @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.
     * 
     * Method returns true only in case an instance equal to the component instance
     * is already present among the components previously registered in the
     * configuration context.
     */
@Test
public void isRegisteredProviderRegisteredInstanceTest() throws Fault {
    Assertable assertable = new Assertable() {

        CallableProvider1 p1 = new CallableProvider1();

        CallableProvider2 p2 = new CallableProvider2();

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

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

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            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(p2), "CallableProvider2.class is NOT 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(p1), "CallableProvider1.class is NOT 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)

Example 2 with Assertable

use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getRuntimeTypeTest.

/*
     * @testName: getRuntimeTypeTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:998;
     * 
     * @test_Strategy: Get the runtime type of this configuration context.
     */
@Test
public void getRuntimeTypeTest() throws Fault {
    Assertable assertable = new SingleCheckAssertable() {

        void assertNotNullAndLog(Configurable<?> config) throws Fault {
            assertEquals(RuntimeType.CLIENT, config.getConfiguration().getRuntimeType(), "getRuntimeType() is unexpected", config.getConfiguration().getRuntimeType(), getLocation());
            logMsg("#getRuntimeType() is", RuntimeType.CLIENT, "as expected", getLocation());
        }

        @Override
        protected void check(Configurable<?> configurable) throws Fault {
            assertNotNullAndLog(configurable);
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) 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)

Example 3 with Assertable

use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getContractsTest.

/*
     * @testName: getContractsTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:993;
     * 
     * @test_Strategy: Get the extension contract registration information for a
     * component of a given class.
     */
@Test
public void getContractsTest() throws Fault {
    final int priority = 124;
    Assertable assertable = new SingleCheckAssertable() {

        void assertNotNullAndLog(Configurable<?> config) throws Fault {
            Map<Class<?>, Integer> map = config.getConfiguration().getContracts(CallableProvider.class);
            assertEqualsInt(1, map.size(), "Unexpected contract size", map.size());
            Class<?> contract = map.entrySet().iterator().next().getKey();
            assertEquals(MessageBodyReader.class, contract, "Unexpected contract", contract, getLocation());
            logMsg("#getContracts() is", contract, "as expected", getLocation());
            int p = map.get(contract);
            assertEqualsInt(priority, p, "Unexpected priority", p);
            logMsg("Found expected priority", p);
        }

        @Override
        protected void check(Configurable<?> configurable) throws Fault {
            assertNotNullAndLog(configurable);
        }
    };
    Registrar registrar = new Registrar() {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            Map<Class<?>, Integer> map = new HashMap<Class<?>, Integer>();
            map.put(MessageBodyReader.class, priority);
            config.register(CallableProvider.class, map);
        }
    };
    checkConfigWithProperties(registrar, assertable);
}
Also used : SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) HashMap(java.util.HashMap) Registrar(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Registrar) 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)

Example 4 with Assertable

use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getInstancesIsNeverNullTest.

/*
     * @testName: getInstancesIsNeverNullTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:994; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: The returned value shall never be null.
     *
     * Register a provider ("singleton") instance
     */
@Test
public void getInstancesIsNeverNullTest() throws Fault {
    Assertable assertable = new SingleCheckAssertable() {

        void assertNotNullAndLog(Configurable<?> config) throws Fault {
            assertNotNull(config.getConfiguration().getInstances(), "config.getInstances() shall never be null", getLocation());
            logMsg("#getInstances() is not null as expected", getLocation());
        }

        @Override
        protected void check(Configurable<?> configurable) throws Fault {
            assertNotNullAndLog(configurable);
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) 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)

Example 5 with Assertable

use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getPropertyNamesIsImmutableTest.

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

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

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

        void setNewProperty(Configuration config) {
            try {
                config.getPropertyNames().add("property88");
            } catch (Exception e) {
            // can throw an exception or do nothing
            // or getPropertyNames can be hard copy
            }
        }

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            int pSize = config.getPropertyNames().size();
            assertEqualsInt(pSize, size + registeredPropertiesCnt, "getPropertyNames() is NOT immutable", 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)

Aggregations

Assertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable)44 SingleCheckAssertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable)44 Test (org.junit.jupiter.api.Test)42 Configurable (jakarta.ws.rs.core.Configurable)34 ConfigurableObject (ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject)25 Client (jakarta.ws.rs.client.Client)14 WebTarget (jakarta.ws.rs.client.WebTarget)14 Invocation (jakarta.ws.rs.client.Invocation)13 Configuration (jakarta.ws.rs.core.Configuration)13 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)10 HashMap (java.util.HashMap)9 Response (jakarta.ws.rs.core.Response)8 CallableProvider (ee.jakarta.tck.ws.rs.api.rs.core.configurable.CallableProvider)4 JaxrsCommonClient (ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient)4 IOException (java.io.IOException)4 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)2 MessageBodyReader (jakarta.ws.rs.ext.MessageBodyReader)2 MessageBodyWriter (jakarta.ws.rs.ext.MessageBodyWriter)2 Registrar (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Registrar)1