Search in sources :

Example 1 with GenericEntity

use of jakarta.ws.rs.core.GenericEntity in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method jaxbWriterClientInterceptorTest.

/*
   * @testName: jaxbWriterClientInterceptorTest
   * 
   * @assertion_ids: JAXRS:SPEC:84;
   * 
   * @test_Strategy: JAX-RS implementations are REQUIRED to call registered
   * interceptors when mapping representations to Java types and vice versa.
   */
@Test
@Tag("xml_binding")
public void jaxbWriterClientInterceptorTest() throws Fault {
    JAXBElement<String> element = new JAXBElement<String>(new QName("element"), String.class, content);
    GenericEntity<JAXBElement<String>> entity = new GenericEntity<JAXBElement<String>>(element) {
    };
    addProvider(EntityWriterInterceptor.class);
    addInterceptors(EntityWriterInterceptor.class);
    setRequestContentEntity(entity);
    setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring"));
    setProperty(Property.SEARCH_STRING, EntityWriterInterceptor.class.getName());
    setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_XML_TYPE));
    setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION);
    invoke();
    logMsg("JAXRS called registered writer interceptor for JAXBElement provider");
}
Also used : QName(javax.xml.namespace.QName) GenericEntity(jakarta.ws.rs.core.GenericEntity) JAXBElement(jakarta.xml.bind.JAXBElement) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 2 with GenericEntity

use of jakarta.ws.rs.core.GenericEntity in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method acceptedGenericEntityTest.

/*
   * @testName: acceptedGenericEntityTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:837;
   * 
   * @test_Strategy: Create a new ResponseBuilder with an ACCEPTED status that
   * contains a representation. It is the callers responsibility to wrap the
   * actual entity with GenericEntity if preservation of its generic type is
   * required.
   */
@Test
public void acceptedGenericEntityTest() throws Fault {
    VerificationResult result;
    String entity = "ENtiTy";
    GenericEntity<String> generic = new GenericEntity<String>(entity, String.class);
    Response response = Response.accepted(generic).build();
    result = verifyStatus(response, Status.ACCEPTED.getStatusCode());
    result.append(verifyContent(response, entity));
    logMsg(result.message);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) GenericEntity(jakarta.ws.rs.core.GenericEntity) Test(org.junit.jupiter.api.Test)

Example 3 with GenericEntity

use of jakarta.ws.rs.core.GenericEntity 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)

Example 4 with GenericEntity

use of jakarta.ws.rs.core.GenericEntity in project jaxrs-api by eclipse-ee4j.

the class Resource method getJaxbElement.

@GET
@Path("getjaxb")
public Response getJaxbElement() {
    JAXBElement<String> element = new JAXBElement<String>(new QName("resource"), String.class, getClass().getName());
    GenericEntity<JAXBElement<String>> generic = new GenericEntity<JAXBElement<String>>(element) {
    };
    return buildResponse(generic, MediaType.TEXT_XML_TYPE);
}
Also used : QName(javax.xml.namespace.QName) GenericEntity(jakarta.ws.rs.core.GenericEntity) JAXBElement(jakarta.xml.bind.JAXBElement) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Aggregations

GenericEntity (jakarta.ws.rs.core.GenericEntity)4 Test (org.junit.jupiter.api.Test)3 Response (jakarta.ws.rs.core.Response)2 JAXBElement (jakarta.xml.bind.JAXBElement)2 QName (javax.xml.namespace.QName)2 GET (jakarta.ws.rs.GET)1 Path (jakarta.ws.rs.Path)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 Invocation (jakarta.ws.rs.client.Invocation)1 MediaType (jakarta.ws.rs.core.MediaType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Tag (org.junit.jupiter.api.Tag)1