Search in sources :

Example 21 with ClientResponseContext

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

the class JAXRSClientIT method hasLinkWhenLinkTest.

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

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            boolean has = responseContext.hasLink(rel);
            assertTrue(has, "the #hasLink did not found the given link");
            logMsg("#hasLink has found the given link");
        }
    };
    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) Test(org.junit.jupiter.api.Test)

Example 22 with ClientResponseContext

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

the class JAXRSClientIT method getLastModifiedTest.

/*
   * @testName: getLastModifiedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:465; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the last modified date.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getLastModifiedTest() throws Fault {
    final Date lastModified = getNewDate();
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Date date = responseContext.getLastModified();
            assertTrue(date != null, "the #getLastModified is null");
            assertTrue(lastModified.equals(date), "#getLastModified was supposed to be " + lastModified + " but was " + date);
            logMsg("Found #getLastModified()=", date);
        }
    };
    Response response = Response.ok().lastModified(lastModified).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 23 with ClientResponseContext

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

the class JAXRSClientIT method getHeaderStringTest.

/*
   * @testName: getHeaderStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: the message header value.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getHeaderStringTest() throws Fault {
    final String header1 = "header1";
    final String value1 = "value1";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            String header = responseContext.getHeaderString(header1);
            assertTrue(header != null, "the #getHeaderString is null");
            assertTrue(header.equals(value1), "the #getHeaderString=" + header + " differs from expected " + value1);
            logMsg("#getHeaderString is", value1, "as expected");
        }
    };
    Response response = Response.ok().header(header1, value1).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 24 with ClientResponseContext

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

the class JAXRSClientIT method getHeaderStringIsEmptyTest.

/*
   * @testName: getHeaderStringIsEmptyTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: the message header value. If the message header is present
   * but has no value then the empty string is returned.
   * 
   * ClientResponseFilter.filter
   */
@Test
public <T> void getHeaderStringIsEmptyTest() throws Fault {
    final String header1 = "header1";
    RuntimeDelegate original = RuntimeDelegate.getInstance();
    RuntimeDelegate.setInstance(new NullStringBeanRuntimeDelegate(original));
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            String header = responseContext.getHeaderString(header1);
            assertTrue(header != null, "the #getHeaderString is null");
            assertTrue(header.equals(""), "the #getHeaderString is NOT empty, but " + header);
            logMsg("#getHeaderString is empty string as expected");
        }
    };
    Response response = Response.ok().header(header1, new StringBean("aa")).build();
    try {
        invokeWithResponseAndAssertStatus(response, Status.OK, in);
    } finally {
        RuntimeDelegate.setInstance(original);
        StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
    }
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Test(org.junit.jupiter.api.Test)

Example 25 with ClientResponseContext

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

the class JAXRSClientIT method hasEntityWhenEntityTest.

/*
   * @testName: hasEntityWhenEntityTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:474; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Check if there is a non-empty entity input stream is
   * available in the response message. ClientResponseFilter.filter
   */
@Test
public void hasEntityWhenEntityTest() throws Fault {
    final String entity = "eNtitY";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            boolean has = responseContext.hasEntity();
            assertTrue(has, "the #hasEntity did not found the given entity");
            logMsg("Found #hasEntity()=true");
        }
    };
    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) 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