Search in sources :

Example 21 with UriBuilder

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

the class URIInfoTest method apathTest.

@GET
@Path("/apath")
public String apathTest(@Context UriInfo info) {
    StringBuilder sb = new StringBuilder();
    URI uri = info.getAbsolutePath();
    UriBuilder urib = info.getAbsolutePathBuilder();
    sb.append(uri.toString());
    if (!uri.toString().equals(urib.build().toString())) {
        sb.append("Got unexpected = " + urib.build().toString());
        sb.append("FAILED");
    }
    return sb.toString();
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 22 with UriBuilder

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

the class URIInfoTest method baseUriTest.

@GET
@Path("/baseuri")
public String baseUriTest(@Context UriInfo info) {
    StringBuilder sb = new StringBuilder();
    URI uri = info.getBaseUri();
    UriBuilder urib = info.getBaseUriBuilder();
    sb.append(uri.toString());
    if (!uri.toString().equals(urib.build().toString())) {
        sb.append("Got unexpected = " + urib.build().toString());
        sb.append("FAILED");
    }
    return sb.toString();
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 23 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesMapBooleanSlashNotEncodedTest.

/*
   * @testName: resolveTemplatesMapBooleanSlashNotEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:965;
   * 
   * @test_Strategy: Resolve one or more URI templates in this UriBuilder
   * instance using supplied name-value pairs.
   */
@Test
public void resolveTemplatesMapBooleanSlashNotEncodedTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("x", new StringBuilder("x%yz"));
    map.put("y", new StringBuffer("/path-absolute/test1"));
    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}");
    uri = builder.resolveTemplates(map, false).build();
    gotExpectedPass(uri.getRawPath(), EXPECTED_PATH);
    assertPassAndLog();
}
Also used : HashMap(java.util.HashMap) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesMapTest.

/*
   * @testName: resolveTemplatesMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:963;
   * 
   * @test_Strategy: Resolve one or more URI templates in this UriBuilder
   * instance using supplied name-value pairs.
   */
@Test
public void resolveTemplatesMapTest() 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}");
    uri = builder.resolveTemplates(map).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 25 with UriBuilder

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

the class JAXRSClientIT method cloneTest1.

/*
   * @testName: cloneTest1
   * 
   * @assertion_ids: JAXRS:JAVADOC:188;
   * 
   * @test_Strategy: Create an UriBuilder instance using
   * UriBuilder.fromPath(String); Create another UriBuilder instance using
   * UriBuilder.clone(); Verify that both are created correctly.
   */
@Test
public void cloneTest1() throws Fault {
    UriBuilder ub, ub1;
    URI uri1;
    String path1 = "test";
    String frag = "xyz";
    String expected_path_1 = "test#xyz";
    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");
    String expected_path_2 = "test/" + ENCODED_EXPECTED_PATH + "#xyz";
    try {
        ub = UriBuilder.fromPath(path1).fragment(frag);
        ub1 = ub.clone();
        uri = ub.build();
        gotExpectedPass(uri.toString(), expected_path_1);
        uri1 = ub1.path("{w}/{x}/{y}/{z}/{x}").buildFromMap(maps);
        gotExpectedPass(uri1.toString(), expected_path_2);
    } catch (Exception ex) {
        pass = false;
        sb.append("Unexpected exception thrown: " + ex.getMessage());
    }
    assertPassAndLog();
}
Also used : HashMap(java.util.HashMap) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) UriBuilderException(jakarta.ws.rs.core.UriBuilderException) 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