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