public void testSerializeToBytes() throws Exception {
OMSourcedElement element = createSourcedElement("test", UTF8);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
element.serialize(baos);
byte[] actual = baos.toByteArray();
baos.reset();
// We validate the result by creating an equivalent OMElement
// and calling serialize on it. The two results must be identical.
element.cloneOMElement().serialize(baos);
byte[] expected = baos.toByteArray();
assertTrue(Arrays.equals(expected, actual));