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);
}
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;
}
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");
}
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");
}
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);
}
Aggregations