Search in sources :

Example 1 with ContextProvider

use of ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method setMethodTest.

/*
   * @testName: setMethodTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:452; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * 
   * @test_Strategy: Set the request method.
   */
@Test
public void setMethodTest() throws Fault {
    String entity = "ENTITY";
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            context.setMethod("PUT");
        }
    };
    addProvider(provider);
    setRequestContentEntity(entity);
    setProperty(Property.REQUEST, buildRequest(Request.POST, "put"));
    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) Test(org.junit.jupiter.api.Test)

Example 2 with ContextProvider

use of ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getHeadersIsMutableTest.

/*
   * @testName: getHeadersIsMutableTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:439; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * 
   * @test_Strategy: Get the generic entity type information.
   */
@Test
public void getHeadersIsMutableTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            MultivaluedMap<String, Object> headers = context.getHeaders();
            headers.add("Accept-Language", "en_gb");
            headers.add("Date", "Tue, 15 Nov 1994 08:12:31 GMT");
            headers.add("tck", "cts");
        }
    };
    addProvider(provider);
    setProperty(Property.REQUEST, buildRequest(Request.GET, "headers"));
    invoke();
    String body = getResponseBody().toLowerCase();
    assertContains(body, "accept-language");
    assertContains(body, "date");
    assertContains(body, "tck");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) ContextProvider(ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider) Test(org.junit.jupiter.api.Test)

Example 3 with ContextProvider

use of ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider 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 4 with ContextProvider

use of ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider 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

ContextProvider (ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider)4 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)4 Test (org.junit.jupiter.api.Test)4 ReplacingOutputStream (ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1