// 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();
OMOutputFormat outputFormat = new OMOutputFormat();
outputFormat.setDoOptimize(true);
outputFormat.setMimeBoundary("MIMEBoundary_Axis2Rocks");
env.serializeAndConsume(baos, outputFormat);
String newText = baos.toString();
System.out.println(newText);
assertTrue(newText.contains("soap"));
assertTrue(newText.contains("Envelope"));
assertTrue(newText.contains("Body"));
assertTrue(newText.indexOf("MIMEBoundary_Axis2Rocks") > 0);
assertTrue(newText.indexOf(sampleText) > 0);
assertTrue(newText.indexOf("<soapenv:Body><sendImage xmlns=\"urn://mtom.test.org\"><input><imageData><xop:Include") > 0);
// 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 on the copied message
baos = new ByteArrayOutputStream();
outputFormat = new OMOutputFormat();