Search in sources :

Example 16 with ClientResponseContext

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

the class JAXRSClientIT method setEntityStreamTest.

/*
   * @testName: setEntityStreamTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:476; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Set a new entity input stream. ClientResponseFilter.filter
   */
@Test
public void setEntityStreamTest() throws Fault {
    final String entity = "ENTITY";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            responseContext.setEntityStream(new ByteArrayInputStream(entity.getBytes()));
            InputStream stream = responseContext.getEntityStream();
            assertTrue(stream != null, "the #getEntityStream is null");
            InputStreamReader isr = new InputStreamReader(stream);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new Fault(e);
            } finally {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            assertTrue(entity.equals(line), "The #getEntityStream " + line + " is not equal to what is inserted to the response: " + entity);
            logMsg("#setEntityStream(", entity, ") set entity", line);
        }
    };
    Response response = Response.ok().build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 17 with ClientResponseContext

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

the class JAXRSClientIT method getEntityStreamTest.

/*
   * @testName: getEntityStreamTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:460; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the entity input stream
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getEntityStreamTest() throws Fault {
    final String entity = "ENTITY";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            InputStream stream = responseContext.getEntityStream();
            assertTrue(stream != null, "the #getEntityStream is null");
            InputStreamReader isr = new InputStreamReader(stream);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new Fault(e);
            } finally {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            assertTrue(entity.equals(line), "The #getEntityStream " + line + " is not equal to what is inserted to the response: " + entity);
            logMsg("Found #getEntityStream()=", line);
            // for next reading
            responseContext.setEntityStream(new ByteArrayInputStream(entity.getBytes()));
        }
    };
    Response response = Response.ok(entity).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 18 with ClientResponseContext

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

the class JAXRSClientIT method getEntityTagTest.

/*
   * @testName: getEntityTagTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:461; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the entity tag.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getEntityTagTest() throws Fault {
    final String value = "EntityTagValue";
    final EntityTag tag = new EntityTag(value);
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            EntityTag etag = responseContext.getEntityTag();
            assertTrue(etag != null, "the #getEntityTag is null");
            assertTrue(value.equals(etag.getValue()), "The #getEntityTag " + etag.getValue() + " is not equal to what is inserted to the response: " + value);
            logMsg("Found #getEntityTag()=", value);
        }
    };
    Response response = Response.ok().tag(tag).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) EntityTag(jakarta.ws.rs.core.EntityTag) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 19 with ClientResponseContext

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

the class JAXRSClientIT method getLinkTest.

/*
   * @testName: getLinkTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:467; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the link for the relation.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLinkTest() throws Fault {
    final String rel = "RELATION";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Link link = responseContext.getLink(rel);
            assertTrue(link != null, "the #getLink is null");
            assertTrue(link.getUri() != null, "the #getLink.getUri is null");
            assertTrue(link.getUri().toASCIIString().contains(getUrl()), "#getLink was supposed to contain " + getUrl() + " but was " + link.getUri().toASCIIString());
            logMsg("Found #getLink()=", link.getUri().toASCIIString());
        }
    };
    Response response = Response.ok().link(getUrl(), rel).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 20 with ClientResponseContext

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

the class JAXRSClientIT method hasLinkWhenNoLinkTest.

/*
   * @testName: hasLinkWhenNoLinkTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:475; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Check if link for relation exists.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void hasLinkWhenNoLinkTest() throws Fault {
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            boolean has = responseContext.hasLink("rel");
            assertTrue(!has, "the #hasLink did found some link");
            logMsg("#hasLink has not found any link as expected");
        }
    };
    Response response = Response.ok().link(getUrl(), "ANY").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)

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