Search in sources :

Example 56 with Link

use of jakarta.ws.rs.core.Link 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 57 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method hasLinkWhenLinkTest.

/*
   * @testName: hasLinkWhenLinkTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:862;
   * 
   * @test_Strategy: Check if link for relation exists.
   */
@Test
public void hasLinkWhenLinkTest() throws Fault {
    Link link = createLink("path", "rel");
    Response response = Response.ok().links(link).build();
    assertTrue(response.hasLink("rel"), "#hasLink did not found a Link");
    logMsg("#hasEntity found the Link as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 58 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getLinkTest.

/*
   * @testName: getLinkTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:853;
   * 
   * @test_Strategy: Get the link for the relation.
   */
@Test
public void getLinkTest() throws Fault {
    Link link = createLink("path", "getLinkTest");
    Response response = Response.ok().links(link).build();
    Link responseLink = response.getLink("getLinkTest");
    assertTrue(link.equals(responseLink), "#getLink() returned unexpected Link" + responseLink);
    logMsg("#getLink matches expected Link");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 59 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getLinkBuilderForTheRelationTest.

/*
   * @testName: getLinkBuilderForTheRelationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:854;
   * 
   * @test_Strategy: Convenience method that returns a Link.Builder for the
   * relation.
   */
@Test
public void getLinkBuilderForTheRelationTest() throws Fault {
    String rel = "anyrelation";
    Response response = Response.ok().link("http://abc.com/b/", rel).build();
    Link builderLink = response.getLinkBuilder("anyrelation").build();
    response = Response.ok().links(builderLink).build();
    Link responseLink = response.getLink("anyrelation");
    assertNotNull(responseLink, "#getLinkBuilder('relation') returned null");
    logMsg("#getLinkBuilder creates correct Link for given relation");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 60 with Link

use of jakarta.ws.rs.core.Link 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

Link (jakarta.ws.rs.core.Link)84 Test (org.junit.jupiter.api.Test)69 Builder (jakarta.ws.rs.core.Link.Builder)37 UriBuilder (jakarta.ws.rs.core.UriBuilder)27 Response (jakarta.ws.rs.core.Response)23 URI (java.net.URI)19 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)14 URISyntaxException (java.net.URISyntaxException)7 Path (jakarta.ws.rs.Path)4 POST (jakarta.ws.rs.POST)3 Client (jakarta.ws.rs.client.Client)3 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)3 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)3 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)3 GET (jakarta.ws.rs.GET)2 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)2 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 Marshaller (jakarta.xml.bind.Marshaller)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2