use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method buildTarget.
protected static WebTarget buildTarget(ContextProvider... providers) {
Client client = ClientBuilder.newClient();
for (ContextProvider provider : providers) client.register(provider);
WebTarget target = client.target(getUrl());
return target;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getUriBuilderIsDetachedTest.
/*
* @testName: getUriBuilderIsDetachedTest
*
* @assertion_ids: JAXRS:JAVADOC:609;
*
* @test_Strategy: Get the URI builder initialized with the URI of the current
* resource target. The returned URI builder is detached from the target, i.e.
* any updates in the URI builder MUST NOT have any effects on the URI of the
* originating target.
*/
@Test
public void getUriBuilderIsDetachedTest() throws Fault {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(URL);
UriBuilder builder = target.getUriBuilder();
// The way to affect original target
client.close();
URI uri = builder.build();
assertContains(uri.toASCIIString(), URL);
logMsg("URI", uri, "contains", URL);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method requestMediaTypeTest.
/*
* @testName: requestMediaTypeTest
*
* @assertion_ids: JAXRS:JAVADOC:624;
*
* @test_Strategy: Start building a request to the targeted web resource and
* define the accepted response media types.
*/
@Test
public void requestMediaTypeTest() throws Fault {
WebTarget target = createWebTarget();
Response response = target.request(MediaType.APPLICATION_ATOM_XML_TYPE, MediaType.APPLICATION_JSON_TYPE, MediaType.TEXT_XML_TYPE).buildGet().invoke();
String body = response.readEntity(String.class);
assertContains(body, URL);
assertContains(body, MediaType.APPLICATION_ATOM_XML);
assertContains(body, MediaType.APPLICATION_JSON);
assertContains(body, MediaType.TEXT_XML);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method resolveTemplatesTest.
/*
* @testName: resolveTemplatesTest
*
* @assertion_ids: JAXRS:JAVADOC:946;
*
* @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 resolveTemplatesTest() 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", "pavement");
WebTarget target = createWebTarget();
target = target.path("{path}").path("{highway}").path("{sidewalk}");
target = target.resolveTemplates(map);
assertConfigurationSnapshot(target);
URI uri = target.getUri();
assertUriContains(uri, "/lane/route66/pavement");
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 matrixParamTest.
/*
* @testName: matrixParamTest
*
* @assertion_ids: JAXRS:JAVADOC:610;
*
* @test_Strategy: Create a new instance by appending a matrix parameter to
* the existing set of matrix parameters of the current final segment of the
* URI of the current target instance. If multiple values are supplied the
* parameter will be added once per value.
*/
@Test
public void matrixParamTest() throws Fault {
WebTarget target = createWebTarget();
target = target.matrixParam("matrix", "arg1", "arg2", "arg3");
assertConfigurationSnapshot(target);
URI uri = target.getUri();
assertContains(uri.toASCIIString(), ";matrix=arg1");
assertContains(uri.toASCIIString(), ";matrix=arg2");
assertContains(uri.toASCIIString(), ";matrix=arg3");
logMsg("URI", uri, "contains given matrix params");
}
Aggregations