Search in sources :

Example 26 with ClientResponseContext

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

the class JAXRSClientIT method setStatusInfoTest.

/*
   * @testName: setStatusInfoTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:478; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Set the complete status information associated with the
   * response.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void setStatusInfoTest() throws Fault {
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            StatusType info = new StatusType() {

                @Override
                public int getStatusCode() {
                    return Status.FOUND.getStatusCode();
                }

                @Override
                public String getReasonPhrase() {
                    return null;
                }

                @Override
                public Family getFamily() {
                    return null;
                }
            };
            responseContext.setStatusInfo(info);
        }
    };
    Response response = Response.ok().build();
    invokeWithResponseAndAssertStatus(response, Status.FOUND, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 27 with ClientResponseContext

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

the class JAXRSClientIT method getHeadersTest.

/*
   * @testName: getHeadersTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:462; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the mutable response headers multivalued map.
   *
   * ClientResponseFilter.filter
   */
@Test
public void getHeadersTest() throws Fault {
    final String header1 = "header1";
    final String value1 = "value1";
    final String header2 = "header2";
    final String value2 = "value2";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            MultivaluedMap<String, String> headers = responseContext.getHeaders();
            assertTrue(headers != null, "the #getHeaders is null");
            assertTrue(headers.size() == 2, "the #getHeaders size is " + headers.size() + " expected 2");
            assertTrue(value1.equals(headers.getFirst(header1)), "#getHeaders was supposed to contain" + header1 + ":" + value1 + " header, but " + header1 + " is " + headers.getFirst(header1));
            logMsg("Found #getHeaders()={", header1, ":", value1, "}");
        }
    };
    Response response = Response.ok().header(header1, value1).header(header2, value2).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 28 with ClientResponseContext

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

the class JAXRSClientIT method getLinkBuilderTest.

/*
   * @testName: getLinkBuilderTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:468; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Convenience method that returns a
   * jakarta.ws.rs.core.Link.Builder for the relation. ClientResponseFilter.filter
   */
@Test
public void getLinkBuilderTest() throws Fault {
    final String rel = "RELATION";
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Builder builder = responseContext.getLinkBuilder(rel);
            assertTrue(builder != null, "the #getLinkBuilder is null");
            assertTrue(builder.build().getUri().toASCIIString().contains(getUrl()), "#getLinkBuilder.build was supposed to contain " + getUrl() + " but was " + builder.build().getUri().toASCIIString());
            logMsg("Found #getLinkBuilder()=", builder.build().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) Builder(jakarta.ws.rs.core.Link.Builder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 29 with ClientResponseContext

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

the class JAXRSClientIT method getHeaderStringIsCommaSeparatedTest.

/*
   * @testName: getHeaderStringIsCommaSeparatedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: the message header value. If the message header is present
   * more than once then the values of joined together and separated by a ','
   * character.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getHeaderStringIsCommaSeparatedTest() throws Fault {
    final String header1 = "header1";
    final String value1 = "value1";
    final String value2 = "value2";
    ContextProvider in = new ContextProvider() {

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

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

the class JAXRSClientIT method getStatusInfoTest.

/*
   * @testName: getStatusInfoTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:473; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the status code associated with the response.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getStatusInfoTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            assertTrue(responseContext.getStatusInfo().getStatusCode() == 222, "unexpected status " + responseContext.getStatusInfo().getStatusCode());
            TestUtil.logMsg("Found expected response status 222");
        }
    };
    Response response = Response.status(222).build();
    ClientRequestFilter filter = createRequestFilter(response);
    Invocation i = buildInvocation(filter, provider);
    Response r = invoke(i);
    assertTrue(r.getStatus() == 222, "unexpected status " + r.getStatus());
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) Invocation(jakarta.ws.rs.client.Invocation) 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