Search in sources :

Example 41 with Builder

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

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

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

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

the class JAXRSClientIT method fromUriBuilderTest.

/*
     * @testName: fromUriBuilderTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1005;
     * 
     * @test_Strategy: Create a new builder instance initialized from a URI builder.
     */
@Test
public void fromUriBuilderTest() throws Fault {
    String segment = "goto/label/ten/";
    Link link = Link.fromUri(uri(segment)).build();
    UriBuilder builder = link.getUriBuilder();
    Builder fromBuilder = Link.fromUriBuilder(builder);
    String sBuilder = builder.build().toASCIIString();
    String sFromBuilder = fromBuilder.build().getUri().toASCIIString();
    assertContains(sFromBuilder, sBuilder, "Original builder", sBuilder, "not found in #fromUriBuilder", sFromBuilder);
    logMsg("#fromUriBuilder", sFromBuilder, "contains the original", sBuilder);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 45 with Builder

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

the class JAXRSClientIT method getTitleTest.

/*
     * @testName: getTitleTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:794;
     * 
     * @test_Strategy: Returns the value associated with the link "title" param, or
     * null if this param is not specified.
     */
@Test
public void getTitleTest() throws Fault {
    Builder builder = Link.fromUri(uri("get"));
    builder.rel("RELREL").title("TITLETITLE").type("TYPETYPE");
    Link link = builder.build();
    String title = link.getTitle();
    assertTrue(title != null, "#getTitle did NOT return expected title");
    assertContains(title, "TITLETITLE");
}
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)

Aggregations

Builder (jakarta.ws.rs.core.Link.Builder)48 Test (org.junit.jupiter.api.Test)46 Link (jakarta.ws.rs.core.Link)37 UriBuilder (jakarta.ws.rs.core.UriBuilder)34 URI (java.net.URI)18 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)16 URISyntaxException (java.net.URISyntaxException)9 Response (jakarta.ws.rs.core.Response)4 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)3 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)2 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)1 Client (jakarta.ws.rs.client.Client)1 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 WebTarget (jakarta.ws.rs.client.WebTarget)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1