Search in sources :

Example 31 with Builder

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

the class JAXRSClientIT method buildRelativizedThrowsIAEWhenSuppliedJustOneValueOutOfThreeTest.

/*
     * @testName: buildRelativizedThrowsIAEWhenSuppliedJustOneValueOutOfThreeTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1054;
     * 
     * @test_Strategy: Throws: java.lang.IllegalArgumentException - if there are any
     * URI template parameters without a supplied value
     */
@Test
public void buildRelativizedThrowsIAEWhenSuppliedJustOneValueOutOfThreeTest() throws Fault {
    // rfc6570
    Builder linkBuilder = Link.fromUri(url() + "{x1}/{x2}/{x3}");
    URI respect = null;
    try {
        respect = new URI(url());
    } catch (URISyntaxException e) {
        fault(e);
    }
    try {
        Link link = linkBuilder.buildRelativized(respect, "p");
        fault("IllegalArgumentException has not been thrown when value is not supplied, link=", link.toString());
    } catch (IllegalArgumentException iae) {
        logMsg("IllegalArgumentException has been thrown as expected when a value has not been supplied");
    }
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 32 with Builder

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

the class JAXRSClientIT method buildRelativizedDoesNotSharePrefixTest.

/*
     * @testName: buildRelativizedDoesNotSharePrefixTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1054;
     * 
     * @test_Strategy: If the underlying link is absolute but does not share a
     * prefix with the supplied URI, this method is equivalent to calling
     * build(java.lang.Object[])
     */
@Test
public void buildRelativizedDoesNotSharePrefixTest() throws Fault {
    String relative = "a/b/c";
    String prefix = "ssh";
    URI underlay = null, respect = null;
    try {
        underlay = new URI(url() + relative);
        respect = new URI(url().replace("http", prefix));
    } catch (URISyntaxException e) {
        fault(e);
    }
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.uri(underlay);
    Link link = linkBuilder.buildRelativized(respect);
    Link build = linkBuilder.build(respect);
    assertContains(link.toString(), relative);
    assertContains(link.toString(), url());
    // |=|
    assertContains(link.toString(), build.getUri().toASCIIString());
    logMsg("When a prefix is not shared, the methods is equivalent to build() as expected");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 33 with Builder

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

the class JAXRSClientIT method baseUriIsNotJustBaseURITest.

/*
     * @testName: baseUriIsNotJustBaseURITest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1125; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set the base URI for resolution of relative URIs. Provide a
     * URI that is not just base, i.e. schema and authority, but also a path
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void baseUriIsNotJustBaseURITest() throws Fault {
    URI uri = uri("something");
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.baseUri(uri);
    URI createdUri = linkBuilder.uri("/a/b/c").build().getUri();
    logMsg("Created URI", createdUri.toASCIIString());
    assertFalse(createdUri.toASCIIString().contains(uri.toASCIIString()), "Base Uri " + uri.toASCIIString() + " is not a base uri built as " + createdUri.toASCIIString());
    assertContains(createdUri.toASCIIString(), url());
}
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)

Example 34 with Builder

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

the class JAXRSClientIT method baseUriStringTest.

/*
     * @testName: baseUriStringTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1126; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set the base URI as a string for resolution of relative URIs.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void baseUriStringTest() throws Fault {
    URI uri = null;
    try {
        uri = new URI(url());
    } catch (URISyntaxException use) {
        fault(use);
    }
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.baseUri(uri.toASCIIString());
    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 35 with Builder

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

the class JAXRSClientIT method uriUriTest.

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