use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable 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);
}
}
}
use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable 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");
}
use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getClassesIsNeverNullTest.
/*
* @testName: getClassesIsNeverNullTest
*
* @assertion_ids: JAXRS:JAVADOC:992; JAXRS:JAVADOC:758;
*
* @test_Strategy: The returned value shall never be null.
*
* Register a provider ("singleton") instance
*/
@Test
public void getClassesIsNeverNullTest() throws Fault {
Assertable assertable = new SingleCheckAssertable() {
@Override
protected void check(Configurable<?> configurable) throws Fault {
assertNotNullAndLog(configurable);
}
void assertNotNullAndLog(Configurable<?> config) throws Fault {
assertNotNull(config.getConfiguration().getClasses(), "#getClasses shall never be null", getLocation());
logMsg("#getClasses() is not null as expected", getLocation());
}
};
checkConfigWithProperties(assertable);
}
use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getClassesIsImmutableTest.
/*
* @testName: getClassesIsImmutableTest
*
* @assertion_ids: JAXRS:JAVADOC:992; JAXRS:JAVADOC:758;
*
* @test_Strategy: Get the immutable set of registered provider classes to be
* instantiated, injected and utilized in the scope of the configured instance.
* A provider class is a Java class with a jakarta.ws.rs.ext.Provider annotation
* declared on the class that implements a specific service interface.
*
* Register a provider class to be instantiated
*/
@Test
public void getClassesIsImmutableTest() throws Fault {
Assertable assertable = new Assertable() {
@Override
public void check1OnClient(Client client) throws Fault {
assertSizeAndLog(client.getConfiguration(), 0);
registerNewProviderInstance(client.getConfiguration());
assertSizeAndLog(client.getConfiguration(), 0);
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
registerNewProviderInstance(target.getConfiguration());
assertSizeAndLog(target.getConfiguration(), 0);
}
void assertSizeAndLog(Configuration config, int count) throws Fault {
if (config.getClasses().size() == 1)
logMsg("Found", config.getClasses().iterator().next());
assertTrue(config.getClasses().size() == count + registeredClassesCnt, "config.getClasses() return unexcepted size " + getLocation() + " : " + config.getClasses().size());
logMsg("Found", config.getClasses().size(), "providers");
}
void registerNewProviderInstance(Configuration config) {
Class<?> clz = CallableProvider.class;
try {
config.getClasses().add(clz);
} catch (Exception e) {
// can throw exception or do nothing
// when adding to this immutable set
// or it can be a new hard copied set
}
}
};
checkConfigWithProperties(assertable);
}
use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getPropertyTest.
/*
* @testName: getPropertyTest
*
* @assertion_ids: JAXRS:JAVADOC:996; JAXRS:JAVADOC:758;
*
* @test_Strategy: Get the value for the property with a given name. Set the new
* configuration property
*/
@Test
public void getPropertyTest() throws Fault {
Assertable assertable = new Assertable() {
@Override
public void check1OnClient(Client client) throws Fault {
assertPropertyIsSet(client.getConfiguration(), "property0");
logMsg("Found", client.getConfiguration().getProperty("property0"));
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
assertPropertyIsSet(target.getConfiguration(), "property0");
assertPropertyIsSet(target.getConfiguration(), "property1");
logMsg("Found", target.getConfiguration().getProperty("property1"));
}
void assertPropertyIsSet(Configuration config, String property) throws Fault {
assertTrue(config.getProperty(property).equals(property), "config.setProperty() did not set anything: " + getLocation());
}
};
checkConfigWithProperties(assertable);
}
Aggregations