Search in sources :

Example 11 with ClientRequestContext

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

the class JAXRSClientIT method getEntityTest.

/*
   * @testName: getEntityTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:434; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85;
   * 
   * @test_Strategy: Get the message entity Java instance. Returns null if the
   * message does not contain an entity.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Object entity = context.getEntity();
            Response r = Response.ok(entity.toString()).build();
            context.abortWith(r);
        }
    };
    Entity<String> post = createEntity("test");
    Invocation invocation = buildBuilder(provider).buildPost(post);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "test");
}
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 12 with ClientRequestContext

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

the class JAXRSClientIT method getEntityNullTest.

/*
   * @testName: getEntityNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:434; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the message entity Java instance. Returns null if the
   * message does not contain an entity.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityNullTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Object entity = context.getEntity();
            Response r = Response.ok(entity == null ? "NULL" : entity.toString()).build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildInvocation(provider);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "NULL");
}
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 13 with ClientRequestContext

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

the class JAXRSClientIT method getLanguageIsNullTest.

/*
   * @testName: getLanguageIsNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:441; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the language of the entity. Returns: the language of
   * the entity or null if not specified
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getLanguageIsNullTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Locale lang = context.getLanguage();
            String entity = lang == null ? "NULL" : lang.toString();
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    Entity<String> entity = createEntity("TEST");
    Invocation invocation = buildBuilder(provider).buildPost(entity);
    Response response = invoke(invocation);
    String body = response.readEntity(String.class);
    assertContains(body, "NULL");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Test(org.junit.jupiter.api.Test)

Example 14 with ClientRequestContext

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

the class JAXRSClientIT method getEntityAnnotationsNullTest.

/*
   * @testName: getEntityAnnotationsNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:435; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the annotations attached to the entity.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityAnnotationsNullTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Annotation[] annotations = context.getEntityAnnotations();
            String len = annotations == null ? "0" : String.valueOf(annotations.length);
            Response r = Response.ok(len).build();
            context.abortWith(r);
        }
    };
    Entity<String> post = createEntity("test");
    Invocation invocation = buildBuilder(provider).buildPost(post);
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "0");
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Annotation(java.lang.annotation.Annotation) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) Test(org.junit.jupiter.api.Test)

Example 15 with ClientRequestContext

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

the class JAXRSClientIT method getLanguageTest.

/*
   * @testName: getLanguageTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:441; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the language of the entity. Returns: the language of
   * the entity or null if not specified
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getLanguageTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Locale lang = context.getLanguage();
            String entity = lang == null ? "NULL" : lang.toString();
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    Locale locale = Locale.TRADITIONAL_CHINESE;
    Variant variant = new Variant(MediaType.TEXT_XML_TYPE, locale, null);
    Entity<String> entity = Entity.entity("TEST", variant);
    Invocation invocation = buildBuilder(provider).buildPost(entity);
    Response response = invoke(invocation);
    String body = response.readEntity(String.class).toLowerCase().replace('-', '_');
    assertContains(body, locale.toString().toLowerCase());
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) Variant(jakarta.ws.rs.core.Variant) Invocation(jakarta.ws.rs.client.Invocation) 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