Search in sources :

Example 51 with ClientRequestContext

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

the class JAXRSClientIT method hasEntityTest.

/*
   * @testName: hasEntityTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:448; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Check if there is an entity available in the request. The
   * method returns true if the entity is present, returns false otherwise.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void hasEntityTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            boolean has = context.hasEntity();
            String entity = String.valueOf(has);
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildInvocation(provider);
    Response response = invoke(invocation);
    String body = response.readEntity(String.class);
    assertContains(body, "false");
    Entity<String> entity = createEntity("TEST");
    WebTarget target = buildTarget(provider);
    invocation = target.request().buildPost(entity);
    response = invoke(invocation);
    body = response.readEntity(String.class);
    assertContains(body, "true");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 52 with ClientRequestContext

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

the class JAXRSClientIT method getConfigurationTest.

/*
   * @testName: getConfigurationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:977; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the immutable configuration of the request.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getConfigurationTest() throws Fault {
    final Client client = ClientBuilder.newClient();
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Client contextClient = context.getClient();
            assertEquals(contextClient, client, "the client instance is different from the context one");
            Configuration contextConfig = context.getConfiguration();
            assertNotNull(contextConfig, "context.getConfiguration() returned null");
            Response r = Response.ok().build();
            context.abortWith(r);
        }
    };
    client.register(provider);
    WebTarget target = client.target(getUrl());
    Invocation invocation = target.request().buildGet();
    Response response = invoke(invocation);
    assertStatus(response, Status.OK);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Configuration(jakarta.ws.rs.core.Configuration) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Example 53 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:439; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the mutable request headers multivalued map.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getHeadersTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            MultivaluedMap<String, Object> headers = context.getHeaders();
            String entity = JaxrsUtil.iterableToString(";", headers.keySet());
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildBuilder(provider).header("Accept", MediaType.TEXT_HTML).header("tck", "cts").header("Date", "Tue, 15 Nov 1994 08:12:31 GMT").buildGet();
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "Accept");
    assertContains(entity, "Date");
    assertContains(entity, "tck");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Test(org.junit.jupiter.api.Test)

Example 54 with ClientRequestContext

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

the class JAXRSClientIT method getEntityClassListStringTest.

/*
   * @testName: getEntityClassListStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:436; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the raw entity type information.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityClassListStringTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Class<?> clazz = context.getEntityClass();
            Response r = Response.ok(clazz.getName()).build();
            context.abortWith(r);
        }
    };
    List<String> list = new ArrayList<String>();
    Entity<List<String>> post = createEntity(list);
    Invocation invocation = buildBuilder(provider).buildPost(post);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, ArrayList.class.getName());
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 55 with ClientRequestContext

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

the class JAXRSClientIT method getEntityTypeListStringTest.

/*
   * @testName: getEntityTypeListStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:438; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the generic entity type information.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityTypeListStringTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Type type = context.getEntityType();
            String entity = type.toString();
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    List<String> list = new ArrayList<String>();
    GenericEntity<List<String>> generic = new GenericEntity<List<String>>(list) {
    };
    Entity<GenericEntity<List<String>>> post = createEntity(generic);
    Invocation invocation = buildBuilder(provider).buildPost(post);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, String.class.getName());
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType) Type(java.lang.reflect.Type) Invocation(jakarta.ws.rs.client.Invocation) GenericEntity(jakarta.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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