Search in sources :

Example 11 with ClientResponseContext

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

the class JAXRSClientIT method getHeadersIsMutableTest.

/*
   * @testName: getHeadersIsMutableTest
   * 
   * @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 getHeadersIsMutableTest() throws Fault {
    final String header1 = "header1";
    final String value1 = "value1";
    ContextProvider in = new ContextProvider() {

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

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

the class JAXRSClientIT method getLanguageNotPresentTest.

/*
   * @testName: getLanguageNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:850;
   * 
   * @test_Strategy: Get null if not present.
   */
@Test
public void getLanguageNotPresentTest() throws Fault {
    ResponseHeaderValue<Locale> value = new ResponseHeaderValue<>();
    addProvider(new HeaderNotPresent<Locale>(value) {

        @Override
        protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<Locale> header) {
            header.value = responseContext.getLanguage();
        }
    });
    Response response = invokePost("language", null);
    Locale locale = response.getLanguage();
    assertHeaderNull(locale, value, "getLanguage");
}
Also used : Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 13 with ClientResponseContext

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

the class JAXRSClientIT method getLinkNotPresentTest.

/*
   * @testName: getLinkNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:853;
   * 
   * @test_Strategy: returns null if not present.
   */
@Test
public void getLinkNotPresentTest() throws Fault {
    ResponseHeaderValue<Link> containerValue = new ResponseHeaderValue<>();
    addProvider(new HeaderNotPresent<Link>(containerValue) {

        @Override
        protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<Link> header) {
            header.value = responseContext.getLink("getLinkTest");
        }
    });
    Response response = invokePost("link", null);
    Link responseLink = response.getLink("getLinkTest");
    assertHeaderNull(responseLink, containerValue, "getLink");
}
Also used : 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 14 with ClientResponseContext

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

the class JAXRSClientIT method getEntityTagNotPresentTest.

/*
   * @testName: getEntityTagNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:847;
   * 
   * @test_Strategy: Get null if not present.
   */
@Test
public void getEntityTagNotPresentTest() throws Fault {
    ResponseHeaderValue<EntityTag> value = new ResponseHeaderValue<>();
    addProvider(new HeaderNotPresent<EntityTag>(value) {

        @Override
        protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<EntityTag> header) {
            header.value = responseContext.getEntityTag();
        }
    });
    Response response = invokePost("entitytag", null);
    EntityTag responseTag = response.getEntityTag();
    assertHeaderNull(responseTag, value, "getEntityTag");
}
Also used : 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 15 with ClientResponseContext

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

the class JAXRSClientIT method getAllowedMethodsTest.

/*
   * @testName: getAllowedMethodsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:457; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get the allowed HTTP methods from the Allow HTTP header.
   * All methods will returned as upper case strings.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getAllowedMethodsTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Set<String> map = responseContext.getAllowedMethods();
            logMsg("found methods:", JaxrsUtil.iterableToString(" ", map));
            assertTrue(map.size() == 2, "Allowed mthods were not set");
            assertTrue(map.contains("OPTIONS"), "OPTIONS allowed method were not found");
            assertTrue(map.contains("GET"), "GET allowed method was not found");
        }
    };
    Response response = Response.ok().header(HttpHeaders.ALLOW, "get").header(HttpHeaders.ALLOW, "options").build();
    invokeWithResponseAndAssertStatus(response, Status.OK, provider);
}
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