Search in sources :

Example 26 with Builder

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

the class JAXRSClientIT method baseUriURITest.

/*
     * @testName: baseUriURITest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1125; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set the base URI for resolution of relative URIs.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void baseUriURITest() throws Fault {
    URI uri = null;
    try {
        uri = new URI(url());
    } catch (URISyntaxException use) {
        fault(use);
    }
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.baseUri(uri);
    URI createdUri = linkBuilder.uri("/a/b/c").build().getUri();
    logMsg("Created URI", createdUri.toASCIIString());
    assertContains(createdUri.toASCIIString(), uri.toASCIIString());
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 27 with Builder

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

the class JAXRSClientIT method getLinkBuilderForTheNotPresentRelationTest.

/*
   * @testName: getLinkBuilderForTheNotPresentRelationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:854;
   * 
   * @test_Strategy: returns null if not present.
   */
@Test
public void getLinkBuilderForTheNotPresentRelationTest() throws Fault {
    Response response = Response.ok().build();
    Builder builder = response.getLinkBuilder("anyrelation");
    assertTrue(builder == null, "#getLinkBuilder('relation') returned unexpected builder" + builder);
    logMsg("#getLinkBuilder returned null as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) Builder(jakarta.ws.rs.core.Link.Builder) Test(org.junit.jupiter.api.Test)

Example 28 with Builder

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

the class JAXRSClientIT method getLinkBuilderForTheNotPresentRelationTest.

/*
   * @testName: getLinkBuilderForTheNotPresentRelationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:854;
   * 
   * @test_Strategy: returns null if not present.
   */
@Test
public void getLinkBuilderForTheNotPresentRelationTest() throws Fault {
    Response response = invokeGet("entity");
    Builder builder = response.getLinkBuilder("anyrelation");
    assertNull(builder, "#getLinkBuilder('relation') returned unexpected builder", builder);
    logMsg("#getLinkBuilder returned null as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) Builder(jakarta.ws.rs.core.Link.Builder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Test(org.junit.jupiter.api.Test)

Example 29 with Builder

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

the class JAXRSClientIT method uriBuilderTest.

/*
     * @testName: uriBuilderTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1006; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set underlying URI builder representing the URI template for
     * the link being constructed.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void uriBuilderTest() throws Fault {
    String segment = "goto/label/ten/";
    Link link = Link.fromUri(uri(segment)).build();
    UriBuilder uriBuilder = link.getUriBuilder();
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder().uriBuilder(uriBuilder);
    String sBuilder = uriBuilder.build().toASCIIString();
    String sFromBuilder = linkBuilder.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) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 30 with Builder

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

the class JAXRSClientIT method uriStringTest.

/*
     * @testName: uriStringTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:813; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set underlying string representing URI template for the link
     * being constructed.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void uriStringTest() throws Fault {
    Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
    Link link = builder.build();
    assertTrue(link.toString().contains(url()), "uri(String) " + url() + " not used in " + link);
    logMsg("#uri(String) affected link", link, "as expected");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) 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