Search in sources :

Example 41 with Book

use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.

the class JAXBElementProviderTest method testReadJAXBElement.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testReadJAXBElement() throws Exception {
    String xml = "<Book><id>123</id><name>CXF in Action</name></Book>";
    JAXBElementProvider<JAXBElement> provider = new JAXBElementProvider<JAXBElement>();
    JAXBElement<Book> jaxbElement = provider.readFrom(JAXBElement.class, Book.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
    Book book = jaxbElement.getValue();
    assertEquals(123L, book.getId());
    assertEquals("CXF in Action", book.getName());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SuperBook(org.apache.cxf.jaxrs.resources.SuperBook) Book(org.apache.cxf.jaxrs.resources.Book) ParamJAXBElement(org.apache.cxf.jaxrs.fortest.jaxb.jaxbelement.ParamJAXBElement) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 42 with Book

use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.

the class ResponseImplTest method testGetEntityUnwrapped.

@Test
public void testGetEntityUnwrapped() {
    final Book book = new Book();
    Response r = Response.ok().entity(new GenericEntity<Book>(book) {
    }).build();
    assertSame(book, r.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) Book(org.apache.cxf.jaxrs.resources.Book) GenericEntity(javax.ws.rs.core.GenericEntity) Test(org.junit.Test)

Aggregations

Book (org.apache.cxf.jaxrs.resources.Book)42 SuperBook (org.apache.cxf.jaxrs.resources.SuperBook)35 Test (org.junit.Test)35 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 MessageImpl (org.apache.cxf.message.MessageImpl)9 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Method (java.lang.reflect.Method)5 MediaType (javax.ws.rs.core.MediaType)5 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)5 Exchange (org.apache.cxf.message.Exchange)5 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)5 Message (org.apache.cxf.message.Message)5 OutputStream (java.io.OutputStream)4 StringReader (java.io.StringReader)4 Annotation (java.lang.annotation.Annotation)4 Response (javax.ws.rs.core.Response)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 InputStream (java.io.InputStream)3