// Make sure the Axiom structure is intact
SOAPEnvelope env = axisMC.getEnvelope();
SOAPBody body = env.getBody();
OMElement child = body.getFirstElement();
assertTrue(child instanceof OMSourcedElement);
OMSourcedElement omse = (OMSourcedElement) child;
assertTrue(!omse.isExpanded());
OMDataSource ds = omse.getDataSource();
assertTrue(ds instanceof JAXBBlockImpl);
// Now simulate persisting the message in memory
SOAPEnvelope env2 = CopyUtils.copy(env);
// Make sure the Axiom structure is intact.
env = axisMC.getEnvelope();
body = env.getBody();
child = body.getFirstElement();
assertTrue(child instanceof OMSourcedElement);
omse = (OMSourcedElement) child;
assertTrue(!omse.isExpanded());
ds = omse.getDataSource();
assertTrue(ds instanceof JAXBBlockImpl);
// Simulate transport
ByteArrayOutputStream baos = new ByteArrayOutputStream();
env.serializeAndConsume(baos, new OMOutputFormat());
// To check that the output is correct, get the String contents of the
// reader
String newText = baos.toString();
System.out.println(newText);
assertTrue(newText.contains(sampleJAXBText));
assertTrue(newText.contains("soap"));
assertTrue(newText.contains("Envelope"));
assertTrue(newText.contains("Body"));
// Now check the copied envelope
body = env2.getBody();
child = body.getFirstElement();
assertTrue(child instanceof OMSourcedElement);
omse = (OMSourcedElement) child;
assertTrue(!omse.isExpanded());
ds = omse.getDataSource();
assertTrue(ds instanceof JAXBDataSource);
// Simulate transport
baos = new ByteArrayOutputStream();
env2.serializeAndConsume(baos, new OMOutputFormat());