Search in sources :

Example 1 with StringBeanWithAnnotation

use of ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getEntityAnnotationsIsNotTakenFromEntityClassTest.

/*
   * @testName: getEntityAnnotationsIsNotTakenFromEntityClassTest
   * 
   * @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. Note that the
   * returned annotations array contains only those annotations explicitly
   * attached to entity instance (such as the ones attached using
   * Entity.Entity(Object, jakarta.ws.rs.core.MediaType,
   * java.lang.annotation.Annotation[]) method). The entity instance annotations
   * array does not include annotations declared on the entity implementation
   * class or its ancestors.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getEntityAnnotationsIsNotTakenFromEntityClassTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Annotation[] annotations = context.getEntityAnnotations();
            String first = annotations == null ? "0" : String.valueOf(annotations.length);
            Response r = Response.ok(first).build();
            context.abortWith(r);
        }
    };
    Entity<StringBeanWithAnnotation> post = createEntity(new StringBeanWithAnnotation("test"));
    Invocation invocation = buildTarget(provider).register(StringBeanEntityProvider.class).request().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) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) Annotation(java.lang.annotation.Annotation) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) Test(org.junit.jupiter.api.Test)

Example 2 with StringBeanWithAnnotation

use of ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation in project jaxrs-api by eclipse-ee4j.

the class Resource method getEntityAnnotationsOnEntity.

@POST
@Path("getentityannotationsonentity")
public Response getEntityAnnotationsOnEntity(String entity) {
    ResponseBuilder builder = createResponseWithHeader();
    builder = builder.entity(new StringBeanWithAnnotation(entity));
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Aggregations

StringBeanWithAnnotation (ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation)2 Response (jakarta.ws.rs.core.Response)2 POST (jakarta.ws.rs.POST)1 Path (jakarta.ws.rs.Path)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 Invocation (jakarta.ws.rs.client.Invocation)1 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)1 Annotation (java.lang.annotation.Annotation)1 Test (org.junit.jupiter.api.Test)1