Search in sources :

Example 61 with ClientRequestContext

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

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

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

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

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

ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)77 Response (jakarta.ws.rs.core.Response)71 Test (org.junit.jupiter.api.Test)70 Invocation (jakarta.ws.rs.client.Invocation)38 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)29 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)10 MediaType (jakarta.ws.rs.core.MediaType)8 Locale (java.util.Locale)6 WebTarget (jakarta.ws.rs.client.WebTarget)5 ContextProvider (ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider)4 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Date (java.util.Date)4 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)3 StringBeanRuntimeDelegate (ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate)3 StringBeanWithAnnotation (ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation)3 Client (jakarta.ws.rs.client.Client)3 Link (jakarta.ws.rs.core.Link)3 RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)3 IOException (java.io.IOException)3