use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class ProviderFactoryTest method testSchemaLocations.
@Test
public void testSchemaLocations() {
ProviderFactory pf = ServerProviderFactory.getInstance();
MessageBodyReader<Book> jaxbReader = pf.createMessageBodyReader(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertTrue(jaxbReader instanceof JAXBElementProvider);
pf.setSchemaLocations(Collections.singletonList("classpath:/test.xsd"));
MessageBodyReader<Book> customJaxbReader = pf.createMessageBodyReader(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertTrue(jaxbReader instanceof JAXBElementProvider);
assertSame(jaxbReader, customJaxbReader);
assertNotNull(((JAXBElementProvider<Book>) customJaxbReader).getSchema());
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class ProviderFactoryTest method testRegisterMbrMbwProviderAsMbrOnly.
@Test
public void testRegisterMbrMbwProviderAsMbrOnly() {
ServerProviderFactory pf = ServerProviderFactory.getInstance();
JAXBElementProvider<Book> customProvider = new JAXBElementProvider<Book>();
pf.registerUserProvider((Feature) context -> {
context.register(customProvider, MessageBodyReader.class);
return true;
});
MessageBodyReader<Book> reader = pf.createMessageBodyReader(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertSame(reader, customProvider);
MessageBodyWriter<Book> writer = pf.createMessageBodyWriter(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertTrue(writer instanceof JAXBElementProvider);
assertNotSame(writer, customProvider);
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class ProviderFactoryTest method testCustomJaxbProvider.
@Test
public void testCustomJaxbProvider() {
ProviderFactory pf = ServerProviderFactory.getInstance();
JAXBElementProvider<Book> provider = new JAXBElementProvider<Book>();
pf.registerUserProvider(provider);
MessageBodyReader<Book> customJaxbReader = pf.createMessageBodyReader(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertSame(customJaxbReader, provider);
MessageBodyWriter<Book> customJaxbWriter = pf.createMessageBodyWriter(Book.class, null, null, MediaType.TEXT_XML_TYPE, new MessageImpl());
assertSame(customJaxbWriter, provider);
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class XSLTJaxbProviderTest method testReadFromStreamReader.
@Test
public void testReadFromStreamReader() throws Exception {
XSLTJaxbProvider<Book> provider = new XSLTJaxbProvider<Book>() {
@Override
protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType mt) {
return StaxUtils.createXMLStreamReader(is);
}
};
provider.setInTemplate(TEMPLATE_LOCATION);
Book b = new Book();
b.setId(123L);
b.setName("TheBook");
Book b2 = provider.readFrom(Book.class, Book.class, b.getClass().getAnnotations(), MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(BOOK_XML.getBytes()));
b.setName("TheBook2");
assertEquals("Transformation is bad", b, b2);
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class XSLTJaxbProviderTest method testWriteWithAnnotation.
@Test
public void testWriteWithAnnotation() throws Exception {
XSLTJaxbProvider<Book> provider = new XSLTJaxbProvider<Book>();
provider.setMessageContext(new MessageContextImpl(createMessage()));
Book b = new Book();
b.setId(123L);
b.setName("TheBook");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Annotation[] anns = Root.class.getMethod("getBook").getAnnotations();
assertTrue(provider.isWriteable(Book.class, Book.class, anns, MediaType.TEXT_XML_TYPE));
provider.writeTo(b, Book.class, Book.class, anns, MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
Unmarshaller um = provider.getClassContext(Book.class).createUnmarshaller();
Book b2 = (Book) um.unmarshal(new StringReader(bos.toString()));
b.setName("TheBook2");
assertEquals("Transformation is bad", b, b2);
}
Aggregations