use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method resolveTemplatesWithBooleanTrueTest.
/*
* @testName: resolveTemplatesWithBooleanTrueTest
*
* @assertion_ids: JAXRS:JAVADOC:948;
*
* @test_Strategy: Create a new WebTarget instance by resolving one or more
* URI templates in the URI of the current target instance using supplied
* name-value pairs. A call to the method with an empty parameter map is
* ignored, i.e. same WebTarget instance is returned. A snapshot of the
* present configuration of the current (parent) target instance is taken and
* is inherited by the newly constructed (child) target instance.
*/
@Test
public void resolveTemplatesWithBooleanTrueTest() throws Fault {
Map<String, Object> map = new TreeMap<String, Object>();
map.put("path", new StringBuilder().append("lane"));
map.put("highway", new StringBuffer().append("route66"));
map.put("sidewalk", SLASHED);
WebTarget target = createWebTarget();
target = target.path("{path}").path("{highway}").path("{sidewalk}");
target = target.resolveTemplates(map, true);
assertConfigurationSnapshot(target);
URI uri = target.getUri();
assertUriContains(uri, "/lane/route66/" + SLASHED.replace("%", "%25").replace("/", "%2F"));
logMsg("URI", uri, "contains given path parameters");
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method resolveTemplatesWithBooleanNullNameTest.
/*
* @testName: resolveTemplatesWithBooleanNullNameTest
*
* @assertion_ids: JAXRS:JAVADOC:948;
*
* @test_Strategy: NullPointerException - if the name-value map or any of the
* names or values in the map is null.
*/
@Test
public void resolveTemplatesWithBooleanNullNameTest() throws Fault {
Map<String, Object> map = new HashMap<String, Object>();
map.put(null, "xyz");
WebTarget target = createWebTarget();
try {
target.path("{path}").resolveTemplates(map, false);
throw new Fault("NullPointerException has not been thrown");
} catch (NullPointerException npe) {
logMsg("NullPointerException has been thrown as expected", npe);
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method resolveTemplatesFromEncodedThrowsNPEForNullValueTest.
/*
* @testName: resolveTemplatesFromEncodedThrowsNPEForNullValueTest
*
* @assertion_ids: JAXRS:JAVADOC:950;
*
* @test_Strategy: NullPointerException - if the name-value map or any of the
* names or encoded values in the map is null.
*/
@Test
public void resolveTemplatesFromEncodedThrowsNPEForNullValueTest() throws Fault {
WebTarget target = createWebTarget();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("path", null);
try {
target.path("{path}").resolveTemplatesFromEncoded(map);
throw new Fault("NullPointerException has not been thrown");
} catch (NullPointerException npe) {
logMsg("NullPointerException has been thrown as expected", npe);
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method invokeWithClientRequestFilters.
// ////////////////////////////////////////////////////////////////////
protected Response invokeWithClientRequestFilters(ClientRequestFilter... filters) {
Client client = ClientBuilder.newClient();
for (ClientRequestFilter filter : filters) client.register(filter);
WebTarget target = client.target("http://nourl/");
Response response = target.request().buildGet().invoke();
return response;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method hasEntityTest.
/*
* @testName: hasEntityTest
*
* @assertion_ids: JAXRS:JAVADOC:448; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Check if there is an entity available in the request. The
* method returns true if the entity is present, returns false otherwise.
*
* ClientRequestFilter.abortWith
*/
@Test
public void hasEntityTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
boolean has = context.hasEntity();
String entity = String.valueOf(has);
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Invocation invocation = buildInvocation(provider);
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(body, "false");
Entity<String> entity = createEntity("TEST");
WebTarget target = buildTarget(provider);
invocation = target.request().buildPost(entity);
response = invoke(invocation);
body = response.readEntity(String.class);
assertContains(body, "true");
}
Aggregations