Search in sources :

Example 36 with UriBuilder

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

the class JAXRSClientIT method buildFromMapWithBooleanSlashEncodedTest.

/*
   * @testName: buildFromMapWithBooleanSlashEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:889;
   * 
   * @test_Strategy: Build a URI. Any URI template parameters will be replaced
   * by the value in the supplied map. Values are converted to String using
   * their toString() method and are then encoded to match the rules of the URI
   * component to which they pertain. All '%' characters in the stringified
   * values will be encoded. The state of the builder is unaffected; this method
   * may be called multiple times on the same builder instance. The slash ('/')
   * characters in parameter values will be encoded if the template is placed in
   * the URI path component.
   */
@Test
public void buildFromMapWithBooleanSlashEncodedTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("x", new StringBuilder("x%yz"));
    map.put("y", new StringBuffer("/path-absolute/%25test1"));
    map.put("z", new Object() {

        public String toString() {
            return "fred@example.com";
        }
    });
    map.put("w", "path-rootless/test2");
    UriBuilder builder = UriBuilder.fromPath("").path("{w}/{x}/{y}/{z}/{x}");
    // can be called multiple times
    builder.buildFromMap(map, false);
    uri = builder.buildFromMap(map, true);
    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 37 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateStringObjectTest.

/*
   * @testName: resolveTemplateStringObjectTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:957;
   * 
   * @test_Strategy: Resolve a URI template with a given name in this UriBuilder
   * instance using a supplied value
   */
@Test
public void resolveTemplateStringObjectTest() throws Fault {
    String template = "{v}/{w}/{x}/{y}/{w}";
    UriBuilder builder = UriBuilder.fromPath("").path(template).resolveTemplate("v", new StringBuilder("aaa"));
    String resolvedTemplate = template.replace("{v}", "aaa");
    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 38 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateStringObjectBooleanSlashEncodedTest.

/*
   * @testName: resolveTemplateStringObjectBooleanSlashEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:959;
   * 
   * @test_Strategy: Resolve a URI template with a given name in this UriBuilder
   * instance using a supplied value. The slash ('/') characters in template
   * values will be encoded.
   */
@Test
public void resolveTemplateStringObjectBooleanSlashEncodedTest() throws Fault {
    String template = "{v}/{w}/{x}/{y}/{w}";
    UriBuilder builder = UriBuilder.fromPath("").path(template).resolveTemplate("v", new StringBuilder("a/a/a"), true);
    String resolvedTemplate = template.replace("{v}", "a%2Fa%2Fa");
    String builderTemplate = builder.toTemplate().replace("%2f", "%2F");
    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 39 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesFromEncodedThrowsNullOnNullMapTest.

/*
   * @testName: resolveTemplatesFromEncodedThrowsNullOnNullMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:967;
   * 
   * @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 resolveTemplatesFromEncodedThrowsNullOnNullMapTest() throws Fault {
    UriBuilder builder = UriBuilder.fromPath("").path("{v}/{w}/{x}/{y}/{w}");
    try {
        builder.resolveTemplatesFromEncoded((Map<String, Object>) null);
        fault("No exception has been thrown");
    } catch (IllegalArgumentException e) {
        logMsg("IllegalArgumentException thrown as expected", e);
    }
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 40 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesFromEncodedThrowsNullOnNullNameTest.

/*
   * @testName: resolveTemplatesFromEncodedThrowsNullOnNullNameTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:967;
   * 
   * @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 resolveTemplatesFromEncodedThrowsNullOnNullNameTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(null, "aa");
    UriBuilder builder = UriBuilder.fromPath("").path("{v}/{w}/{x}/{y}/{w}");
    try {
        builder.resolveTemplatesFromEncoded(map);
        fault("No exception has been thrown");
    } catch (IllegalArgumentException e) {
        logMsg("IllegalArgumentException 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