Search in sources :

Example 26 with Configurable

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

the class JAXRSClientIT method registerClassNotAssignableContractsInMapTest.

/*
   * @testName: registerClassNotAssignableContractsInMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:989;
   * 
   * @test_Strategy: Contracts that are not assignable from the registered
   * component class MUST be ignored
   */
@Test
public void registerClassNotAssignableContractsInMapTest() throws Fault {
    Class<?>[] classes = createProviderClasses();
    // 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((Class<?>) 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, classes, 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)

Example 27 with Configurable

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

the class JAXRSClientIT method registerClassEmptyContractsTest.

/*
   * @testName: registerClassEmptyContractsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:756;
   * 
   * @test_Strategy: Implementations MUST ignore attempts to register a
   * component class for an empty collection of contracts via this method and
   * SHOULD raise a warning about such event.
   */
@Test
public void registerClassEmptyContractsTest() throws Fault {
    Class<?>[] classes = createProviderClasses();
    // 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)
                config.register((Class<?>) registerable, new Class<?>[] {});
        }
    };
    setResourceMethod("echo");
    // build client configurableCnt times to register provider using a
    // different
    // configurable each time
    Assertable assertable = getAssertableWithNoRegisteredProvider();
    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, classes, entity);
        logMsg("The provider of with contracts 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) Configurable(jakarta.ws.rs.core.Configurable) Test(org.junit.jupiter.api.Test)

Example 28 with Configurable

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

the class JAXRSClientIT method registerClassNullContractsTest.

/*
   * @testName: registerClassNullContractsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:756;
   * 
   * @test_Strategy: Implementations MUST ignore attempts to register a
   * component class for a null collection of contracts via this method and
   * SHOULD raise a warning about such event.
   */
@Test
public void registerClassNullContractsTest() throws Fault {
    Class<?>[] classes = createProviderClasses();
    // 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)
                config.register((Class<?>) registerable, (Class<?>[]) null);
        }
    };
    setResourceMethod("echo");
    // build client configurableCnt times to register provider using a
    // different
    // configurable each time
    Assertable assertable = getAssertableWithNoRegisteredProvider();
    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, classes, entity);
        logMsg("The provider with null 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) Configurable(jakarta.ws.rs.core.Configurable) Test(org.junit.jupiter.api.Test)

Example 29 with Configurable

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

the class JAXRSClientIT method registerClassReaderContractsInMapTest.

/*
   * @testName: registerClassReaderContractsInMapTest
   * 
   * @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 registerClassReaderContractsInMapTest() throws Fault {
    final String content = "registerClassReaderContractsInMapTest";
    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(MessageBodyReader.class, 100);
                config.register((Class<?>) 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 = 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) 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)

Example 30 with Configurable

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

the class JAXRSClientIT method getAssertableWithRegisteredProviderClassesOnConfigurable.

// ///////////////////////////////////////////////////////////////////////
private Assertable getAssertableWithRegisteredProviderClassesOnConfigurable(final int configurableIndex, final int numberOfRegisteredClasses) {
    Assertable assertable = new SingleCheckAssertable() {

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

        void assertSizeAndLog(Configurable<?> config) throws Fault {
            int size = config.getConfiguration().getClasses().size();
            int shouldBe = getLocationIndex() >= configurableIndex ? numberOfRegisteredClasses : 0;
            shouldBe += registeredClassesCnt;
            assertEqualsInt(size, shouldBe, "unexpected number of registered classes found:", size, getLocation());
            logMsg("Found", size, "provider(s) as expected");
        }
    };
    return 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)

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