Search in sources :

Example 21 with Builder

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

the class JAXRSClientIT method buildRelativizedThrowsIAEWhenSuppliedValueIsNullTest.

/*
     * @testName: buildRelativizedThrowsIAEWhenSuppliedValueIsNullTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1054;
     * 
     * @test_Strategy: Throws: java.lang.IllegalArgumentException - if a value is
     * null.
     */
@Test
public void buildRelativizedThrowsIAEWhenSuppliedValueIsNullTest() 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, new Object[] { (String) null });
        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 supplied value is null");
    }
}
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 22 with Builder

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

the class JAXRSClientIT method typeTest.

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

Example 23 with Builder

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

the class JAXRSClientIT method baseUriIsIgnoredURITest.

/*
     * @testName: baseUriIsIgnoredURITest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1125; 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 baseUriIsIgnoredURITest() throws Fault {
    String ignored = "http://ignored.com";
    URI ignoredUri = null;
    try {
        ignoredUri = new URI(ignored);
    } catch (URISyntaxException e) {
        fault(ignored);
    }
    URI uri = uri("something");
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.uri(uri);
    linkBuilder = linkBuilder.baseUri(ignoredUri);
    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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 24 with Builder

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

the class JAXRSClientIT method buildObjectsThrowsUriBuilderExceptionTest.

/*
     * @testName: buildObjectsThrowsUriBuilderExceptionTest
     * 
     * @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 buildObjectsThrowsUriBuilderExceptionTest() throws Fault {
    Link.Builder builder = Link.fromUri("http://:@");
    try {
        Link link = builder.build("aaa");
        assertTrue(false, "No exception has been thrown for link " + link);
    } catch (UriBuilderException e) {
        logMsg("#build(someNonURIObjects) 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 25 with Builder

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

the class JAXRSClientIT method relTest.

/*
     * @testName: relTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:809; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Convenience method to set a link relation. More than one rel
     * value can be specified using this method.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void relTest() throws Fault {
    String[] names = { "name1", "name2" };
    Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
    for (String name : names) {
        Link link = builder.rel(name).build();
        assertTrue(link.getRel().contains(name), "Rel " + name + " 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)

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