Search in sources :

Example 16 with UriBuilder

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

the class JAXRSClientIT method toTemplateTest.

/*
   * @testName: toTemplateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:896;
   * 
   * @test_Strategy: Get the URI template string represented by this URI
   * builder.
   */
@Test
public void toTemplateTest() throws Fault {
    String template = "{v}/{w}/{x}/{y}/{w}";
    UriBuilder builder = UriBuilder.fromPath("").path(template);
    assertEquals(template, builder.toTemplate(), "Given template", template, "differs from obtain", builder.toTemplate());
    logMsg("Got expected template", template);
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 17 with UriBuilder

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

the class JAXRSClientIT method buildFromMapTest5.

/*
   * @testName: buildFromMapTest5
   * 
   * @assertion_ids: JAXRS:JAVADOC:185;
   * 
   * @test_Strategy: Create multiple URI instances from the same UriBuilder
   * instance using the UriBuilder.buildFromMap(Map); Verify that the builder is
   * not affected.
   */
@Test
public void buildFromMapTest5() throws Fault {
    UriBuilder ub;
    Map<String, String> maps = new HashMap<String, String>();
    maps.put("x", "x%yz");
    maps.put("y", "/path-absolute/%25test1");
    maps.put("z", "fred@example.com");
    maps.put("w", "path-rootless/test2");
    Map<String, String> maps1 = new HashMap<String, String>();
    maps1.put("x", "x%20yz");
    maps1.put("y", "/path-absolute/test1");
    maps1.put("z", "fred@example.com");
    maps1.put("w", "path-rootless/test2");
    Map<String, String> maps2 = new HashMap<String, String>();
    maps2.put("x", "x%yz");
    maps2.put("y", "/path-absolute/%25test1");
    maps2.put("z", "fred@example.com");
    maps2.put("w", "path-rootless/test2");
    maps2.put("v", "xyz");
    String expected_path_1 = "path-rootless%2Ftest2/x%2520yz/%2Fpath-absolute%2Ftest1/fred@example.com/x%2520yz";
    try {
        ub = UriBuilder.fromPath("").path("{w}/{x}/{y}/{z}/{x}");
        uri = ub.buildFromMap(maps);
        gotExpectedPass(uri.getRawPath(), ENCODED_EXPECTED_PATH);
        uri = ub.buildFromMap(maps1);
        gotExpectedPass(uri.getRawPath(), expected_path_1);
        uri = ub.buildFromMap(maps2);
        gotExpectedPass(uri.getRawPath(), ENCODED_EXPECTED_PATH);
    } catch (Throwable ex) {
        pass = false;
        sb.append("Unexpected exception thrown: " + ex.getMessage() + newline);
    }
    assertPassAndLog();
}
Also used : HashMap(java.util.HashMap) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 18 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateFromEncodedThrowsNullOnNullNameTest.

/*
   * @testName: resolveTemplateFromEncodedThrowsNullOnNullNameTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:961;
   * 
   * @test_Strategy: java.lang.IllegalArgumentException - if the resolved
   * template name or encoded value is null.
   */
@Test
public void resolveTemplateFromEncodedThrowsNullOnNullNameTest() 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}");
    try {
        builder.resolveTemplateFromEncoded(null, s[0]);
        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 19 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesFromEncodedTest.

/*
   * @testName: resolveTemplatesFromEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:967;
   * 
   * @test_Strategy: Resolve one or more URI templates in this instance using
   * supplied name-value pairs.
   */
@Test
public void resolveTemplatesFromEncodedTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("v", new StringBuilder("path-rootless%2Ftest2"));
    map.put("w", new StringBuilder("x%25yz"));
    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 20 with UriBuilder

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

the class JAXRSClientIT method checkCreatedUriBuilderTest.

/*
   * @testName: checkCreatedUriBuilderTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:289;
   * 
   * @test_Strategy: Check that RuntimeDelegate.createUriBuilder makes no
   * exception and is not null
   * 
   */
@Test
public void checkCreatedUriBuilderTest() throws Fault {
    UriBuilder builder = delegate.createUriBuilder();
    assertTrue(builder != null, "UriBuilder has not been created");
}
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