use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityGenericTypeThrowsIllegalStateExceptionTest.
/*
* @testName: readEntityGenericTypeThrowsIllegalStateExceptionTest
*
* @assertion_ids: JAXRS:JAVADOC:866;
*
* @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 readEntityGenericTypeThrowsIllegalStateExceptionTest() 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(generic(String.class));
assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(GenericType<byte[]>)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
try {
response.readEntity(generic(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 readEntityClassAnnotationThrowsIllegalStateExceptionTest.
/*
* @testName: readEntityClassAnnotationThrowsIllegalStateExceptionTest
*
* @assertion_ids: JAXRS:JAVADOC:869;
*
* @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 readEntityClassAnnotationThrowsIllegalStateExceptionTest() 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(String.class, annotations);
assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(String.class, annotations)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
try {
response.readEntity(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 isEnabledFeatureClassReturningTrueTest.
/*
* @testName: isEnabledFeatureClassReturningTrueTest
*
* @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 isEnabledFeatureClassReturningTrueTest() throws Fault {
final CheckingFeature feature1 = new FeatureReturningTrue1();
final CheckingFeature feature2 = new FeatureReturningTrue2();
final CheckingFeature feature3 = new FeatureReturningTrue3();
final CheckingFeature feature4 = new FeatureReturningTrue4();
feature1.addDisabledClasses(FeatureReturningTrue2.class, FeatureReturningTrue3.class, FeatureReturningTrue4.class).setName("feature1");
feature2.addDisabledClasses(FeatureReturningTrue3.class, FeatureReturningTrue4.class).addEnabledClasses(FeatureReturningTrue1.class).setName("feature2");
feature3.addDisabledClasses(FeatureReturningTrue4.class).addEnabledClasses(FeatureReturningTrue1.class, FeatureReturningTrue2.class).setName("feature3");
feature4.addEnabledClasses(FeatureReturningTrue1.class, FeatureReturningTrue2.class, FeatureReturningTrue3.class).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 imutableWithRespectToUriMatrixPathTest.
/* Run test */
/*
* @testName: imutableWithRespectToUriMatrixPathTest
*
* @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 imutableWithRespectToUriMatrixPathTest() throws Fault {
IteratedList<WebTarget> targets = new IteratedList<WebTarget>(WebTarget.class);
Client client = ClientBuilder.newClient();
WebTarget target = client.target("");
targets.add(target);
targets.doWithAll("matrixParam", "", new String[] { "" });
assertFaultEqualWebTargets(targets);
targets.doWithAll("matrixParam", "matrix", new String[] { "st" });
assertFaultEqualWebTargets(targets);
TestUtil.logMsg("checked matrixParam() method");
targets.doWithAll("path", "");
assertFaultEqualWebTargets(targets);
targets.doWithAll("path", "/");
assertFaultEqualWebTargets(targets);
targets.doWithAll("path", "path");
assertFaultEqualWebTargets(targets);
targets.doWithAll("path", "path/path/path");
assertFaultEqualWebTargets(targets);
TestUtil.logMsg("checked path() method");
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method startBuilderForMethod.
protected Invocation.Builder startBuilderForMethod(String methodName) {
Client client = ClientBuilder.newClient();
client.register(new JdkLoggingFilter(false));
WebTarget target = client.target(getAbsoluteUrl(methodName));
Invocation.Builder ib = target.request();
return ib;
}
Aggregations