use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method registerObjectWriterContractsInMapTest.
/*
* @testName: registerObjectWriterContractsInMapTest
*
* @assertion_ids: JAXRS:JAVADOC:990;
*
* @test_Strategy: This registration method provides same functionality as
* register(Object, 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 registerObjectWriterContractsInMapTest() throws Fault {
final String content = "registerObjectWriterContractsInMapTest";
Object[] instances = createProviderInstances();
// 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(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 = getAssertableWithRegisteredProviderInstancesOnConfigurable(cnt, 1);
// set we want to register the provider on Configurable
// Assertable::LOCATION[cnt]
registrar.setCurrentValue(0).setFinalValue(cnt);
Invocation i = checkConfig(registrar, assertable, instances, 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 jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method registerObjectReaderContractsTest.
/*
* @testName: registerObjectReaderContractsTest
*
* @assertion_ids: JAXRS:JAVADOC:760;
*
* @test_Strategy: This registration method provides the same functionality as
* register(Object) except the JAX-RS component class is only registered as a
* provider of the listed extension provider or meta-provider contracts.
*/
@Test
public void registerObjectReaderContractsTest() throws Fault {
final String content = "registerClassReaderContractsTest";
Object[] instances = createProviderInstances();
// 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(registerable, MessageBodyReader.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 = getAssertableWithRegisteredProviderInstancesOnConfigurable(cnt, 1);
// set we want to register the provider on Configurable
// Assertable::LOCATION[cnt]
registrar.setCurrentValue(0).setFinalValue(cnt);
Invocation i = checkConfig(registrar, assertable, instances, 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));
}
}
use of jakarta.ws.rs.core.Response 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 jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method dynamicFeatureIsRegisteredTest.
/*
* @testName: dynamicFeatureIsRegisteredTest
*
* @assertion_ids: JAXRS:SPEC:137;
*
* @test_Strategy:
*/
@Test
public void dynamicFeatureIsRegisteredTest() throws Fault {
try (Response response = ClientBuilder.newClient().target(getAbsoluteUrl("dynamicFeature")).request().get()) {
assertEquals(200, response.getStatus());
assertEquals(TckDynamicFeature.class.getName(), response.readEntity(String.class));
} catch (Exception e) {
fault(e);
}
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method featureIsRegisteredTest.
/* Run test */
/*
* @testName: featureIsRegisteredTest
*
* @assertion_ids: JAXRS:SPEC:137;
*
* @test_Strategy:
*/
@Test
public void featureIsRegisteredTest() throws Fault {
try (Response response = ClientBuilder.newClient().target(getAbsoluteUrl("staticFeature")).request().get()) {
assertEquals(200, response.getStatus());
assertEquals(TckFeature.class.getName(), response.readEntity(String.class));
} catch (Exception e) {
fault(e);
}
}
Aggregations