Search in sources :

Example 6 with Builder

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

the class JAXRSClientIT method getRelsTest.

/*
     * @testName: getRelsTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:956;
     * 
     * @test_Strategy: Returns the value associated with the link "rel" param as a
     * list of strings or the empty list if "rel" is not defined.
     */
@Test
public void getRelsTest() throws Fault {
    String[] rels = { "RELREL", "REL", "relrelrel", "RELRELREL" };
    Builder builder = Link.fromUri(uri("get"));
    for (int i = 0; i != rels.length; i++) builder = builder.rel(rels[i]);
    Link link = builder.build();
    assertNotNull(link.getRels(), "#getRels is null");
    assertEqualsInt(link.getRels().size(), 4, "Unexpected #getRels size", link.getRels().size(), "Should be 4");
    String list = ";" + JaxrsUtil.iterableToString(";", link.getRels()) + ";";
    for (int i = 0; i != rels.length; i++) assertContains(list, ";" + rels[i] + ";", "Relation", rels[i], "has not been found in #getRels", list);
    logMsg("#getRel() return expected rels", list);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 7 with Builder

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

the class JAXRSClientIT method getUriTest.

/*
     * @testName: getUriTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:796;
     * 
     * @test_Strategy: Returns the underlying URI associated with this link.
     */
@Test
public void getUriTest() throws Fault {
    URI uri = uri("get");
    Builder builder = Link.fromUri(uri);
    Link link = builder.build();
    URI uriFromLink = link.getUri();
    assertTrue(uri.equals(uriFromLink), "#getUri() " + uriFromLink + " differes from original uri " + uri);
    logMsg("Original URI", uri, "equals obtained", uriFromLink);
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 8 with Builder

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

the class JAXRSClientIT method fromResourceMethodLinkUsedInInvocationTest.

/*
     * @testName: fromResourceMethodLinkUsedInInvocationTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:787;
     * 
     * @test_Strategy: Generate a link by introspecting a resource method.
     */
@Test
public void fromResourceMethodLinkUsedInInvocationTest() throws Fault {
    final String linkName = "link";
    Client client = ClientBuilder.newClient();
    client.register(new ClientRequestFilter() {

        @Override
        public void filter(ClientRequestContext ctx) throws IOException {
            String uri = ctx.getUri().toASCIIString();
            Link.Builder builder = Link.fromMethod(Resource.class, "consumesAppJson").rel(linkName);
            Link link = builder.build();
            Response response = Response.ok(uri).links(link).build();
            ctx.abortWith(response);
        }
    });
    // Phase 1, ask for a link;
    WebTarget target = client.target(url() + "resource/get");
    Response response = target.request().get();
    String entity = response.readEntity(String.class);
    assertTrue(response.hasLink(linkName), "No link received");
    assertContains(url() + "resource/get", entity);
    // Phase 2, use the link, check the correctness
    assertTrue(response.hasLink(linkName), "No link received");
    Link link = response.getLink(linkName);
    response = client.invocation(link).post(null);
    entity = response.readEntity(String.class);
    assertTrue(response.hasLink(linkName), "No link received");
    assertContains(url() + "resource/consumesappjson", entity);
    logMsg("Opaque Link has been used in Client.invocation() sucessfully");
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) IOException(java.io.IOException) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 9 with Builder

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

the class JAXRSClientIT method paramTest.

/*
     * @testName: paramTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:807; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Set an arbitrary parameter on this link.
     * 
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void paramTest() throws Fault {
    String[] params = { "param1", "param2" };
    String[] values = { "param1value1", "param1value2" };
    Link.Builder builder = RuntimeDelegate.getInstance().createLinkBuilder().uri(url());
    builder = builder.param(params[0], values[0]).param(params[1], values[1]);
    Link link = builder.build();
    assertParams(link, params, values);
    logMsg("#param set correct parameters");
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 10 with Builder

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

the class JAXRSClientIT method buildRelativizedTest.

/*
     * @testName: buildRelativizedTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1054; JAXRS:JAVADOC:1053;
     * 
     * @test_Strategy: Finish building this link using the supplied values as URI
     * parameters and relativize the result with respect to the supplied URI.
     * jakarta.ws.rs.ext.RuntimeDelegate.createLinkBuilder
     */
@Test
public void buildRelativizedTest() throws Fault {
    String relative = "a/b/c";
    URI underlay = uri(relative), respect = uri("");
    Builder linkBuilder = RuntimeDelegate.getInstance().createLinkBuilder();
    linkBuilder = linkBuilder.uri(underlay);
    Link link = linkBuilder.buildRelativized(respect);
    assertFalse(link.toString().contains(url()), "Found unexpected absolute path " + url());
    assertContains(link.toString(), relative);
    logMsg("Absolute", url(), "has not been found as expected in link", link.toString());
}
Also used : Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Aggregations

Builder (jakarta.ws.rs.core.Link.Builder)48 Test (org.junit.jupiter.api.Test)46 Link (jakarta.ws.rs.core.Link)37 UriBuilder (jakarta.ws.rs.core.UriBuilder)34 URI (java.net.URI)18 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)16 URISyntaxException (java.net.URISyntaxException)9 Response (jakarta.ws.rs.core.Response)4 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)3 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)2 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)1 Client (jakarta.ws.rs.client.Client)1 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 WebTarget (jakarta.ws.rs.client.WebTarget)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1