use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method startAsyncInvokerForMethod.
// ///////////////////////////////////////////////////////////////////////
// utility methods
/**
* Create AsyncInvoker for given resource method and start time
*/
protected AsyncInvoker startAsyncInvokerForMethod(String methodName) {
Client client = createClient();
client.register(new JdkLoggingFilter(false));
WebTarget target = client.target(getAbsoluteUrl(methodName));
AsyncInvoker async = target.request().async();
setStartTime();
return async;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method closeTest.
/*
* @testName: closeTest
*
* @assertion_ids: JAXRS:JAVADOC:841;
*
* @test_Strategy: Close the message entity input stream (if available and
* open). This operation is idempotent, i.e. it can be invoked multiple times
* with the same effect which also means that calling the method on an already
* closed message instance is legal and has no further effect
*/
@Test
public void closeTest() throws Fault {
// make new Client, the one from super class calls bufferEntity()
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
// calling the method on an already closed message
response.close();
// instance is legal
response.close();
// closed response will result in an IllegalStateException being thrown
try {
String entity = response.readEntity(String.class);
assertTrue(false, "IllegalStateException has not been thrown when" + "#close() and #readEntity() but entity" + entity + "has been read");
} catch (IllegalStateException e) {
logMsg("#close() closed the stream, and consecutive reading threw IllegalStateException as expected");
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method checkConfig.
protected void checkConfig(Registrar registrar, Assertable assertable, Object[] registerables) throws Fault {
Entity<String> entity = Entity.entity("echo", MediaType.WILDCARD_TYPE);
Client client = ClientBuilder.newClient();
logMsg("Registering on Client");
register(registrar, client, registerables[0]);
WebTarget target = client.target(getAbsoluteUrl());
logMsg("Registering on WebTarget");
register(registrar, target, registerables[1]);
Invocation.Builder builder = target.request();
Invocation invocation = builder.buildPost(entity);
String response = invocation.invoke(String.class);
assertEquals(entity.getEntity(), response, "Unexpected response received", response);
assertable.check1OnClient(client);
assertable.incrementLocation();
assertable.check2OnTarget(target);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method isEnabledClassReturningFalseTest.
/*
* @testName: isEnabledClassReturningFalseTest
*
* @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 isEnabledClassReturningFalseTest() throws Fault {
final CheckingFeature feature1 = new FeatureReturningFalse1();
final CheckingFeature feature2 = new FeatureReturningFalse2();
final CheckingFeature feature3 = new FeatureReturningFalse3();
final CheckingFeature feature4 = new FeatureReturningFalse4();
feature1.addDisabledClasses(FeatureReturningFalse2.class, FeatureReturningFalse3.class, FeatureReturningFalse4.class).setName("feature1");
feature2.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse3.class, FeatureReturningFalse4.class).setName("feature2");
feature3.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse2.class, FeatureReturningFalse4.class).setName("feature3");
feature4.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse2.class, FeatureReturningFalse3.class).setName("feature4");
Assertable assertable = new Assertable() {
@Override
public void check1OnClient(Client client) throws Fault {
assertIsDisabled(client, feature1);
assertIsDisabled(client, feature2);
assertIsDisabled(client, feature3);
assertIsDisabled(client, feature4);
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
assertIsDisabled(target, feature1);
assertIsDisabled(target, feature2);
assertIsDisabled(target, feature3);
assertIsDisabled(target, feature4);
}
void assertIsDisabled(Configurable<?> config, CheckingFeature feature) throws Fault {
boolean isEnabled = config.getConfiguration().isEnabled(feature);
assertFalse(isEnabled, "Feature" + feature.getName() + "is unexpectedly enabled" + getLocation());
logMsg("No feature enabled 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.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method isEnabledFeatureReturningFalseTest.
/* Run test */
/*
* @testName: isEnabledFeatureReturningFalseTest
*
* @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 isEnabledFeatureReturningFalseTest() throws Fault {
final CheckingFeature feature1 = new FeatureReturningFalse1();
final CheckingFeature feature2 = new FeatureReturningFalse2();
final CheckingFeature feature3 = new FeatureReturningFalse3();
final CheckingFeature feature4 = new FeatureReturningFalse4();
feature1.addDisabledFeatures(feature2, feature3, feature4).setName("feature1");
feature2.addDisabledFeatures(feature1, feature3, feature4).setName("feature2");
feature3.addDisabledFeatures(feature1, feature2, feature4).setName("feature3");
feature4.addDisabledFeatures(feature1, feature2, feature3).setName("feature4");
Assertable assertable = new Assertable() {
@Override
public void check1OnClient(Client client) throws Fault {
assertIsDisabled(client, feature1);
assertIsDisabled(client, feature2);
assertIsDisabled(client, feature3);
assertIsDisabled(client, feature4);
}
@Override
public void check2OnTarget(WebTarget target) throws Fault {
assertIsDisabled(target, feature1);
assertIsDisabled(target, feature2);
assertIsDisabled(target, feature3);
assertIsDisabled(target, feature4);
}
void assertIsDisabled(Configurable<?> config, CheckingFeature feature) throws Fault {
boolean isEnabled = config.getConfiguration().isEnabled(feature);
assertFalse(isEnabled, "Feature" + feature.getName() + "is unexpectedly enabled" + getLocation());
logMsg("No feature enabled as expected", getLocation());
}
};
Object[] instances = { feature1, feature2, feature3, feature4 };
checkConfig(assertable, instances);
logMsg("The provider with unassignable contract has ben ignored as expected");
}
Aggregations