Search in sources :

Example 11 with Builder

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

the class JAXRSClientIT method buildRelativizedThrowsUriBuilderExceptionTest.

/*
     * @testName: buildRelativizedThrowsUriBuilderExceptionTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1054; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Throws: UriBuilderException - if a URI cannot be constructed
     * based on the current state of the underlying URI builder.
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void buildRelativizedThrowsUriBuilderExceptionTest() throws Fault {
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    URI respect = null;
    try {
        respect = new URI(url());
    } catch (URISyntaxException e) {
        fault(e);
    }
    try {
        Link link = linkBuilder.uri("http://@").buildRelativized(respect);
        fault("UriBuilderException has not been thrown, link=", link.toString());
    } catch (UriBuilderException iae) {
        logMsg("UriBuilderException has been thrown as expected");
    }
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URISyntaxException(java.net.URISyntaxException) UriBuilderException(jakarta.ws.rs.core.UriBuilderException) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 12 with Builder

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

the class JAXRSClientIT method titleTest.

/*
     * @testName: titleTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:810; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Convenience method to set a title on this link. If called
     * more than once, the previous value of title is overwritten.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void titleTest() throws Fault {
    String[] titles = { "tiTle1", "titlE2", "titLe3" };
    Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
    for (String title : titles) {
        builder = builder.title(title);
        Link link = builder.build();
        assertTrue(link.getTitle().equals(title), "Title " + title + " not found in " + link);
    }
    logMsg("#title set expected title");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 13 with Builder

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

the class JAXRSClientIT method baseUriStringThrowsIAETest.

/*
     * @testName: baseUriStringThrowsIAETest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1126; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: throws java.lang.IllegalArgumentException - if string
     * representation of URI is invalid.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void baseUriStringThrowsIAETest() throws Fault {
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    try {
        linkBuilder.baseUri("?:!@#$%^&*()");
        fault("IllegalArgumentException has not been thrown");
    } catch (IllegalArgumentException iae) {
        logMsg("IllegalArgumentException has been thrown as expected");
    }
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with Builder

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

the class JAXRSClientIT method baseUriIsNotJustBaseStringTest.

/*
     * @testName: baseUriIsNotJustBaseStringTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1126; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set the base URI as a string 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 baseUriIsNotJustBaseStringTest() throws Fault {
    URI uri = uri("something");
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.baseUri(uri.toASCIIString());
    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 15 with Builder

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

the class JAXRSClientIT method buildThrowsIAEWhenSuppliedJustOneValueOutOfThreeTest.

/*
     * @testName: buildThrowsIAEWhenSuppliedJustOneValueOutOfThreeTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:804;
     * 
     * @test_Strategy: Throws: java.lang.IllegalArgumentException - if there are any
     * URI template parameters without a supplied value
     */
@Test
public void buildThrowsIAEWhenSuppliedJustOneValueOutOfThreeTest() throws Fault {
    // rfc6570
    Builder linkBuilder = Link.fromUri(url() + "{x1}/{x2}/{x3}");
    try {
        Link link = linkBuilder.build("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) 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