Search in sources :

Example 41 with UriBuilder

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

the class JAXRSClientIT method fromPathTest.

/*
     * @testName: fromPathTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1038;
     * 
     * @test_Strategy: Convenience method to build a link from a path. Equivalent to
     * fromUriBuilder(UriBuilder.fromPath(path)).
     */
@Test
public void fromPathTest() throws Fault {
    String path = "somewhere/somehow";
    UriBuilder builder = UriBuilder.fromPath(path);
    Link.Builder linkBuilder = Link.fromUriBuilder(builder);
    Link.Builder fromPathBuilder = Link.fromPath(path);
    String fromUriBuilderString = linkBuilder.build().toString();
    String fromPathString = fromPathBuilder.build().toString();
    assertEquals(fromUriBuilderString, fromPathString, "fromUriBuilder()=", fromUriBuilderString, "differs from Link.fromPath()", fromPathString);
    logMsg("fromUriBuilder(UriBuilder.fromPath(path)) is equivalent to fromPath(path)", "The link is", fromPathString);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 42 with UriBuilder

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

the class JAXRSClientIT method fromPathWithUriTemplateParamsTest.

/*
     * @testName: fromPathWithUriTemplateParamsTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1038;
     * 
     * @test_Strategy: Convenience method to build a link from a path. Equivalent to
     * fromUriBuilder(UriBuilder.fromPath(path)).
     */
@Test
public void fromPathWithUriTemplateParamsTest() throws Fault {
    String path = "somewhere/somehow/{p1}/{p2}";
    String param1 = "param1", param2 = "param2";
    UriBuilder builder = UriBuilder.fromPath(path);
    Link.Builder linkBuilder = Link.fromUriBuilder(builder);
    Link.Builder fromPathBuilder = Link.fromPath(path);
    String fromUriBuilderString = linkBuilder.build(param1, param2).toString();
    String fromPathString = fromPathBuilder.build(param1, param2).toString();
    assertEquals(fromUriBuilderString, fromPathString, "fromUriBuilder(UriBuilder.fromPath(,", path, "))=", fromUriBuilderString, "differs from Link.fromPath(", path, ")", fromPathString);
    logMsg("fromUriBuilder(UriBuilder.fromPath(", path, ")) is equivalent to fromPath(", path, ")", "The link is", fromPathString);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 43 with UriBuilder

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

the class JAXRSClientIT method fromUriBuilderTest.

/*
     * @testName: fromUriBuilderTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1005;
     * 
     * @test_Strategy: Create a new builder instance initialized from a URI builder.
     */
@Test
public void fromUriBuilderTest() throws Fault {
    String segment = "goto/label/ten/";
    Link link = Link.fromUri(uri(segment)).build();
    UriBuilder builder = link.getUriBuilder();
    Builder fromBuilder = Link.fromUriBuilder(builder);
    String sBuilder = builder.build().toASCIIString();
    String sFromBuilder = fromBuilder.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) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 44 with UriBuilder

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

the class JAXRSClientIT method closeOnClientTargetWithUriBuilderTest.

/*
   * @testName: closeOnClientTargetWithUriBuilderTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:409;
   * 
   * @test_Strategy: Close client instance and all it's associated resources.
   * Subsequent calls have no effect and are ignored. Once the client is closed,
   * invoking any other method on the client instance would result in an
   * IllegalTStateException being thrown. Calling this method effectively
   * invalidates all WebTarget resource targets produced by the client instance.
   * Invoking any method on such targets once the client is closed would result
   * in an IllegalStateException being thrown.
   */
@Test
public void closeOnClientTargetWithUriBuilderTest() throws Fault {
    client.close();
    Link link = Link.fromUri("cts").build();
    UriBuilder builder = UriBuilder.fromUri(link.getUri());
    assertException(IllegalStateException.class, client, "target", builder);
}
Also used : UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 45 with UriBuilder

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

the class JAXRSClientIT method targetUriBuilderTest.

/*
   * @testName: targetUriBuilderTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:418;
   * 
   * @test_Strategy: Build a new web resource target.
   */
@Test
public void targetUriBuilderTest() throws Fault {
    UriBuilder builder = UriBuilder.fromUri(getUrl("call"));
    target = client.target(builder);
    assertTrue(target != null, "WebTarget is null");
}
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