Search in sources :

Example 16 with Configurable

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

the class JAXRSClientIT method registerObjectReaderContractsTest.

/*
   * @testName: registerObjectReaderContractsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:760;
   * 
   * @test_Strategy: This registration method provides the same functionality as
   * register(Object) except the JAX-RS component class is only registered as a
   * provider of the listed extension provider or meta-provider contracts.
   */
@Test
public void registerObjectReaderContractsTest() throws Fault {
    final String content = "registerClassReaderContractsTest";
    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)
                config.register(registerable, MessageBodyReader.class);
        }
    };
    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 : Response(jakarta.ws.rs.core.Response) MessageBodyReader(jakarta.ws.rs.ext.MessageBodyReader) Invocation(jakarta.ws.rs.client.Invocation) 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)

Example 17 with Configurable

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

the class JAXRSClientIT method registerClassBindingPriorityInMapTest.

/*
   * @testName: registerClassBindingPriorityInMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:989;
   * 
   * @test_Strategy: This registration method provides same functionality as
   * register(Class, 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 registerClassBindingPriorityInMapTest() throws Fault {
    final String content = "registerClassBindingPriorityInMapTest";
    Class<?>[] classes = createProviderClasses();
    // 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(ClientRequestFilter.class, 400);
                config.register(FirstFilter.class, contracts);
                contracts.clear();
                contracts.put(ClientRequestFilter.class, 300);
                config.register(SecondFilter.class, 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));
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Assertable assertable = getAssertableWithRegisteredProviderClassesOnConfigurable(cnt, 2);
        Invocation i = checkConfig(registrar, assertable, classes, entity);
        String response = i.invoke(String.class);
        assertEquals(FirstFilter.class.getName(), response, "Unexpected filter ordering, the last was", response);
        logMsg(response, "has been executed as second, as expected");
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) HashMap(java.util.HashMap) Configurable(jakarta.ws.rs.core.Configurable) 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)

Example 18 with Configurable

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

the class JAXRSClientIT method registerObjectBindingPriorityInMapTest.

/*
   * @testName: registerObjectBindingPriorityInMapTest
   * 
   * @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 registerObjectBindingPriorityInMapTest() throws Fault {
    final String content = "registerObjectBindingPriorityInMapTest";
    Class<?>[] classes = createProviderClasses();
    // 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(ClientRequestFilter.class, 400);
                config.register(new FirstFilter(), contracts);
                contracts.clear();
                contracts.put(ClientRequestFilter.class, 300);
                config.register(new SecondFilter(), 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));
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Assertable assertable = getAssertableWithRegisteredProviderInstancesOnConfigurable(cnt, 2);
        Invocation i = checkConfig(registrar, assertable, classes, entity);
        String response = i.invoke(String.class);
        assertEquals(FirstFilter.class.getName(), response, "Unexpected filter ordering, the last was", response);
        logMsg(response, "has been executed as second, as expected");
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) HashMap(java.util.HashMap) Configurable(jakarta.ws.rs.core.Configurable) 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)

Example 19 with Configurable

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

the class JAXRSClientIT method registerClassWriterContractsTest.

/* Run test */
/*
   * @testName: registerClassWriterContractsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:756;
   * 
   * @test_Strategy: This registration method provides the same functionality as
   * register(Class) except the JAX-RS component class is only registered as a
   * provider of the listed extension provider or meta-provider contracts.
   */
@Test
public void registerClassWriterContractsTest() throws Fault {
    final String content = "registerClassWriterContractsTest";
    Class<?>[] classes = createProviderClasses();
    // entity to send to a server
    Entity<?> entity = getCallableEntity(content);
    // register only once per client build
    IncrementableRegistrar registrar = new IncrementableRegistrar(0, 1) {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            if (currentValue++ == finalValue)
                config.register((Class<?>) registerable, MessageBodyWriter.class);
        }
    };
    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 = getAssertableWithRegisteredProviderClassesOnConfigurable(cnt, 1);
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Invocation i = checkConfig(registrar, assertable, classes, entity);
        Response response = i.invoke();
        response.bufferEntity();
        String responseString = response.readEntity(String.class);
        assertEquals(content, responseString, "Expected", content, "differs from given", response);
        logMsg("sucessufully wrote Callable by provider registered on Configurable", Assertable.getLocation(cnt));
        // check message body reader contract
        try {
            Callable<?> callable = response.readEntity(Callable.class);
            fault("MessageBodyReader contract has been unexpectedly registered", callable);
        } catch (Exception e) {
            logMsg("MessageBodyReader contract has not been registered as expected", e);
        }
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) Configurable(jakarta.ws.rs.core.Configurable) IOException(java.io.IOException) 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) MessageBodyWriter(jakarta.ws.rs.ext.MessageBodyWriter) Test(org.junit.jupiter.api.Test)

Example 20 with Configurable

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

the class JAXRSClientIT method isEnabledFeatureClassReturningTrueTest.

/*
   * @testName: isEnabledFeatureClassReturningTrueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:1000; JAXRS:JAVADOC:1003;
   * 
   * @test_Strategy: Check if a feature instance of featureClass class has been
   * previously enabled in the runtime configuration context.
   * 
   * Returns true if the feature was successfully enabled, false otherwise
   */
@SuppressWarnings("unchecked")
@Test
public void isEnabledFeatureClassReturningTrueTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningTrue1();
    final CheckingFeature feature2 = new FeatureReturningTrue2();
    final CheckingFeature feature3 = new FeatureReturningTrue3();
    final CheckingFeature feature4 = new FeatureReturningTrue4();
    feature1.addDisabledClasses(FeatureReturningTrue2.class, FeatureReturningTrue3.class, FeatureReturningTrue4.class).setName("feature1");
    feature2.addDisabledClasses(FeatureReturningTrue3.class, FeatureReturningTrue4.class).addEnabledClasses(FeatureReturningTrue1.class).setName("feature2");
    feature3.addDisabledClasses(FeatureReturningTrue4.class).addEnabledClasses(FeatureReturningTrue1.class, FeatureReturningTrue2.class).setName("feature3");
    feature4.addEnabledClasses(FeatureReturningTrue1.class, FeatureReturningTrue2.class, FeatureReturningTrue3.class).setName("feature4");
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            assertIsRegistered(client, feature1);
            assertIsNotRegistered(client, feature2);
            assertIsNotRegistered(client, feature3);
            assertIsNotRegistered(client, feature4);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            assertIsRegistered(target, feature1);
            assertIsRegistered(target, feature2);
            assertIsNotRegistered(target, feature3);
            assertIsNotRegistered(target, feature4);
        }

        void assertIsRegistered(Configurable<?> config, CheckingFeature feature) throws Fault {
            Configuration configuration = config.getConfiguration();
            assertTrue(configuration.isRegistered(feature), "Feature" + feature.getName() + "is NOT registered" + getLocation());
            logMsg("Feature", feature.getName(), "registered as expected", getLocation());
        }

        void assertIsNotRegistered(Configurable<?> config, CheckingFeature feature) throws Fault {
            Configuration configuration = config.getConfiguration();
            assertFalse(configuration.isRegistered(feature), "Feature" + feature.getName() + "is unexpectedly registered" + getLocation());
            logMsg("Feature", feature.getName(), "NOT registered as expected", getLocation());
        }
    };
    Object[] instances = { feature1, feature2, feature3, feature4 };
    checkConfig(assertable, instances);
    logMsg("The provider with unassignable contract has ben ignored as expected");
}
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) ConfigurableObject(ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject) WebTarget(jakarta.ws.rs.client.WebTarget) Configurable(jakarta.ws.rs.core.Configurable) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client) 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