Search in sources :

Example 76 with ClientRequestContext

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

the class JAXRSClientIT method setUriTest.

/*
   * @testName: setUriTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:454; JAXRS:JAVADOC:447; JAXRS:JAVADOC:455;
   * JAXRS:JAVADOC:456;
   * 
   * @test_Strategy: Set a new request URI. Get the request URI.
   */
@Test
public void setUriTest() throws Fault {
    String entity = "ENTITY";
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            URI uri = context.getUri();
            try {
                uri = new URI(uri.toASCIIString().replace("qwerty", "post"));
            } catch (URISyntaxException e) {
                throw new Fault(e);
            }
            context.setUri(uri);
        }
    };
    addProvider(provider);
    setRequestContentEntity(entity);
    setProperty(Property.REQUEST, buildRequest(Request.POST, "qwerty"));
    invoke();
    String body = getResponseBody();
    assertContains(body, entity);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) ContextProvider(ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 77 with ClientRequestContext

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

the class JAXRSClientIT method getEntityStreamTest.

/* Run test */
/*
   * @testName: getEntityStreamTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:437; JAXRS:JAVADOC:451; JAXRS:JAVADOC:455;
   * JAXRS:JAVADOC:456;
   * 
   * @test_Strategy: Get the entity output stream. Set a new entity output
   * stream.
   */
@Test
public void getEntityStreamTest() throws Fault {
    final String entityStreamWorks = "ENTITY_STREAM_WORKS";
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            OutputStream stream = context.getEntityStream();
            ReplacingOutputStream wrapper = new ReplacingOutputStream(stream, 'X', 'T');
            context.setEntityStream(wrapper);
        }
    };
    ByteArrayInputStream entity = new ByteArrayInputStream(entityStreamWorks.replace('T', 'X').getBytes());
    addProvider(provider);
    setRequestContentEntity(entity);
    setProperty(Property.REQUEST, buildRequest(Request.POST, "post"));
    invoke();
    String body = getResponseBody();
    assertContains(body, entityStreamWorks);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream) ContextProvider(ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider) ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream) 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