Search in sources :

Example 41 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 registerClassReaderContractsTest.

/*
   * @testName: registerClassReaderContractsTest
   * 
   * @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 registerClassReaderContractsTest() throws Fault {
    final String content = "registerClassReaderContractsTest";
    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)
                config.register((Class<?>) 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 = 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();
        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) Configurable(jakarta.ws.rs.core.Configurable) Response(jakarta.ws.rs.core.Response) MessageBodyReader(jakarta.ws.rs.ext.MessageBodyReader) 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 42 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 isEnabledFeatureReturningTrueTest.

/*
   * @testName: isEnabledFeatureReturningTrueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:999; 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
   */
@Test
public void isEnabledFeatureReturningTrueTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningTrue1();
    final CheckingFeature feature2 = new FeatureReturningTrue2();
    final CheckingFeature feature3 = new FeatureReturningTrue3();
    final CheckingFeature feature4 = new FeatureReturningTrue4();
    feature1.addDisabledFeatures(feature2, feature3, feature4).setName("feature1");
    feature2.addDisabledFeatures(feature3, feature4).addEnabledFeatures(feature1).setName("feature2");
    feature3.addDisabledFeatures(feature4).addEnabledFeatures(feature1, feature2).setName("feature3");
    feature4.addEnabledFeatures(feature1, feature2, feature3).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)

Example 43 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 isEnabledClassReturningFalseTest.

/*
   * @testName: isEnabledClassReturningFalseTest
   * 
   * @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 isEnabledClassReturningFalseTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningFalse1();
    final CheckingFeature feature2 = new FeatureReturningFalse2();
    final CheckingFeature feature3 = new FeatureReturningFalse3();
    final CheckingFeature feature4 = new FeatureReturningFalse4();
    feature1.addDisabledClasses(FeatureReturningFalse2.class, FeatureReturningFalse3.class, FeatureReturningFalse4.class).setName("feature1");
    feature2.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse3.class, FeatureReturningFalse4.class).setName("feature2");
    feature3.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse2.class, FeatureReturningFalse4.class).setName("feature3");
    feature4.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse2.class, FeatureReturningFalse3.class).setName("feature4");
    Assertable assertable = new Assertable() {

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

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

        void assertIsDisabled(Configurable<?> config, CheckingFeature feature) throws Fault {
            boolean isEnabled = config.getConfiguration().isEnabled(feature);
            assertFalse(isEnabled, "Feature" + feature.getName() + "is unexpectedly enabled" + getLocation());
            logMsg("No feature enabled 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 : 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)

Example 44 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 isEnabledFeatureReturningFalseTest.

/* Run test */
/*
   * @testName: isEnabledFeatureReturningFalseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:999; 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
   */
@Test
public void isEnabledFeatureReturningFalseTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningFalse1();
    final CheckingFeature feature2 = new FeatureReturningFalse2();
    final CheckingFeature feature3 = new FeatureReturningFalse3();
    final CheckingFeature feature4 = new FeatureReturningFalse4();
    feature1.addDisabledFeatures(feature2, feature3, feature4).setName("feature1");
    feature2.addDisabledFeatures(feature1, feature3, feature4).setName("feature2");
    feature3.addDisabledFeatures(feature1, feature2, feature4).setName("feature3");
    feature4.addDisabledFeatures(feature1, feature2, feature3).setName("feature4");
    Assertable assertable = new Assertable() {

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

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

        void assertIsDisabled(Configurable<?> config, CheckingFeature feature) throws Fault {
            boolean isEnabled = config.getConfiguration().isEnabled(feature);
            assertFalse(isEnabled, "Feature" + feature.getName() + "is unexpectedly enabled" + getLocation());
            logMsg("No feature enabled 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 : 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

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