Search in sources :

Example 1 with ClientResponseContext

use of jakarta.ws.rs.client.ClientResponseContext 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 2 with ClientResponseContext

use of jakarta.ws.rs.client.ClientResponseContext 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)

Example 3 with ClientResponseContext

use of jakarta.ws.rs.client.ClientResponseContext 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 4 with ClientResponseContext

use of jakarta.ws.rs.client.ClientResponseContext 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 5 with ClientResponseContext

use of jakarta.ws.rs.client.ClientResponseContext 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)

Aggregations

ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)34 Response (jakarta.ws.rs.core.Response)33 Test (org.junit.jupiter.api.Test)33 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)29 Link (jakarta.ws.rs.core.Link)3 Date (java.util.Date)3 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)2 Invocation (jakarta.ws.rs.client.Invocation)2 EntityTag (jakarta.ws.rs.core.EntityTag)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 Locale (java.util.Locale)2 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)1 StringBeanRuntimeDelegate (ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate)1 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)1 ClientResponseFilter (jakarta.ws.rs.client.ClientResponseFilter)1