Search in sources :

Example 16 with ClientRequestContext

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

the class JAXRSClientIT method getHeaderStringTest.

/*
   * @testName: getHeaderStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:440; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get a message header as a single string value.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getHeaderStringTest() throws Fault {
    final String TCK = "cts";
    final String DATE = "Tue, 15 Nov 1994 08:12:31 GMT";
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            String value;
            value = context.getHeaderString("tck");
            assertContainsIgnoreCase(value, TCK, "The expected value", TCK, "was not found, found", value, "instead");
            value = context.getHeaderString("accept");
            assertContainsIgnoreCase(value, MediaType.TEXT_HTML, "The expected value", MediaType.TEXT_HTML, "was not found, found", value, "instead");
            value = context.getHeaderString("date");
            assertContainsIgnoreCase(value, DATE, "The expected value", DATE, "was not found, found", value, "instead");
            Response r = Response.ok().build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildBuilder(provider).header("Accept", MediaType.TEXT_HTML).header("tck", // toString()
    new StringBuffer().append(TCK)).header("Date", DATE).buildGet();
    Response response = invoke(invocation);
    assertStatus(response, Status.OK);
}
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 17 with ClientRequestContext

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

the class JAXRSClientIT method getEntityAnnotationsIsNotTakenFromEntityClassTest.

/*
   * @testName: getEntityAnnotationsIsNotTakenFromEntityClassTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:435; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the annotations attached to the entity. Note that the
   * returned annotations array contains only those annotations explicitly
   * attached to entity instance (such as the ones attached using
   * Entity.Entity(Object, jakarta.ws.rs.core.MediaType,
   * java.lang.annotation.Annotation[]) method). The entity instance annotations
   * array does not include annotations declared on the entity implementation
   * class or its ancestors.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityAnnotationsIsNotTakenFromEntityClassTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Annotation[] annotations = context.getEntityAnnotations();
            String first = annotations == null ? "0" : String.valueOf(annotations.length);
            Response r = Response.ok(first).build();
            context.abortWith(r);
        }
    };
    Entity<StringBeanWithAnnotation> post = createEntity(new StringBeanWithAnnotation("test"));
    Invocation invocation = buildTarget(provider).register(StringBeanEntityProvider.class).request().buildPost(post);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "0");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) Annotation(java.lang.annotation.Annotation) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) Test(org.junit.jupiter.api.Test)

Example 18 with ClientRequestContext

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

the class JAXRSClientIT method getMediaTypeIsNullTest.

/*
   * @testName: getMediaTypeIsNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:442; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the media type of the entity. Returns: the media type
   * or null if not specified (e.g. there's no request entity).
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getMediaTypeIsNullTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

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

Example 19 with ClientRequestContext

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

the class JAXRSClientIT method getMediaTypeTest.

/*
   * @testName: getMediaTypeTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:471; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the media type of the entity.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getMediaTypeTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            MediaType type = responseContext.getMediaType();
            assertTrue(MediaType.APPLICATION_SVG_XML_TYPE.equals(type), "Unexpected mediatype found " + type);
            TestUtil.logMsg("Found expected MediaType.APPLICATION_SVG_XML_TYPE");
        }
    };
    Response response = Response.ok("TEST", MediaType.APPLICATION_SVG_XML).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, provider);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 20 with ClientRequestContext

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

the class JAXRSClientIT method getLengthTest.

/*
   * @testName: getLengthTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:466; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get Content-Length value.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLengthTest() throws Fault {
    final String entity = "ENTITY";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            int len = responseContext.getLength();
            assertTrue(len == entity.length(), "#getLength was supposed to be " + entity.length() + " but was " + len);
            logMsg("Found #getLength()=", len);
        }
    };
    Response response = Response.ok().header(HttpHeaders.CONTENT_LENGTH, entity.length()).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) 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