use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityGenericTypeAnnotationThrowsIllegalStateExceptionTest.
/*
* @testName: readEntityGenericTypeAnnotationThrowsIllegalStateExceptionTest
*
* @assertion_ids: JAXRS:JAVADOC:872;
*
* @test_Strategy: if the entity is not backed by an input stream, or if the
* entity input stream has been fully consumed already and has not been
* buffered prior consuming.
*/
@Test
public void readEntityGenericTypeAnnotationThrowsIllegalStateExceptionTest() throws Fault {
Annotation[] annotations = AnnotatedClass.class.getAnnotations();
// create a new client
Client client = ClientBuilder.newClient();
WebTarget target = // with no bufferEntity called
client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
String entity = response.readEntity(generic(String.class), annotations);
assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(GenericType<String>, annotations)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
try {
response.readEntity(generic(Reader.class), annotations);
throw new Fault("No exception has been thrown when reader for entity is not buffered");
} catch (IllegalStateException e) {
logMsg("IllegalStateException has been thrown as expected");
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityClassThrowsIllegalStateExceptionTest.
/*
* @testName: readEntityClassThrowsIllegalStateExceptionTest
*
* @assertion_ids: JAXRS:JAVADOC:863;
*
* @test_Strategy: if the entity is not backed by an input stream, or if the
* entity input stream has been fully consumed already and has not been
* buffered prior consuming.
*/
@Test
public void readEntityClassThrowsIllegalStateExceptionTest() throws Fault {
// create a new client
Client client = ClientBuilder.newClient();
WebTarget target = // with no bufferEntity called
client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
String entity = response.readEntity(String.class);
assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(String.class)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
try {
response.readEntity(Reader.class);
throw new Fault("No exception has been thrown when reader for entity is not buffered");
} catch (IllegalStateException e) {
logMsg("IllegalStateException has been thrown as expected");
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method checkConfig.
protected Invocation checkConfig(Registrar registrar, Assertable assertable, Object[] registerables, Entity<?> entity) 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(getAbsoluteUrl());
register(registrar, target, registerables[1]);
assertable.check2OnTarget(target);
assertable.incrementLocation();
Invocation.Builder builder = target.request();
Invocation invocation = builder.buildPost(entity);
return invocation;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method isEnabledFeatureReturningTrueTest.
/*
* @testName: isEnabledFeatureReturningTrueTest
*
* @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 isEnabledFeatureReturningTrueTest() throws Fault {
final CheckingFeature feature1 = new FeatureReturningTrue1();
final CheckingFeature feature2 = new FeatureReturningTrue2();
final CheckingFeature feature3 = new FeatureReturningTrue3();
final CheckingFeature feature4 = new FeatureReturningTrue4();
feature1.addDisabledFeatures(feature2, feature3, feature4).setName("feature1");
feature2.addDisabledFeatures(feature3, feature4).addEnabledFeatures(feature1).setName("feature2");
feature3.addDisabledFeatures(feature4).addEnabledFeatures(feature1, feature2).setName("feature3");
feature4.addEnabledFeatures(feature1, feature2, feature3).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 jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method imutableWithRespectToUriQueryResolveTemplateTest.
/*
* @testName: imutableWithRespectToUriQueryResolveTemplateTest
*
* @assertion_ids: JAXRS:SPEC:66;
*
* @test_Strategy: WebTarget instances are immutable with respect to their URI
* (or URI template): methods for specifying additional path segments and
* parameters return a new instance of WebTarget.
*/
@Test
public void imutableWithRespectToUriQueryResolveTemplateTest() throws Fault {
IteratedList<WebTarget> targets = new IteratedList<WebTarget>(WebTarget.class);
Client client = ClientBuilder.newClient();
WebTarget target = client.target("");
targets.add(target);
targets.doWithAll("queryParam", "", new String[] { "" });
assertFaultEqualWebTargets(targets);
targets.doWithAll("queryParam", "path", new String[] { "xyz" });
assertFaultEqualWebTargets(targets);
targets.doWithAll("queryParam", "xyz", new String[] { "path" });
assertFaultEqualWebTargets(targets);
TestUtil.logMsg("checked queryParam() method");
targets.doWithAll("resolveTemplateFromEncoded", "", "");
assertFaultEqualWebTargets(targets);
targets.doWithAll("resolveTemplateFromEncoded", "path", "xyz");
assertFaultEqualWebTargets(targets);
targets.doWithAll("resolveTemplateFromEncoded", "path/path/path", "");
assertFaultEqualWebTargets(targets);
TestUtil.logMsg("checked resolveTemplateFromEncoded() method");
Map<String, Object> params = new HashMap<String, Object>();
params.put("", "path");
targets.doWithAll("resolveTemplates", params);
assertFaultEqualWebTargets(targets);
params = new HashMap<String, Object>();
params.put("path", "xyz");
targets.doWithAll("resolveTemplates", params);
assertFaultEqualWebTargets(targets);
TestUtil.logMsg("checked resolveTemplates() method");
targets.doWithAll("resolveTemplatesFromEncoded", params);
assertFaultEqualWebTargets(targets);
params = new HashMap<String, Object>();
params.put("path", "xyz");
targets.doWithAll("resolveTemplatesFromEncoded", params);
assertFaultEqualWebTargets(targets);
TestUtil.logMsg("checked resolveTemplatesFromEncoded() method");
}
Aggregations