Search in sources :

Example 46 with UriBuilder

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

the class UriBuilderIT method shouldBuildValidInstanceFromScratch.

/**
 * Verifies that a valid instance can be created from scratch.
 *
 * @throws ExecutionException   if the instance didn't boot correctly
 * @throws InterruptedException if the test took much longer than usually
 *                              expected
 */
@Test
public final void shouldBuildValidInstanceFromScratch() throws InterruptedException, ExecutionException {
    // given
    final UriBuilder uriBuilder = UriBuilder.newInstance();
    // when
    final URI uri = uriBuilder.scheme("scheme").host("host").port(1).build();
    // then
    assertThat(uri.toString(), is("scheme://host:1"));
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 47 with UriBuilder

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

the class UriBuilderIT method shouldThrowUriBuilderExceptionOnSchemeOnlyUri.

/**
 * Verifies that {@code UriBuilder#build()} throws a {@link UriBuilderException}
 * when it would be asked to create an invalid URI.
 *
 * @throws ExecutionException   if the instance didn't boot correctly
 * @throws InterruptedException if the test took much longer than usually
 *                              expected
 */
@Test
public final void shouldThrowUriBuilderExceptionOnSchemeOnlyUri() throws InterruptedException, ExecutionException {
    // given
    final UriBuilder uriBuilder = UriBuilder.newInstance().scheme("http");
    // then
    assertThrows(UriBuilderException.class, /* when */
    uriBuilder::build);
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 48 with UriBuilder

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

the class URIInfoTest method requestTest.

@GET
@Path("/request")
public String requestTest(@Context UriInfo info) {
    StringBuilder sb = new StringBuilder();
    URI uri = info.getRequestUri();
    UriBuilder urib = info.getRequestUriBuilder();
    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)

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