use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getInstancesTest.
/*
* @testName: getInstancesTest
*
* @assertion_ids: JAXRS:JAVADOC:994; JAXRS:JAVADOC:758;
*
* @test_Strategy: Get the immutable set of registered provider instances to be
* utilized by the configurable instance.
*
* Register a provider ("singleton") instance
*/
@Test
public void getInstancesTest() throws Fault {
Assertable assertable = new Assertable() {
@Override
public void check1OnClient(Client client) throws Fault {
assertSizeAndLog(client.getConfiguration(), 1);
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
assertSizeAndLog(target.getConfiguration(), 2);
}
void assertSizeAndLog(Configuration config, int count) throws Fault {
assertTrue(config.getInstances().size() == count + registeredInstancesCnt, "config.getClasses() return unexcepted size " + getLocation() + " : " + config.getInstances().size());
logMsg("Found", config.getInstances().size(), "providers");
}
};
Object[] providerObjects = createProviderInstances();
checkConfig(assertable, providerObjects);
}
use of ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method registerObjectNotAssignableContractsInMapTest.
/*
* @testName: registerObjectNotAssignableContractsInMapTest
*
* @assertion_ids: JAXRS:JAVADOC:990;
*
* @test_Strategy: Contracts that are not assignable from the registered
* component class MUST be ignored
*/
@Test
public void registerObjectNotAssignableContractsInMapTest() throws Fault {
Object[] instances = createProviderInstances();
// 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(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, instances, entity);
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 registerClassBindingPriorityFirstIsFirstTest.
/*
* @testName: registerClassBindingPriorityFirstIsFirstTest
*
* @assertion_ids: JAXRS:JAVADOC:755;
*
* @test_Strategy: This registration method provides the same functionality as
* register(Class) except that any binding priority specified on the
* registered JAX-RS component class via
*
* @Priority annotation is overridden with the supplied bindingPriority value.
*/
@Test
public void registerClassBindingPriorityFirstIsFirstTest() throws Fault {
final String content = "registerClassBindingPriorityFirstIsFirstTest";
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(FirstFilter.class, 300);
config.register(SecondFilter.class, 399);
}
}
};
setResourceMethod("echo");
// configurable each time
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);
Assertable assertable = getAssertableWithRegisteredProviderClassesOnConfigurable(cnt, 2);
Invocation i = checkConfig(registrar, assertable, classes, entity);
String response = i.invoke(String.class);
assertEquals(SecondFilter.class.getName(), response, "Unexpected filter ordering, the last was", response);
logMsg(response, "has been executed as second, 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 registerClassWriterContractsInMapTest.
/*
* @testName: registerClassWriterContractsInMapTest
*
* @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 registerClassWriterContractsInMapTest() throws Fault {
final String content = "registerClassWriterContractsInMapTest";
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) {
Map<Class<?>, Integer> contracts = new HashMap<Class<?>, Integer>();
contracts.put(MessageBodyWriter.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();
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 getAssertableWithRegisteredProviderInstancesOnConfigurable.
private Assertable getAssertableWithRegisteredProviderInstancesOnConfigurable(final int configurableIndex, final int numberOfRegisteredInstances) {
Assertable assertable = new SingleCheckAssertable() {
@Override
protected void check(Configurable<?> configurable) throws Fault {
assertSizeAndLog(configurable);
}
void assertSizeAndLog(Configurable<?> config) throws Fault {
int size = config.getConfiguration().getInstances().size();
int shouldBe = getLocationIndex() >= configurableIndex ? numberOfRegisteredInstances : 0;
shouldBe += registeredInstancesCnt;
assertEqualsInt(size, shouldBe, "unexpected number of registered classes found:", size, getLocation());
logMsg("Found", size, "provider(s) as expected");
}
};
return assertable;
}
Aggregations