use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getRelsTest.
/*
* @testName: getRelsTest
*
* @assertion_ids: JAXRS:JAVADOC:956;
*
* @test_Strategy: Returns the value associated with the link "rel" param as a
* list of strings or the empty list if "rel" is not defined.
*/
@Test
public void getRelsTest() throws Fault {
String[] rels = { "RELREL", "REL", "relrelrel", "RELRELREL" };
Builder builder = Link.fromUri(uri("get"));
for (int i = 0; i != rels.length; i++) builder = builder.rel(rels[i]);
Link link = builder.build();
assertNotNull(link.getRels(), "#getRels is null");
assertEqualsInt(link.getRels().size(), 4, "Unexpected #getRels size", link.getRels().size(), "Should be 4");
String list = ";" + JaxrsUtil.iterableToString(";", link.getRels()) + ";";
for (int i = 0; i != rels.length; i++) assertContains(list, ";" + rels[i] + ";", "Relation", rels[i], "has not been found in #getRels", list);
logMsg("#getRel() return expected rels", list);
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getUriTest.
/*
* @testName: getUriTest
*
* @assertion_ids: JAXRS:JAVADOC:796;
*
* @test_Strategy: Returns the underlying URI associated with this link.
*/
@Test
public void getUriTest() throws Fault {
URI uri = uri("get");
Builder builder = Link.fromUri(uri);
Link link = builder.build();
URI uriFromLink = link.getUri();
assertTrue(uri.equals(uriFromLink), "#getUri() " + uriFromLink + " differes from original uri " + uri);
logMsg("Original URI", uri, "equals obtained", uriFromLink);
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method fromResourceMethodLinkUsedInInvocationTest.
/*
* @testName: fromResourceMethodLinkUsedInInvocationTest
*
* @assertion_ids: JAXRS:JAVADOC:787;
*
* @test_Strategy: Generate a link by introspecting a resource method.
*/
@Test
public void fromResourceMethodLinkUsedInInvocationTest() throws Fault {
final String linkName = "link";
Client client = ClientBuilder.newClient();
client.register(new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext ctx) throws IOException {
String uri = ctx.getUri().toASCIIString();
Link.Builder builder = Link.fromMethod(Resource.class, "consumesAppJson").rel(linkName);
Link link = builder.build();
Response response = Response.ok(uri).links(link).build();
ctx.abortWith(response);
}
});
// Phase 1, ask for a link;
WebTarget target = client.target(url() + "resource/get");
Response response = target.request().get();
String entity = response.readEntity(String.class);
assertTrue(response.hasLink(linkName), "No link received");
assertContains(url() + "resource/get", entity);
// Phase 2, use the link, check the correctness
assertTrue(response.hasLink(linkName), "No link received");
Link link = response.getLink(linkName);
response = client.invocation(link).post(null);
entity = response.readEntity(String.class);
assertTrue(response.hasLink(linkName), "No link received");
assertContains(url() + "resource/consumesappjson", entity);
logMsg("Opaque Link has been used in Client.invocation() sucessfully");
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method paramTest.
/*
* @testName: paramTest
*
* @assertion_ids: JAXRS:JAVADOC:807; JAXRS:JAVADOC:1053;
*
* @test_Strategy: Set an arbitrary parameter on this link.
*
* jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
*/
@Test
public void paramTest() throws Fault {
String[] params = { "param1", "param2" };
String[] values = { "param1value1", "param1value2" };
Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
builder = builder.param(params[0], values[0]).param(params[1], values[1]);
Link link = builder.build();
assertParams(link, params, values);
logMsg("#param set correct parameters");
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method buildRelativizedTest.
/*
* @testName: buildRelativizedTest
*
* @assertion_ids: JAXRS:JAVADOC:1054; JAXRS:JAVADOC:1053;
*
* @test_Strategy: Finish building this link using the supplied values as URI
* parameters and relativize the result with respect to the supplied URI.
* jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
*/
@Test
public void buildRelativizedTest() throws Fault {
String relative = "a/b/c";
URI underlay = uri(relative), respect = uri("");
Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
linkBuilder = linkBuilder.uri(underlay);
Link link = linkBuilder.buildRelativized(respect);
assertFalse(link.toString().contains(url()), "Found unexpected absolute path " + url());
assertContains(link.toString(), relative);
logMsg("Absolute", url(), "has not been found as expected in link", link.toString());
}
Aggregations