Search in sources :

Example 26 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateStringObjectThrowsIAEOnNullNameTest.

/*
   * @testName: resolveTemplateStringObjectThrowsIAEOnNullNameTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:957;
   * 
   * @test_Strategy: if the resolved template name or value is null.
   */
@Test
public void resolveTemplateStringObjectThrowsIAEOnNullNameTest() throws Fault {
    String template = "{v}/{w}/{x}/{y}/{w}";
    UriBuilder builder = UriBuilder.fromPath("").path(template);
    try {
        builder.resolveTemplate(null, "aaa");
        fault("No exception has been thrown");
    } catch (IllegalArgumentException e) {
        logMsg("IllegalArgumentException has been thrown as expected", e);
    }
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 27 with UriBuilder

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

the class JAXRSClientIT method resolveTemplatesMapBooleanThrowsIAEOnNullNameTest.

/*
   * @testName: resolveTemplatesMapBooleanThrowsIAEOnNullNameTest
   * 
   * @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 resolveTemplatesMapBooleanThrowsIAEOnNullNameTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("a", new StringBuilder("x%yz"));
    map.put(null, "path-rootless/test2");
    UriBuilder builder = UriBuilder.fromPath("").path("{a}/{b}");
    try {
        builder.resolveTemplates(map, true);
        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 28 with UriBuilder

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

the class JAXRSClientIT method buildFromMapWithBooleanSlashNotEncodedTest.

/*
   * @testName: buildFromMapWithBooleanSlashNotEncodedTest
   * 
   * @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.
   */
@Test
public void buildFromMapWithBooleanSlashNotEncodedTest() 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.buildFromMap(map, false);
    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 29 with UriBuilder

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

the class JAXRSClientIT method resolveTemplateFromEncodedThrowsNullOnNullValueTest.

/*
   * @testName: resolveTemplateFromEncodedThrowsNullOnNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:961;
   * 
   * @test_Strategy: java.lang.IllegalArgumentException - if the resolved
   * template name or encoded value is null.
   */
@Test
public void resolveTemplateFromEncodedThrowsNullOnNullValueTest() throws Fault {
    UriBuilder builder = UriBuilder.fromPath("").path("{v}/{w}/{x}/{y}/{w}");
    try {
        builder.resolveTemplateFromEncoded("v", (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 30 with UriBuilder

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

the class JAXRSClientIT method uriBuilderTest.

/*
     * @testName: uriBuilderTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1006; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set underlying URI builder representing the URI template for
     * the link being constructed.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void uriBuilderTest() throws Fault {
    String segment = "goto/label/ten/";
    Link link = Link.fromUri(uri(segment)).build();
    UriBuilder uriBuilder = link.getUriBuilder();
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder().uriBuilder(uriBuilder);
    String sBuilder = uriBuilder.build().toASCIIString();
    String sFromBuilder = linkBuilder.build().getUri().toASCIIString();
    assertContains(sFromBuilder, sBuilder, "Original builder", sBuilder, "not found in #fromUriBuilder", sFromBuilder);
    logMsg("#fromUriBuilder", sFromBuilder, "contains the original", sBuilder);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) 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