use of jakarta.ws.rs.core.Configuration in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method newClientWithConfigurationTest.
/*
* @testName: newClientWithConfigurationTest
*
* @assertion_ids: JAXRS:JAVADOC:1020;
*
* @test_Strategy: Create new configured client instance using the default
* client builder factory provided by the JAX-RS implementation provider.
*/
@Test
public void newClientWithConfigurationTest() throws Fault {
String property = "JAXRSTCK";
Client client = ClientBuilder.newClient();
client.property(property, property);
Configuration config = client.getConfiguration();
client = ClientBuilder.newClient(config);
assertNotNull(client, "could not create Client instance");
assertEquals(property, client.getConfiguration().getProperty(property), "client does not contain given config");
}
use of jakarta.ws.rs.core.Configuration in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method checkConfig.
protected void checkConfig(Registrar registrar, Assertable assertable, Object[] registerables) 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("http://tck.cts:888");
register(registrar, target, registerables[1]);
assertable.check2OnTarget(target);
assertable.incrementLocation();
}
use of jakarta.ws.rs.core.Configuration in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method isRegisteredProviderRegisteredInstanceTest.
/*
* @testName: isRegisteredProviderRegisteredInstanceTest
*
* @assertion_ids: JAXRS:JAVADOC:1001; JAXRS:JAVADOC:1002;
*
* @test_Strategy: Check if a particular JAX-RS component instance (such as
* providers or features) has been previously registered in the runtime
* configuration context.
*
* Method returns true only in case an instance equal to the component instance
* is already present among the components previously registered in the
* configuration context.
*/
@Test
public void isRegisteredProviderRegisteredInstanceTest() throws Fault {
Assertable assertable = new Assertable() {
CallableProvider1 p1 = new CallableProvider1();
CallableProvider2 p2 = new CallableProvider2();
@Override
public void check1OnClient(Client client) throws Fault {
client.register(p1);
assertSizeAndLog(client.getConfiguration(), 1);
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
target.register(p2);
assertSizeAndLog(target.getConfiguration(), 2);
}
void assertSizeAndLog(Configuration config, int size) throws Fault {
assertFalse(config.isRegistered(CallableProvider.class), "CallableProvider is unexpectedly registered");
switch(size) {
case 2:
assertFalse(config.isRegistered(new CallableProvider2()), "CallableProvider2 is registered " + getLocation());
assertTrue(config.isRegistered(p2), "CallableProvider2.class is NOT registered " + getLocation());
assertTrue(config.isRegistered(CallableProvider2.class), "CallableProvider2.class is NOT registered " + getLocation());
logMsg("Found registered CallableProvider2 as expected", getLocation());
case 1:
assertFalse(config.isRegistered(new CallableProvider1()), "CallableProvider1 is registered " + getLocation());
assertTrue(config.isRegistered(p1), "CallableProvider1.class is NOT registered " + getLocation());
assertTrue(config.isRegistered(CallableProvider1.class), "CallableProvider1.class is NOT registered " + getLocation());
logMsg("Found registered CallableProvider1 as expected", getLocation());
}
}
};
checkConfigWithProperties(assertable);
}
use of jakarta.ws.rs.core.Configuration in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getPropertyNamesIsImmutableTest.
/*
* @testName: getPropertyNamesIsImmutableTest
*
* @assertion_ids: JAXRS:JAVADOC:997; JAXRS:JAVADOC:758;
*
* @test_Strategy: Returns an immutable collection containing the property names
* available within the context of the current configuration instance. Set the
* new configuration property
*/
@Test
public void getPropertyNamesIsImmutableTest() throws Fault {
Assertable assertable = new Assertable() {
@Override
public void check1OnClient(Client client) throws Fault {
setNewProperty(client.getConfiguration());
assertSizeAndLog(client.getConfiguration(), 1);
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
setNewProperty(target.getConfiguration());
assertSizeAndLog(target.getConfiguration(), 2);
}
void setNewProperty(Configuration config) {
try {
config.getPropertyNames().add("property88");
} catch (Exception e) {
// can throw an exception or do nothing
// or getPropertyNames can be hard copy
}
}
void assertSizeAndLog(Configuration config, int size) throws Fault {
int pSize = config.getPropertyNames().size();
assertEqualsInt(pSize, size + registeredPropertiesCnt, "getPropertyNames() is NOT immutable", getLocation(), "got", pSize, "properties");
logMsg("Found", pSize, " properties");
}
};
checkConfigWithProperties(assertable);
}
use of jakarta.ws.rs.core.Configuration 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);
}
Aggregations