Search in sources :

Example 21 with Configurable

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

the class JAXRSClientIT method getClassesIsNeverNullTest.

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

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

        void assertNotNullAndLog(Configurable<?> config) throws Fault {
            assertNotNull(config.getConfiguration().getClasses(), "#getClasses shall never be null", getLocation());
            logMsg("#getClasses() is not null as expected", getLocation());
        }
    };
    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 22 with Configurable

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

Example 23 with Configurable

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

the class JAXRSClientIT method getContractsIsNeverNullTest.

/*
     * @testName: getContractsIsNeverNullTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:993;
     * 
     * @test_Strategy: Get the extension contract registration information for a
     * component of a given class. Method does not return null.
     */
@Test
public void getContractsIsNeverNullTest() throws Fault {
    Assertable assertable = new SingleCheckAssertable() {

        void assertNotNullAndLog(Configurable<?> config) throws Fault {
            Map<Class<?>, Integer> map = config.getConfiguration().getContracts(MessageBodyReader.class);
            assertNotNull(map, "getContracts is null", getLocation());
            logMsg("#getContracts() 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 24 with Configurable

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

the class JAXRSClientIT method getPropertyIsNullTest.

/*
     * @testName: getPropertyIsNullTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:996; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: null if the property with such name is not configured.
     */
@Test
public void getPropertyIsNullTest() throws Fault {
    Assertable assertable = new SingleCheckAssertable() {

        void assertPropertyIsNull(Configurable<?> config) throws Fault {
            assertTrue(config.getConfiguration().getProperty("property88") == null, "#getProperty('nonexisting') != null " + getLocation());
            logMsg("#getProperty('nonexisting') is null as expected");
        }

        @Override
        protected void check(Configurable<?> configurable) throws Fault {
            assertPropertyIsNull(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 25 with Configurable

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

the class JAXRSClientIT method registerObjectReaderContractsInMapTest.

/*
   * @testName: registerObjectReaderContractsInMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:990;
   * 
   * @test_Strategy: This registration method provides same functionality as
   * register(Object, Class[]) except that any binding priority specified on the
   * registered JAX-RS component class using @Priority annotation is overridden
   * for each extension provider contract type separately with an integer
   * binding priority value specified as a value in the supplied map.
   */
@Test
public void registerObjectReaderContractsInMapTest() throws Fault {
    final String content = "registerObjectReaderContractsInMapTest";
    Object[] instances = createProviderInstances();
    // entity to send to a server
    Entity<?> entity = Entity.entity(content, MediaType.WILDCARD);
    // register only once per client build
    IncrementableRegistrar registrar = new IncrementableRegistrar(0, 1) {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            if (currentValue++ == finalValue) {
                Map<Class<?>, Integer> contracts = new HashMap<Class<?>, Integer>();
                contracts.put(MessageBodyReader.class, 100);
                config.register(registerable, contracts);
            }
        }
    };
    setResourceMethod("echo");
    // configurable each time
    for (int cnt = 0; cnt != configurableCnt; cnt++) {
        // Check the provider is registered
        logMsg("Check on Configurable", Assertable.getLocation(cnt));
        Assertable assertable = getAssertableWithRegisteredProviderInstancesOnConfigurable(cnt, 1);
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Invocation i = checkConfig(registrar, assertable, instances, entity);
        Response response = i.invoke();
        Callable<?> callable = response.readEntity(Callable.class);
        assertEquals(content, callable.toString(), "Expected", content, "differs from given", response);
        logMsg("sucessufully read Callable by provider registered on Configurable", Assertable.getLocation(cnt));
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) HashMap(java.util.HashMap) Configurable(jakarta.ws.rs.core.Configurable) Response(jakarta.ws.rs.core.Response) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) ConfigurableObject(ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject) Test(org.junit.jupiter.api.Test)

Aggregations

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