Search in sources :

Example 36 with Builder

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);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 37 with Builder

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);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 38 with Builder

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");
    }
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 39 with Builder

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");
    }
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 40 with Builder

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);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Aggregations

Builder (jakarta.ws.rs.core.Link.Builder)48 Test (org.junit.jupiter.api.Test)46 Link (jakarta.ws.rs.core.Link)37 UriBuilder (jakarta.ws.rs.core.UriBuilder)34 URI (java.net.URI)18 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)16 URISyntaxException (java.net.URISyntaxException)9 Response (jakarta.ws.rs.core.Response)4 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)3 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)2 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)1 Client (jakarta.ws.rs.client.Client)1 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 WebTarget (jakarta.ws.rs.client.WebTarget)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1