Search in sources :

Example 21 with ClientRequestContext

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

the class JAXRSClientIT method getLocationTest.

/*
   * @testName: getLocationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:470; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the location. ClientResponseFilter.filter
   */
@Test
public void getLocationTest() throws Fault {
    URI uri = null;
    try {
        uri = new URI(getUrl());
    } catch (URISyntaxException e) {
        throw new Fault(e);
    }
    final URI location = uri;
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            URI responseLocation = responseContext.getLocation();
            assertTrue(responseLocation != null, "the #getLinks is null");
            assertTrue(location.equals(responseLocation), "#getLocation was supposed to be " + location + " but was " + responseLocation);
            logMsg("Found #getLocation=", location.toASCIIString());
        }
    };
    Response response = Response.ok().location(location).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 22 with ClientRequestContext

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

the class JAXRSClientIT method createRequestFilter.

// ///////////////////////////////////////////////////////////////////////
protected static ClientRequestFilter createRequestFilter(final Response response) {
    ClientRequestFilter outFilter = new ClientRequestFilter() {

        @Override
        public void filter(ClientRequestContext context) throws IOException {
            // logMsg(" -- OUT FILTER --");
            Response r;
            if (response == null)
                r = Response.ok().build();
            else
                r = response;
            context.abortWith(r);
        }
    };
    return outFilter;
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response)

Example 23 with ClientRequestContext

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

the class JAXRSClientIT method getCookiesTest.

/*
   * @testName: getCookiesTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:458; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get any new cookies set on the response message.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getCookiesTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Map<String, NewCookie> map = responseContext.getCookies();
            assertTrue(map.size() == 2, "Cookies were not set");
        }
    };
    NewCookie cookie1 = new NewCookie("cookie1", "cookie1");
    NewCookie cookie2 = new NewCookie("cookie2", "cookie2");
    Response response = Response.ok().cookie(cookie1).cookie(cookie2).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, provider);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 24 with ClientRequestContext

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

the class JAXRSClientIT method getDateTest.

/*
   * @testName: getDateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:459; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get message date.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getDateTest() throws Fault {
    final Date date = getNewDate();
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            assertTrue(date.equals(responseContext.getDate()), "The #getDate " + responseContext.getDate() + " is not equal to what is inserted to the response " + date);
            logMsg("Found #getDate()=", responseContext.getDate());
        }
    };
    Response response = Response.ok().header("Date", date).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) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 25 with ClientRequestContext

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

the class JAXRSClientIT method setStatusTest.

/*
   * @testName: setStatusTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:477; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Set a new response status code. ClientResponseFilter.filter
   */
@Test
public void setStatusTest() throws Fault {
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            responseContext.setStatus(Status.FORBIDDEN.getStatusCode());
        }
    };
    Response response = Response.ok().build();
    invokeWithResponseAndAssertStatus(response, Status.FORBIDDEN, 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