Search in sources :

Example 16 with Configuration

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

the class JAXRSClientIT method getConfigurationTest.

/*
   * @testName: getConfigurationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:977; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the immutable configuration of the request.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getConfigurationTest() throws Fault {
    final Client client = ClientBuilder.newClient();
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Client contextClient = context.getClient();
            assertEquals(contextClient, client, "the client instance is different from the context one");
            Configuration contextConfig = context.getConfiguration();
            assertNotNull(contextConfig, "context.getConfiguration() returned null");
            Response r = Response.ok().build();
            context.abortWith(r);
        }
    };
    client.register(provider);
    WebTarget target = client.target(getUrl());
    Invocation invocation = target.request().buildGet();
    Response response = invoke(invocation);
    assertStatus(response, Status.OK);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Configuration(jakarta.ws.rs.core.Configuration) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Example 17 with Configuration

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

the class JAXRSClientIT method checkConfig.

protected Invocation checkConfig(Registrar registrar, Assertable assertable, Object[] registerables, Entity<?> entity) throws Fault {
    Client client = ClientBuilder.newClient();
    Configuration config = client.getConfiguration();
    registeredClassesCnt = config.getClasses().size();
    registeredInstancesCnt = config.getInstances().size();
    logMsg("Already registered", registeredClassesCnt, "classes");
    logMsg("Already registered", registeredInstancesCnt, "instances");
    register(registrar, client, registerables[0]);
    assertable.check1OnClient(client);
    assertable.incrementLocation();
    WebTarget target = client.target(getAbsoluteUrl());
    register(registrar, target, registerables[1]);
    assertable.check2OnTarget(target);
    assertable.incrementLocation();
    Invocation.Builder builder = target.request();
    Invocation invocation = builder.buildPost(entity);
    return invocation;
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client)

Example 18 with Configuration

use of jakarta.ws.rs.core.Configuration 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 19 with Configuration

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

the class JAXRSClientIT method checkConfig.

// /////////////////////////////////////////////////////////////////////////
void checkConfig(Configurable<?> configurable, int providersCount, int propertiesCount) throws Fault {
    Configuration config = configurable.getConfiguration();
    boolean check;
    Set<Object> providers = config.getInstances();
    check = checkCollectionSize(providers, providersCount);
    assertTrue(check, "Unexpected Instances List in Client:" + providers.size());
    TestUtil.logTrace("Test of Providers passed");
    Map<String, Object> properties = config.getProperties();
    check = checkCollectionSize(properties, propertiesCount);
    assertTrue(check, "Unexpected Properties List in Client:" + properties.size());
    TestUtil.logTrace("Test of Properties passed");
}
Also used : Configuration(jakarta.ws.rs.core.Configuration)

Example 20 with Configuration

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

the class JAXRSClientIT method deepCopyConfigClientLevelTest.

/*
   * @testName: deepCopyConfigClientLevelTest
   * 
   * @assertion_ids: JAXRS:SPEC:68; JAXRS:SPEC:72;
   * 
   * @test_Strategy: Note that changes to hello's configuration do not affect
   * base, i.e. configuration inheritance requires performing a deep copy of the
   * configuration.
   * 
   * The following Client API types are configurable: Client, Invocation,
   * Invocation.Builder and WebTarget.
   */
@Test
public void deepCopyConfigClientLevelTest() throws Fault {
    Client client = ClientBuilder.newClient();
    // Client level inheritance
    client.property("test", "test");
    Configuration conf2 = ClientBuilder.newClient().getConfiguration();
    Object o = conf2.getProperty("test");
    assertNull(o, "configuration() does not perform deep copy, o=", o);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (jakarta.ws.rs.core.Configuration)21 Client (jakarta.ws.rs.client.Client)19 WebTarget (jakarta.ws.rs.client.WebTarget)17 Test (org.junit.jupiter.api.Test)17 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)16 Assertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable)13 SingleCheckAssertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable)13 CallableProvider (ee.jakarta.tck.ws.rs.api.rs.core.configurable.CallableProvider)4 JaxrsCommonClient (ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient)3 Configurable (jakarta.ws.rs.core.Configurable)3 ConfigurableObject (ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject)2 Invocation (jakarta.ws.rs.client.Invocation)2 StringBeanEntityProvider (ee.jakarta.tck.ws.rs.common.provider.StringBeanEntityProvider)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 Response (jakarta.ws.rs.core.Response)1