Search in sources :

Example 1 with Configurable

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

the class JAXRSClientIT method registerFeatureInstanceReturningFalseTest.

/*
     * @testName: registerFeatureInstanceReturningFalseTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: Register a feature. In case the registered provider is a
     * client-side Feature feature, this object instantiates the feature and invokes
     * the Feature#configure(FeatureContext) method and lets the feature update it's
     * internal configuration state.
     */
@Test
public void registerFeatureInstanceReturningFalseTest() throws Fault {
    final Feature feature = new FeatureReturningFalse();
    Assertable assertable = new SingleCheckAssertable() {

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

        void assertSizeAndLog(Configurable<?> config) throws Fault {
            int cnt = config.getConfiguration().getInstances().size();
            assertEqualsInt(cnt, 1 + registeredInstancesCnt, "unexpected number of registered instances found:", cnt, getLocation());
            logMsg("Found", cnt, "features");
        }
    };
    Object[] features = new Object[] { feature, feature };
    checkConfig(assertable, features);
}
Also used : Configurable(jakarta.ws.rs.core.Configurable) Feature(jakarta.ws.rs.core.Feature) Test(org.junit.jupiter.api.Test)

Example 2 with Configurable

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

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

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

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

the class JAXRSClientIT method registerObjectNotAssignableContractsInMapTest.

/*
   * @testName: registerObjectNotAssignableContractsInMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:990;
   * 
   * @test_Strategy: Contracts that are not assignable from the registered
   * component class MUST be ignored
   */
@Test
public void registerObjectNotAssignableContractsInMapTest() throws Fault {
    Object[] instances = createProviderInstances();
    // entity to send to a server
    Entity<?> entity = Entity.entity("", 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(ClientRequestFilter.class, 400);
                config.register(registerable, contracts);
            }
        }
    };
    setResourceMethod("echo");
    // build client configurableCnt times to register provider using a
    // different
    // configurable each time
    Assertable assertable = getAssertableWithNoRegisteredProviderInstance();
    for (int cnt = 0; cnt != configurableCnt; cnt++) {
        // Check the provider is registered
        logMsg("Check on Configurable", Assertable.getLocation(cnt));
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        checkConfig(registrar, assertable, instances, entity);
        logMsg("The provider with unassignable contract has ben ignored as expected");
    }
}
Also used : HashMap(java.util.HashMap) 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) Configurable(jakarta.ws.rs.core.Configurable) 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