@SuppressWarnings("unchecked")
@Test
public void testWriteWithXmlRootElementAndPackageInfo() throws Exception {
JAXBElementProvider provider = new JAXBElementProvider();
Book2 book = new Book2(333);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(book, Book2.class,
Book2.class,
new Annotation[0], MediaType.TEXT_XML_TYPE,
new MetadataMap<String, Object>(), bos);
assertTrue(bos.toString().contains("thebook2"));
assertTrue(bos.toString().contains("http://superbooks"));
ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
Book2 book2 =
(Book2)provider.readFrom(
(Class)Book2.class,
Book2.class,
new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
assertEquals(book2.getId(), book.getId());
}