Search in sources :

Example 21 with Link

use of javax.ws.rs.core.Link in project cxf by apache.

the class ResponseImplTest method testGetLinks.

@Test
public void testGetLinks() {
    ResponseImpl ri = new ResponseImpl(200);
    MetadataMap<String, Object> meta = new MetadataMap<String, Object>();
    ri.addMetadata(meta);
    assertFalse(ri.hasLink("next"));
    assertNull(ri.getLink("next"));
    assertFalse(ri.hasLink("prev"));
    assertNull(ri.getLink("prev"));
    meta.add(HttpHeaders.LINK, "<http://localhost:8080/next;a=b>;rel=next");
    meta.add(HttpHeaders.LINK, "<http://prev>;rel=prev");
    assertTrue(ri.hasLink("next"));
    Link next = ri.getLink("next");
    assertNotNull(next);
    assertTrue(ri.hasLink("prev"));
    Link prev = ri.getLink("prev");
    assertNotNull(prev);
    Set<Link> links = ri.getLinks();
    assertTrue(links.contains(next));
    assertTrue(links.contains(prev));
    assertEquals("http://localhost:8080/next;a=b", next.getUri().toString());
    assertEquals("next", next.getRel());
    assertEquals("http://prev", prev.getUri().toString());
    assertEquals("prev", prev.getRel());
}
Also used : Link(javax.ws.rs.core.Link) Test(org.junit.Test)

Example 22 with Link

use of javax.ws.rs.core.Link in project cxf by apache.

the class BookStoreSpring method getBookLink.

@GET
@Path("/link")
public Response getBookLink() {
    URI selfUri = ui.getBaseUriBuilder().path(BookStoreSpring.class).build();
    Link link = Link.fromUri(selfUri).rel("self").build();
    return Response.ok().links(link).build();
}
Also used : URI(java.net.URI) Link(javax.ws.rs.core.Link) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 23 with Link

use of javax.ws.rs.core.Link in project tomee by apache.

the class LinkTest method get.

@Test
public void get() throws IOException {
    final Response response = ClientBuilder.newClient().target(base.toExternalForm()).path("openejb/link").property("org.apache.cxf.http.header.split", true).request(WILDCARD_TYPE).get();
    assertEquals(2, Collection.class.cast(response.getHeaders().get("a")).size());
    final Set<Link> actual = response.getLinks();
    assertEquals(2, actual.size());
    final Set<Link> expected = new LinkEndpoint().doLink().getLinks();
    assertEquals(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) Link(javax.ws.rs.core.Link) Test(org.junit.Test)

Example 24 with Link

use of javax.ws.rs.core.Link in project jersey by jersey.

the class JerseyClientTest method testCreateLinkBasedInvocation.

/**
     * Regression test for JERSEY-1192.
     */
@Test
public void testCreateLinkBasedInvocation() {
    final JerseyClient jerseyClient = new JerseyClient();
    try {
        jerseyClient.invocation(null);
        fail("NullPointerException expected.");
    } catch (NullPointerException ex) {
    // success.
    }
    try {
        jerseyClient.invocation(null);
        fail("NullPointerException expected.");
    } catch (NullPointerException ex) {
    // success.
    }
    Link link1 = Link.fromUri(UriBuilder.fromPath("http://localhost:8080/").build()).build();
    Link link2 = Link.fromUri(UriBuilder.fromPath("http://localhost:8080/").build()).type("text/plain").build();
    assertNotNull(jerseyClient.invocation(link1).buildPost(null));
    assertNotNull(jerseyClient.invocation(link2).buildPost(null));
    assertNotNull(jerseyClient.invocation(link1).buildPost(Entity.text("Test.")));
    assertNotNull(jerseyClient.invocation(link2).buildPost(Entity.text("Test.")));
    assertNotNull(jerseyClient.invocation(link1).buildPost(Entity.xml("Test.")));
    assertNotNull(jerseyClient.invocation(link2).buildPost(Entity.xml("Test.")));
}
Also used : Link(javax.ws.rs.core.Link) Test(org.junit.Test)

Example 25 with Link

use of javax.ws.rs.core.Link in project jersey by jersey.

the class LinkTest method testInvocationFromLinkNoEntity.

@Test
public void testInvocationFromLinkNoEntity() {
    Link l = Link.fromUri("http://examples.org/app").type("text/plain").build();
    assertNotNull(l);
    javax.ws.rs.client.Invocation i = client.invocation(l).buildGet();
    assertNotNull(i);
}
Also used : Link(javax.ws.rs.core.Link) Test(org.junit.Test)

Aggregations

Link (javax.ws.rs.core.Link)51 Test (org.junit.Test)44 URI (java.net.URI)7 Response (javax.ws.rs.core.Response)5 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 WebTarget (javax.ws.rs.client.WebTarget)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 Type (java.lang.reflect.Type)1 ParseException (java.text.ParseException)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1