Search in sources :

Example 66 with ClientRequestContext

use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getLinksTest.

/*
   * @testName: getLinksTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:469; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the links attached to the message as header.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLinksTest() throws Fault {
    final Link link = Link.fromUri(getUrl()).build();
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Set<Link> links = responseContext.getLinks();
            assertTrue(links != null, "the #getLinks is null");
            assertTrue(links.size() == 1, "the links was supposed to be of size 1, was " + links.size());
            assertTrue(links.contains(link), "#getLinks was supposed to contain " + link.getUri().toASCIIString());
            logMsg("Found #getLinks()={", link.getUri().toASCIIString(), "}");
        }
    };
    Response response = Response.ok().links(link).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 67 with ClientRequestContext

use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getEntityClassTest.

/*
   * @testName: getEntityClassTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:436; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the raw entity type information.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityClassTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Class<?> clazz = context.getEntityClass();
            Response r = Response.ok(clazz.getName()).build();
            context.abortWith(r);
        }
    };
    Entity<ByteArrayInputStream> post = createEntity(new ByteArrayInputStream("test".getBytes()));
    Invocation invocation = buildBuilder(provider).buildPost(post);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, ByteArrayInputStream.class.getName());
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Example 68 with ClientRequestContext

use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getDateNullTest.

/*
   * @testName: getDateNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:433; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get message date. Returns: the message date, otherwise null
   * if not present.
   *
   * ClientRequestFilter.abortWith
   */
@Test
public void getDateNullTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Date date = context.getDate();
            Response r = Response.ok(date == null ? "NULL" : date.toString()).build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildInvocation(provider);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "NULL");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 69 with ClientRequestContext

use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getMethodTest.

/*
   * @testName: getMethodTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:443; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the request method.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getMethodTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            String method = context.getMethod();
            Response r = Response.ok(method).build();
            context.abortWith(r);
        }
    };
    Entity<String> entity = createEntity("TEST");
    Invocation invocation;
    Response response;
    for (String method : new String[] { "OPTIONS", "DELETE", "GET", "TRACE" }) {
        invocation = buildBuilder(provider).build(method);
        response = invoke(invocation);
        String body = response.readEntity(String.class).toUpperCase();
        assertContains(body, method);
    }
    for (String method : new String[] { "PUT", "POST" }) {
        invocation = buildBuilder(provider).build(method, entity);
        response = invoke(invocation);
        String body = response.readEntity(String.class).toUpperCase();
        assertContains(body, method);
    }
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Test(org.junit.jupiter.api.Test)

Example 70 with ClientRequestContext

use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getAcceptableLanguagesByWeightsTest.

/*
   * @testName: getAcceptableLanguagesByWeightsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:428; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: a read-only list of requested response media types sorted
   * according to their q-value, with highest preference first.
   * 
   * ClientRequestFilter.filter ClientRequestFilter.abortWith
   */
@Test
public void getAcceptableLanguagesByWeightsTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            List<Locale> locales = context.getAcceptableLanguages();
            String languages = JaxrsUtil.iterableToString(";", locales);
            Response r = Response.ok(languages).build();
            context.abortWith(r);
        }
    };
    Invocation.Builder builder = buildBuilder(provider);
    Invocation invocation;
    invocation = builder.acceptLanguage("da, en-gb;q=0.6, en-us;q=0.7").buildGet();
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class).toLowerCase();
    assertContains(entity, "da");
    assertContains(entity, "gb");
    assertContains(entity, "us");
    int indexDa = entity.indexOf("da");
    int indexUs = entity.indexOf("us");
    int indexGb = entity.indexOf("gb");
    assertTrue(indexDa < indexUs && indexUs < indexGb, "List of acceptable languages " + entity + " is not sorted by q values");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Test(org.junit.jupiter.api.Test)

Aggregations

ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)77 Response (jakarta.ws.rs.core.Response)71 Test (org.junit.jupiter.api.Test)70 Invocation (jakarta.ws.rs.client.Invocation)38 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)29 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)10 MediaType (jakarta.ws.rs.core.MediaType)8 Locale (java.util.Locale)6 WebTarget (jakarta.ws.rs.client.WebTarget)5 ContextProvider (ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider)4 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Date (java.util.Date)4 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)3 StringBeanRuntimeDelegate (ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate)3 StringBeanWithAnnotation (ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation)3 Client (jakarta.ws.rs.client.Client)3 Link (jakarta.ws.rs.core.Link)3 RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)3 IOException (java.io.IOException)3