Search in sources :

Example 16 with Builder

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

the class JAXRSClientIT method buildObjectsTest.

/*
     * @testName: buildObjectsTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:804;
     * 
     * @test_Strategy: Finish building this link using the supplied values as URI
     * parameters.
     */
@Test
public void buildObjectsTest() throws Fault {
    StringBuilder path1 = new StringBuilder().append("p1");
    ByteArrayInputStream path2 = new ByteArrayInputStream("p2".getBytes(Charset.defaultCharset())) {

        @Override
        public String toString() {
            return "p2";
        }
    };
    URI path3;
    try {
        path3 = new URI("p3");
    } catch (URISyntaxException e) {
        throw new Fault(e);
    }
    String expected = "<" + url() + "p1/p2/p3" + ">";
    Link.Builder builder = Link.fromUri(url() + "{x1}/{x2}/{x3}");
    Link link = builder.build(path1, path2, path3);
    assertTrue(link != null, "#build should return an instance");
    assertTrue(link.toString().equals(expected), "Link " + link + " differs from expected " + expected);
    logMsg("#build() finished building a link and returned the instance", link);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) ByteArrayInputStream(java.io.ByteArrayInputStream) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 17 with Builder

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

the class ResponseFilter method getLinkBuilder.

public void getLinkBuilder() {
    Builder builder = responseContext.getLinkBuilder(RELATION);
    if (builder != null) {
        Link link = builder.build();
        setLinkForGetLink(link);
    } else
        setEntity(NULL);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) Link(jakarta.ws.rs.core.Link)

Example 18 with Builder

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

the class JAXRSClientIT method buildNoArgsThrowsUriBuilderExceptionTest.

/*
     * @testName: buildNoArgsThrowsUriBuilderExceptionTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:804;
     * 
     * @test_Strategy: throws UriBuilderException if a URI cannot be constructed
     * based on the current state of the underlying URI builder.
     */
@Test
public void buildNoArgsThrowsUriBuilderExceptionTest() throws Fault {
    Link.Builder builder = Link.fromUri("http://:@");
    try {
        Link link = builder.build();
        assertTrue(false, "No exception has been thrown for link " + link);
    } catch (UriBuilderException e) {
        logMsg("#build() throw UriBuilderException as expected");
    }
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilderException(jakarta.ws.rs.core.UriBuilderException) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 19 with Builder

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

the class JAXRSClientIT method relMoreNamesTest.

/*
     * @testName: relMoreNamesTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:809; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: More than one "rel" value can be specified by using one or
     * more whitespace characters as delimiters according to RFC 5988. The effect of
     * calling this method is cumulative; relations are appended using a single
     * space character as separator.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void relMoreNamesTest() throws Fault {
    String[] names = { "name1", "name2" };
    Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
    for (String name : names) builder = builder.rel(name);
    Link link = builder.build();
    String search = JaxrsUtil.iterableToString(" ", (Object[]) names);
    assertTrue(link.getRel().contains(search), "rel " + search + " 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 20 with Builder

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

the class JAXRSClientIT method baseUriIsIgnoredStringTest.

/*
     * @testName: baseUriIsIgnoredStringTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1126; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: If the underlying URI is already absolute, the base URI is
     * ignored. jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void baseUriIsIgnoredStringTest() throws Fault {
    String ignored = "http://ignored.com";
    URI uri = uri("something");
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.uri(uri);
    linkBuilder = linkBuilder.baseUri(ignored);
    URI createdUri = linkBuilder.build().getUri();
    logMsg("Created URI", createdUri.toASCIIString());
    assertFalse(createdUri.toASCIIString().contains(ignored), "Base Uri " + ignored + " is not ignored, though " + uri.toASCIIString() + "is absolute");
    assertContains(createdUri.toASCIIString(), url());
    logMsg("The base uri", ignored, "has been ignored as expected");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) 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