use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method relTest.
/*
* @testName: relTest
*
* @assertion_ids: JAXRS:JAVADOC:809; JAXRS:JAVADOC:1053;
*
* @test_Strategy: Convenience method to set a link relation. More than one rel
* value can be specified using this method.
*
* jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
*/
@Test
public void relTest() throws Fault {
String[] names = { "name1", "name2" };
Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
for (String name : names) {
Link link = builder.rel(name).build();
assertTrue(link.getRel().contains(name), "Rel " + name + " not found in " + link);
}
logMsg("#rel added expected relations");
}
use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method marshallTest.
/*
* @testName: marshallTest
*
* @assertion_ids: JAXRS:JAVADOC:815; JAXRS:JAVADOC:816;
*
* @test_Strategy:
*/
@Test
public void marshallTest() throws Fault {
Link link = RuntimeDelegate.getInstance().createLinkBuilder().uri(url).title(title).rel(rel).type(media).param(param_names[0], param_vals[0]).param(param_names[1], param_vals[1]).build();
Model model = new Model(link);
ByteArrayOutputStream ostream = new ByteArrayOutputStream(1000);
JAXBContext jc = null;
Marshaller marshaller = null;
byte[] array = null;
try {
jc = JAXBContext.newInstance(Model.class);
marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(model, ostream);
array = ostream.toByteArray();
String string = new String(array, Charset.defaultCharset());
assertContains(string, "link href=", "Marshalled Link", string, "does not contain expected uri reference field");
assertContains(string, url, "Marshalled Link", string, " does not contain expected uri reference", url);
assertContains(string, media, "MediaType has not been marshalled in", string);
assertContains(string, title, "Title has not been marshalled in", string);
assertContains(string, rel, "Relation has not been marshalled in", string);
assertContains(string, param_names[0], "parameter name", param_names[0], "has not been marshalled in", string);
assertContains(string, param_names[1], "parameter name", param_names[1], "has not been marshalled in", string);
assertContains(string, param_vals[0], "parameter value", param_vals[0], "has not been marshalled in", string);
assertContains(string, param_vals[1], "parameter value", param_vals[1], "has not been marshalled in", string);
logMsg("Marshalled Link contains expected", string);
} catch (JAXBException e) {
throw new Fault(e);
}
// return array;
}
use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLinksTest.
/*
* @testName: getLinksTest
*
* @assertion_ids: JAXRS:JAVADOC:855;
*
* @test_Strategy: Get the links attached to the message as header.
*/
@Test
public void getLinksTest() throws Fault {
Link link1 = createLink("path1", "rel1");
Link link2 = createLink("path2", "rel2");
Response response = Response.ok().links(link1, link2).build();
Set<Link> responseLinks = response.getLinks();
assertEqualsInt(responseLinks.size(), 2, "#getLinks() returned set of unexpected size", responseLinks.size());
assertTrue(responseLinks.contains(link1), "#getLinks does not contain" + link1);
assertTrue(responseLinks.contains(link2), "#getLinks does not contain" + link2);
logMsg("#getLinks contains expected links");
}
use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLinkNotPresentTest.
/*
* @testName: getLinkNotPresentTest
*
* @assertion_ids: JAXRS:JAVADOC:853;
*
* @test_Strategy: returns null if not present.
*/
@Test
public void getLinkNotPresentTest() throws Fault {
Response response = Response.ok().build();
Link responseLink = response.getLink("getLinkTest");
assertTrue(responseLink == null, "#getLink() returned unexpected Link" + responseLink);
logMsg("#getLink return null as expected");
}
use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method invocationFromLinkWithMediaType.
// /////////////////////////////////////////////////////////////////////////
protected Response invocationFromLinkWithMediaType(String mediaType) throws Fault {
String url = "mediatype";
Client client = ClientBuilder.newClient();
client.register(new JdkLoggingFilter(false));
URI uri = UriBuilder.fromPath(getUrl(url)).build();
Link link = Link.fromUri(uri).type(mediaType).build();
Invocation i = client.invocation(link).buildGet();
Response response = i.invoke();
return response;
}
Aggregations