Search in sources :

Example 21 with Link

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

the class JAXRSClientIT method relTest.

/*
     * @testName: relTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:809; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Convenience method to set a link relation. More than one rel
     * value can be specified using this method.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void relTest() throws Fault {
    String[] names = { "name1", "name2" };
    Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
    for (String name : names) {
        Link link = builder.rel(name).build();
        assertTrue(link.getRel().contains(name), "Rel " + name + " not found in " + link);
    }
    logMsg("#rel added expected relations");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 22 with Link

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

the class JAXRSClientIT method marshallTest.

/*
     * @testName: marshallTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:815; JAXRS:JAVADOC:816;
     * 
     * @test_Strategy:
     */
@Test
public void marshallTest() throws Fault {
    Link link = RuntimeDelegate.getInstance().createLinkBuilder().uri(url).title(title).rel(rel).type(media).param(param_names[0], param_vals[0]).param(param_names[1], param_vals[1]).build();
    Model model = new Model(link);
    ByteArrayOutputStream ostream = new ByteArrayOutputStream(1000);
    JAXBContext jc = null;
    Marshaller marshaller = null;
    byte[] array = null;
    try {
        jc = JAXBContext.newInstance(Model.class);
        marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(model, ostream);
        array = ostream.toByteArray();
        String string = new String(array, Charset.defaultCharset());
        assertContains(string, "link href=", "Marshalled Link", string, "does not contain expected uri reference field");
        assertContains(string, url, "Marshalled Link", string, " does not contain expected uri reference", url);
        assertContains(string, media, "MediaType has not been marshalled in", string);
        assertContains(string, title, "Title has not been marshalled in", string);
        assertContains(string, rel, "Relation has not been marshalled in", string);
        assertContains(string, param_names[0], "parameter name", param_names[0], "has not been marshalled in", string);
        assertContains(string, param_names[1], "parameter name", param_names[1], "has not been marshalled in", string);
        assertContains(string, param_vals[0], "parameter value", param_vals[0], "has not been marshalled in", string);
        assertContains(string, param_vals[1], "parameter value", param_vals[1], "has not been marshalled in", string);
        logMsg("Marshalled Link contains expected", string);
    } catch (JAXBException e) {
        throw new Fault(e);
    }
// return array;
}
Also used : Marshaller(jakarta.xml.bind.Marshaller) JAXBException(jakarta.xml.bind.JAXBException) JAXBContext(jakarta.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 23 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:855;
   * 
   * @test_Strategy: Get the links attached to the message as header.
   */
@Test
public void getLinksTest() throws Fault {
    Link link1 = createLink("path1", "rel1");
    Link link2 = createLink("path2", "rel2");
    Response response = Response.ok().links(link1, link2).build();
    Set<Link> responseLinks = response.getLinks();
    assertEqualsInt(responseLinks.size(), 2, "#getLinks() returned set of unexpected size", responseLinks.size());
    assertTrue(responseLinks.contains(link1), "#getLinks does not contain" + link1);
    assertTrue(responseLinks.contains(link2), "#getLinks does not contain" + link2);
    logMsg("#getLinks contains expected links");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 24 with Link

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

the class JAXRSClientIT method getLinkNotPresentTest.

/*
   * @testName: getLinkNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:853;
   * 
   * @test_Strategy: returns null if not present.
   */
@Test
public void getLinkNotPresentTest() throws Fault {
    Response response = Response.ok().build();
    Link responseLink = response.getLink("getLinkTest");
    assertTrue(responseLink == null, "#getLink() returned unexpected Link" + responseLink);
    logMsg("#getLink return null as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 25 with Link

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

the class JAXRSClientIT method invocationFromLinkWithMediaType.

// /////////////////////////////////////////////////////////////////////////
protected Response invocationFromLinkWithMediaType(String mediaType) throws Fault {
    String url = "mediatype";
    Client client = ClientBuilder.newClient();
    client.register(new JdkLoggingFilter(false));
    URI uri = UriBuilder.fromPath(getUrl(url)).build();
    Link link = Link.fromUri(uri).type(mediaType).build();
    Invocation i = client.invocation(link).buildGet();
    Response response = i.invoke();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) JdkLoggingFilter(ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter) Invocation(jakarta.ws.rs.client.Invocation) Client(jakarta.ws.rs.client.Client) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) URI(java.net.URI) Link(jakarta.ws.rs.core.Link)

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