Search in sources :

Example 61 with Link

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

the class JAXRSClientIT method getParamsFromBuilderTest.

/*
     * @testName: getParamsFromBuilderTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:792;
     * 
     * @test_Strategy: Returns an immutable map that includes all the link
     * parameters defined on this link. If defined, this map will include entries
     * for "rel", "title" and "type".
     */
@Test
public void getParamsFromBuilderTest() throws Fault {
    Builder builder = Link.fromUri(uri("get"));
    builder.rel("RELREL").title("TITLETITLE").type("TYPETYPE").param("NEWPARAM", "NEWPARAMVALUE");
    Link link = builder.build();
    String value;
    Map<String, String> params = link.getParams();
    value = params.get("title");
    assertContains(value, "titletitle");
    value = params.get("rel");
    assertContains(value, "RELREL");
    value = params.get("type");
    assertContains(value, "typetype");
    value = params.get("NEWPARAM");
    assertContains(value, "newparamvalue");
    logMsg(params, "found as expected");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 62 with Link

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

the class JAXRSClientIT method fromResourceThrowsIAEWhenNullClassTest.

/*
     * @testName: fromResourceThrowsIAEWhenNullClassTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1039;
     * 
     * @test_Strategy: IllegalArgumentException - if any argument is null or no
     * method is found.
     */
@Test
public void fromResourceThrowsIAEWhenNullClassTest() throws Fault {
    try {
        Link link = Link.fromResource((Class<?>) null).build();
        logMsg("Unexpectedly thrown no exception and created link", link);
    } catch (IllegalArgumentException e) {
        logMsg("IllegalArgumentException has been thrown as expected", e);
    }
}
Also used : Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 63 with Link

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

the class JAXRSClientIT method fromPathWithUriTemplateParamsTest.

/*
     * @testName: fromPathWithUriTemplateParamsTest
     * 
     * @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 fromPathWithUriTemplateParamsTest() throws Fault {
    String path = "somewhere/somehow/{p1}/{p2}";
    String param1 = "param1", param2 = "param2";
    UriBuilder builder = UriBuilder.fromPath(path);
    Link.Builder linkBuilder = Link.fromUriBuilder(builder);
    Link.Builder fromPathBuilder = Link.fromPath(path);
    String fromUriBuilderString = linkBuilder.build(param1, param2).toString();
    String fromPathString = fromPathBuilder.build(param1, param2).toString();
    assertEquals(fromUriBuilderString, fromPathString, "fromUriBuilder(UriBuilder.fromPath(,", path, "))=", fromUriBuilderString, "differs from Link.fromPath(", path, ")", 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)

Example 64 with Link

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

the class JAXRSClientIT method getRelsIsEmptyTest.

/*
     * @testName: getRelsIsEmptyTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:956;
     * 
     * @test_Strategy: Returns the value associated with the link "rel" param as a
     * list of strings or the empty list if "rel" is not defined.
     */
@Test
public void getRelsIsEmptyTest() throws Fault {
    Builder builder = Link.fromUri(uri("get"));
    Link link = builder.build();
    assertNotNull(link.getRels(), "#getRels is null");
    assertEqualsInt(link.getRels().size(), 0, "Unexpected #getRels size", link.getRels().size(), "Should be 0");
    logMsg("#getRel() return empty list as expected");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 65 with Link

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

the class JAXRSClientIT method fromResourceWithMediaTypeTest.

/*
     * @testName: fromResourceWithMediaTypeTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1004;
     * 
     * @test_Strategy: Convenience method to build a link from a resource.
     */
@Test
public void fromResourceWithMediaTypeTest() throws Fault {
    Link link = Link.fromResource(ResourceWithProduces.class).build();
    String resource = link.toString();
    assertContains(resource, "<producesresource>");
    assertNotContains(resource, "type=\"" + MediaType.TEXT_HTML + "\"");
    logMsg("Link", resource, "has been created");
}
Also used : 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