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);
}
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);
}
}
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();
}
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);
}
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();
}
Aggregations