Search in sources :

Example 31 with ClientResponseContext

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

the class JAXRSClientIT method getLinksTest.

/*
   * @testName: getLinksTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:469; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the links attached to the message as header.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLinksTest() throws Fault {
    final Link link = Link.fromUri(getUrl()).build();
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Set<Link> links = responseContext.getLinks();
            assertTrue(links != null, "the #getLinks is null");
            assertTrue(links.size() == 1, "the links was supposed to be of size 1, was " + links.size());
            assertTrue(links.contains(link), "#getLinks was supposed to contain " + link.getUri().toASCIIString());
            logMsg("Found #getLinks()={", link.getUri().toASCIIString(), "}");
        }
    };
    Response response = Response.ok().links(link).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) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 32 with ClientResponseContext

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

the class JAXRSClientIT method setCorruptedStream.

protected AtomicInteger setCorruptedStream() {
    final AtomicInteger ai = new AtomicInteger(0);
    ClientResponseFilter filter = new ClientResponseFilter() {

        @Override
        public void filter(ClientRequestContext arg0, ClientResponseContext response) throws IOException {
            CorruptedInputStream cis = new CorruptedInputStream(ResponseTest.ENTITY.getBytes(), ai);
            cis.setCorrupted(true);
            response.setEntityStream(cis);
        }
    };
    addProvider(filter);
    // do not use new entity stream in logging filter for the case of priority
    // disfunction, the CorruptedInputStream would be then replaced, wrongly
    // informing about not closing the stream
    super.setPrintEntity(false);
    return ai;
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientResponseFilter(jakarta.ws.rs.client.ClientResponseFilter) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext)

Example 33 with ClientResponseContext

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

the class JAXRSClientIT method getLocationNotPresentTest.

/*
   * @testName: getLocationNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:856;
   * 
   * @test_Strategy: Get null when no present.
   */
@Test
public void getLocationNotPresentTest() throws Fault {
    ResponseHeaderValue<URI> containerValue = new ResponseHeaderValue<>();
    addProvider(new HeaderNotPresent<URI>(containerValue) {

        @Override
        protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<URI> header) {
            header.value = responseContext.getLocation();
        }
    });
    Response response = invokeGet("entity");
    URI responseLocation = response.getLocation();
    assertHeaderNull(responseLocation, containerValue, "getLocation");
}
Also used : Response(jakarta.ws.rs.core.Response) URI(java.net.URI) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 34 with ClientResponseContext

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

the class JAXRSClientIT method getLastModifiedNotPresentTest.

/*
   * @testName: getLastModifiedNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:851;
   * 
   * @test_Strategy: Get null if not present.
   */
@Test
public void getLastModifiedNotPresentTest() throws Fault {
    ResponseHeaderValue<Date> containerValue = new ResponseHeaderValue<>();
    addProvider(new HeaderNotPresent<Date>(containerValue) {

        @Override
        protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<Date> header) {
            header.value = responseContext.getLastModified();
        }
    });
    Response response = invokePost("lastmodified", null);
    Date responseDate = response.getLastModified();
    assertHeaderNull(responseDate, containerValue, "getLastModified");
}
Also used : 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