use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method linkStringTest.
/*
* @testName: linkStringTest
*
* @assertion_ids: JAXRS:JAVADOC:1043; JAXRS:JAVADOC:1053;
*
* @test_Strategy: Initialize builder using another link represented as a
* string. Uses simple parser to convert string representation into a link.
*/
@Test
public void linkStringTest() throws Fault {
String title = "Ttttlll";
String rel = "RlrL";
String[] params = { "Param1", "parAM2", "paRam3" };
String[] values = { "vAlUe", "ValuEe", "VVallue" };
StringBuilder sb = new StringBuilder().append("<").append(url()).append(">;").append("rel=\"").append(rel).append("\";");
for (int i = 0; i != params.length; i++) sb = sb.append(params[i]).append("=\"").append(values[i]).append("\";");
sb = sb.append("title=\"").append(title).append("\";");
sb = sb.append("type=\"").append(MediaType.TEXT_XML).append("\"");
String originalLink = sb.toString();
Builder lb = RuntimeDelegate.getInstance().createLinkBuilder();
lb = lb.link(originalLink);
Link link = lb.build();
// rel & title is param of Link
assertContains(link.getRel(), rel, "link(Link) does not pass relation");
assertContains(link.getTitle(), title, "link(Link) does noot pass title");
assertContains(link.getType(), MediaType.TEXT_XML, "link(Link) does not pass type");
assertParams(link, params, values);
assertContains(link.toString(), url());
logMsg("parameters and underlaying URI were copied as expected to a new link", link);
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method linkLinkTest.
/*
* @testName: linkLinkTest
*
* @assertion_ids: JAXRS:JAVADOC:1042; JAXRS:JAVADOC:1053;
*
* @test_Strategy: Initialize builder using another link. Sets underlying URI
* and copies all parameters.
* jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
*/
@Test
public void linkLinkTest() throws Fault {
String title = "Ttttlll";
String rel = "RlrL";
String[] params = { "Param1", "parAM2", "paRam3" };
String[] values = { "vAlUe", "ValuEe", "VVallue" };
Builder lb = RuntimeDelegate.getInstance().createLinkBuilder();
lb = lb.baseUri(url()).title(title).rel(rel).type(MediaType.TEXT_XML);
for (int i = 0; i != params.length; i++) lb = lb.param(params[i], values[i]);
Link link = lb.build();
Builder lb2 = RuntimeDelegate.getInstance().createLinkBuilder();
lb2 = lb2.link(link);
link = lb2.build();
// rel & title is param of Link
assertContains(link.getRel(), rel, "link(Link) does not pass relation");
assertContains(link.getTitle(), title, "link(Link) does noot pass title");
assertContains(link.getType(), MediaType.TEXT_XML, "link(Link) does not pass type");
assertParams(link, params, values);
assertContains(link.toString(), url());
logMsg("parameters and underlaying URI were copied as expected to a new link", link);
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method linkStringThrowsIAETest.
/*
* @testName: linkStringThrowsIAETest
*
* @assertion_ids: JAXRS:JAVADOC:1043; JAXRS:JAVADOC:1053;
*
* @test_Strategy: Throws: java.lang.IllegalArgumentException - if string
* representation of URI is invalid.
*/
@Test
public void linkStringThrowsIAETest() throws Fault {
Builder lb = RuntimeDelegate.getInstance().createLinkBuilder();
try {
lb.link("<>>");
fault("IllegalArgumentException has not been throw when invalid uri");
} catch (IllegalArgumentException e) {
logMsg("IllegalArgumentException has been thrown as expected");
}
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method buildRelativizedThrowsIAEWhenNotSuppliedValuesTest.
/*
* @testName: buildRelativizedThrowsIAEWhenNotSuppliedValuesTest
*
* @assertion_ids: JAXRS:JAVADOC:1054;
*
* @test_Strategy: Throws: java.lang.IllegalArgumentException - if there are any
* URI template parameters without a supplied value
*/
@Test
public void buildRelativizedThrowsIAEWhenNotSuppliedValuesTest() throws Fault {
// rfc6570
Builder linkBuilder = Link.fromUri(url() + "{x1}/{x2}/{x3}");
URI respect = null;
try {
respect = new URI(url());
} catch (URISyntaxException e) {
fault(e);
}
try {
Link link = linkBuilder.buildRelativized(respect);
fault("IllegalArgumentException has not been thrown when value is not supplied, link=", link.toString());
} catch (IllegalArgumentException iae) {
logMsg("IllegalArgumentException has been thrown as expected when a value has not been supplied");
}
}
use of jakarta.ws.rs.core.Link.Builder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method fromPathTest.
/*
* @testName: fromPathTest
*
* @assertion_ids: JAXRS:JAVADOC:1038;
*
* @test_Strategy: Convenience method to build a link from a path. Equivalent to
* fromUriBuilder(UriBuilder.fromPath(path)).
*/
@Test
public void fromPathTest() throws Fault {
String path = "somewhere/somehow";
UriBuilder builder = UriBuilder.fromPath(path);
Link.Builder linkBuilder = Link.fromUriBuilder(builder);
Link.Builder fromPathBuilder = Link.fromPath(path);
String fromUriBuilderString = linkBuilder.build().toString();
String fromPathString = fromPathBuilder.build().toString();
assertEquals(fromUriBuilderString, fromPathString, "fromUriBuilder()=", fromUriBuilderString, "differs from Link.fromPath()", fromPathString);
logMsg("fromUriBuilder(UriBuilder.fromPath(path)) is equivalent to fromPath(path)", "The link is", fromPathString);
}
Aggregations