Search in sources :

Example 1 with UriBuilder

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

the class SeBootstrapTest method shouldReturnSameUri.

/**
 * Assert that calling {@code Configuration.baseUri} returns the correct URI as set
 * by the mocked classes.
 *
 * @since 3.1
 */
@Test
public void shouldReturnSameUri() {
    // given
    final URI uri = URI.create("http://localhost:8080/foo");
    final UriBuilder uriBuilder = mock(UriBuilder.class);
    given(uriBuilder.build()).willReturn(uri);
    final Configuration configuration = mock(Configuration.class);
    given(configuration.baseUri()).willCallRealMethod();
    given(configuration.baseUriBuilder()).willReturn(uriBuilder);
    final SeBootstrap.Instance instance = mock(SeBootstrap.Instance.class);
    given(instance.configuration()).willReturn(configuration);
    // when
    URI returnedUri = instance.configuration().baseUri();
    // then
    assertThat(uri, is(returnedUri));
}
Also used : Configuration(jakarta.ws.rs.SeBootstrap.Configuration) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 2 with UriBuilder

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

the class JAXRSClientIT method getUriBuilderIsDetachedTest.

/*
   * @testName: getUriBuilderIsDetachedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:609;
   * 
   * @test_Strategy: Get the URI builder initialized with the URI of the current
   * resource target. The returned URI builder is detached from the target, i.e.
   * any updates in the URI builder MUST NOT have any effects on the URI of the
   * originating target.
   */
@Test
public void getUriBuilderIsDetachedTest() throws Fault {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(URL);
    UriBuilder builder = target.getUriBuilder();
    // The way to affect original target
    client.close();
    URI uri = builder.build();
    assertContains(uri.toASCIIString(), URL);
    logMsg("URI", uri, "contains", URL);
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 3 with UriBuilder

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

the class JAXRSClientIT method getUriBuilderTest.

/*
     * @testName: getUriBuilderTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:797;
     * 
     * @test_Strategy: Convenience method that returns a
     * jakarta.ws.rs.core.UriBuilder initialized with this link's underlying URI.
     */
@Test
public void getUriBuilderTest() throws Fault {
    URI uri = uri("get");
    Builder builder = Link.fromUri(uri);
    Link link = builder.build();
    UriBuilder uriBuilder = link.getUriBuilder();
    assertTrue(uriBuilder != null, "#getUriBuilder is null");
    URI uriFromLink = uriBuilder.build();
    assertTrue(uri.equals(uriFromLink), "#getUri() " + uriFromLink + " differes from original uri " + uri);
    logMsg("Original URI", uri, "equals obtained", uriFromLink);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 4 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateFromEncodedTest.

/*
   * @testName: resolveTemplateFromEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:961;
   * 
   * @test_Strategy: Resolve a URI template with a given name in this UriBuilder
   * instance using a supplied encoded value.
   */
@Test
public void resolveTemplateFromEncodedTest() throws Fault {
    Object[] s = { "path-rootless%2Ftest2", new StringBuilder("x%25yz"), "%2Fpath-absolute%2F%2525test1", "fred@example.com" };
    UriBuilder builder = UriBuilder.fromPath("").path("{v}/{w}/{x}/{y}/{w}");
    builder = builder.resolveTemplateFromEncoded("v", s[0]);
    builder = builder.resolveTemplateFromEncoded("w", s[1]);
    builder = builder.resolveTemplateFromEncoded("x", s[2]);
    builder = builder.resolveTemplateFromEncoded("y", s[3]);
    uri = builder.build();
    gotExpectedPass(uri.getRawPath(), ENCODED_EXPECTED_PATH);
    assertPassAndLog();
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesMapThrowsIAEOnNullValueTest.

/*
   * @testName: resolveTemplatesMapThrowsIAEOnNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:963;
   * 
   * @test_Strategy:java.lang.IllegalArgumentException - if the name-value map
   * or any of the names or values in the map is null.
   */
@Test
public void resolveTemplatesMapThrowsIAEOnNullValueTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("a", null);
    map.put("b", "path-rootless/test2");
    UriBuilder builder = UriBuilder.fromPath("").path("{a}/{b}");
    try {
        builder.resolveTemplates(map);
        fault("IllegalArgumentException has not been thrown");
    } catch (IllegalArgumentException e) {
        logMsg("IllegalArgumentException has been thrown as expected", e);
    }
}
Also used : HashMap(java.util.HashMap) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

UriBuilder (jakarta.ws.rs.core.UriBuilder)48 Test (org.junit.jupiter.api.Test)45 HashMap (java.util.HashMap)18 URI (java.net.URI)8 Link (jakarta.ws.rs.core.Link)6 Builder (jakarta.ws.rs.core.Link.Builder)5 GET (jakarta.ws.rs.GET)3 Path (jakarta.ws.rs.Path)3 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)1 Configuration (jakarta.ws.rs.SeBootstrap.Configuration)1 Client (jakarta.ws.rs.client.Client)1 WebTarget (jakarta.ws.rs.client.WebTarget)1 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)1 URISyntaxException (java.net.URISyntaxException)1