Search in sources :

Example 11 with UriBuilder

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

the class UriBuilderIT method shouldThrowIllegalArgumentExceptionForUnresolvedTemplates.

/**
 * Verifies that {@code UriBuilder#build()} throws a {@code IllegalArgumentException}
 * when it would be asked to create a URI with unresolved template variables.
 *
 * @throws ExecutionException   if the instance didn't boot correctly
 * @throws InterruptedException if the test took much longer than usually
 *                              expected
 */
@Test
public final void shouldThrowIllegalArgumentExceptionForUnresolvedTemplates() throws InterruptedException, ExecutionException {
    // given
    final UriBuilder uriBuilder = UriBuilder.newInstance().scheme("http").host("localhost").path("contextroot").path("{var}");
    // then
    assertThrows(IllegalArgumentException.class, /* when */
    uriBuilder::build);
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 12 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesMapBooleanThrowsIAEOnNullValueTest.

/*
   * @testName: resolveTemplatesMapBooleanThrowsIAEOnNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:966;
   * 
   * @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 resolveTemplatesMapBooleanThrowsIAEOnNullValueTest() 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, false);
        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)

Example 13 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesFromEncodedPercentEncodedTest.

/*
   * @testName: resolveTemplatesFromEncodedPercentEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:967;
   * 
   * @test_Strategy: Resolve one or more URI templates in this instance using
   * supplied name-value pairs. All % characters in the stringified values that
   * are not followed by two hexadecimal numbers will be encoded.
   */
@Test
public void resolveTemplatesFromEncodedPercentEncodedTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("v", new StringBuilder("path-rootless%2Ftest2"));
    map.put("w", new StringBuilder("x%yz"));
    map.put("x", new Object() {

        public String toString() {
            return "%2Fpath-absolute%2F%2525test1";
        }
    });
    map.put("y", "fred@example.com");
    UriBuilder builder = UriBuilder.fromPath("").path("{v}/{w}/{x}/{y}/{w}");
    builder = builder.resolveTemplatesFromEncoded(map);
    uri = builder.build();
    gotExpectedPass(uri.getRawPath(), ENCODED_EXPECTED_PATH);
    assertPassAndLog();
}
Also used : HashMap(java.util.HashMap) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateStringObjectBooleanSlashNotEncodedTest.

/*
   * @testName: resolveTemplateStringObjectBooleanSlashNotEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:959;
   * 
   * @test_Strategy: Resolve a URI template with a given name in this UriBuilder
   * instance using a supplied value.
   */
@Test
public void resolveTemplateStringObjectBooleanSlashNotEncodedTest() throws Fault {
    String template = "{v}/{w}/{x}/{y}/{w}";
    UriBuilder builder = UriBuilder.fromPath("").path(template).resolveTemplate("v", new StringBuilder("a/a/a"), false);
    String resolvedTemplate = template.replace("{v}", "a/a/a");
    String builderTemplate = builder.toTemplate();
    assertEquals(resolvedTemplate, builderTemplate, "Given template", template, "was not resolved correctly, remains", builderTemplate);
    logMsg("Got expected template", template);
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 15 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateFromEncodedPercentEncodedTest.

/*
   * @testName: resolveTemplateFromEncodedPercentEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:961;
   * 
   * @test_Strategy: Resolve a URI template with a given name in this UriBuilder
   * instance using a supplied encoded value. All % characters in the
   * stringified values that are not followed by two hexadecimal numbers will be
   * encoded.
   */
@Test
public void resolveTemplateFromEncodedPercentEncodedTest() throws Fault {
    Object[] s = { "path-rootless%2Ftest2", new StringBuilder("x%yz"), "%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)

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