super(metaFactory, spec);
}
protected void runTest() throws Throwable {
SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
String localName = "myPayload";
String encoding = "utf-8";
String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = soapFactory.createOMNamespace("urn://test", "tns");
ByteArrayDataSource bads1 = new ByteArrayDataSource(payload1.getBytes(encoding), encoding);
// Set an empty MustUnderstand property on the data source
bads1.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, bads1);
soapHeader.addChild(omse);
OMNode firstChild = soapHeader.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof SOAPHeaderBlock);
SOAPHeaderBlock child = (SOAPHeaderBlock) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
child.getDataSource() instanceof ByteArrayDataSource);
// Make sure that getting the MustUnderstand property does not cause expansion.
assertTrue(!child.getMustUnderstand());
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
child.getDataSource() instanceof ByteArrayDataSource);
// A ByteArrayDataSource does not consume the backing object when read.
// Thus getting the XMLStreamReader of the ByteArrayDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// Likewise, a ByteArrayDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
soapHeader.serialize(baos);
String output = baos.toString(encoding);
// System.out.println(output);
assertTrue("The payload was not present in the output",
output.indexOf(payload1) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());