Search in sources :

Example 76 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:467; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the link for the relation.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLinkTest() throws Fault {
    final String rel = "RELATION";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Link link = responseContext.getLink(rel);
            assertTrue(link != null, "the #getLink is null");
            assertTrue(link.getUri() != null, "the #getLink.getUri is null");
            assertTrue(link.getUri().toASCIIString().contains(getUrl()), "#getLink was supposed to contain " + getUrl() + " but was " + link.getUri().toASCIIString());
            logMsg("Found #getLink()=", link.getUri().toASCIIString());
        }
    };
    Response response = Response.ok().link(getUrl(), rel).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 77 with Link

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:469; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the links attached to the message as header.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLinksTest() throws Fault {
    final Link link = Link.fromUri(getUrl()).build();
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Set<Link> links = responseContext.getLinks();
            assertTrue(links != null, "the #getLinks is null");
            assertTrue(links.size() == 1, "the links was supposed to be of size 1, was " + links.size());
            assertTrue(links.contains(link), "#getLinks was supposed to contain " + link.getUri().toASCIIString());
            logMsg("Found #getLinks()={", link.getUri().toASCIIString(), "}");
        }
    };
    Response response = Response.ok().links(link).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 78 with Link

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

the class JAXRSClientIT method closeOnClientTargetWithLinkTest.

/*
   * @testName: closeOnClientTargetWithLinkTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:409;
   * 
   * @test_Strategy: Close client instance and all it's associated resources.
   * Subsequent calls have no effect and are ignored. Once the client is closed,
   * invoking any other method on the client instance would result in an
   * IllegalStateException being thrown. Calling this method effectively
   * invalidates all WebTarget resource targets produced by the client instance.
   * Invoking any method on such targets once the client is closed would result
   * in an IllegalStateException being thrown.
   */
@Test
public void closeOnClientTargetWithLinkTest() throws Fault {
    client.close();
    Link link = Link.fromUri("cts").build();
    assertException(IllegalStateException.class, client, "target", link);
}
Also used : Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 79 with Link

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

the class JAXRSClientIT method closeOnClientTargetWithUriBuilderTest.

/*
   * @testName: closeOnClientTargetWithUriBuilderTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:409;
   * 
   * @test_Strategy: Close client instance and all it's associated resources.
   * Subsequent calls have no effect and are ignored. Once the client is closed,
   * invoking any other method on the client instance would result in an
   * IllegalTStateException being thrown. Calling this method effectively
   * invalidates all WebTarget resource targets produced by the client instance.
   * Invoking any method on such targets once the client is closed would result
   * in an IllegalStateException being thrown.
   */
@Test
public void closeOnClientTargetWithUriBuilderTest() throws Fault {
    client.close();
    Link link = Link.fromUri("cts").build();
    UriBuilder builder = UriBuilder.fromUri(link.getUri());
    assertException(IllegalStateException.class, client, "target", builder);
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 80 with Link

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

the class JAXRSClientIT method targetLinkTest.

/*
   * @testName: targetLinkTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:420;
   * 
   * @test_Strategy: Build a new web resource target.
   */
@Test
public void targetLinkTest() throws Fault {
    URI uri = UriBuilder.fromPath(getUrl("call")).build();
    Link link = Link.fromUri(uri).build();
    target = client.target(link);
    assertTrue(target != null, "WebTarget is null");
}
Also used : URI(java.net.URI) 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