@SuppressWarnings("unchecked") @Test public void testRead() throws Exception { XSLTJaxbProvider provider = new XSLTJaxbProvider(); provider.setInTemplate(TEMPLATE_LOCATION); Book b = new Book(); b.setId(123L); b.setName("TheBook"); Book b2 = (Book) provider.readFrom( (Class) 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); }
@Test public void testWrite() throws Exception { XSLTJaxbProvider provider = new XSLTJaxbProvider(); provider.setOutTemplate(TEMPLATE_LOCATION); Book b = new Book(); b.setId(123L); b.setName("TheBook"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); provider.writeTo( b, Book.class, Book.class, b.getClass().getAnnotations(), 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); }