XMLHelper xmlHelper = hc.getXMLHelper();
DataObject loadedObject =
xmlHelper.load(getClass().getResourceAsStream("/substitutionValues1.xml")).getRootObject();
Type type = loadedObject.getType();
Sequence groupHeadSubstitutionValues = SDOUtil.getSubstitutionValues(loadedObject, type.getProperty("groupHead"));
assertNotNull(groupHeadSubstitutionValues);
assertNull(SDOUtil.getSubstitutionValues(loadedObject, type.getProperty("nonGroupHead")));
String nsURI = "http://www.apache.org/tuscany/SubstitutionValues";
DataObject createdObject = hc.getDataFactory().create(nsURI, "TestObject");
Property groupMemberProperty = xsdHelper.getGlobalProperty(nsURI, "groupMember", true);
createdObject.set(groupMemberProperty, groupHeadSubstitutionValues.getValue(0));
createdObject.setString("nonGroupHead", loadedObject.getString("nonGroupHead"));
assertTrue(hc.getEqualityHelper().equal(loadedObject, createdObject));
ByteArrayOutputStream loadedBaos = new ByteArrayOutputStream();
xmlHelper.save(loadedObject, nsURI, "testObject", loadedBaos);
ByteArrayOutputStream createdBaos = new ByteArrayOutputStream();
xmlHelper.save(createdObject, nsURI, "testObject", createdBaos);
assertTrue(
TestUtil.equalXmlFiles(
new ByteArrayInputStream(loadedBaos.toByteArray()),
new ByteArrayInputStream(createdBaos.toByteArray())));
loadedObject =
xmlHelper.load(getClass().getResourceAsStream("/substitutionValues2.xml")).getRootObject();
groupHeadSubstitutionValues = SDOUtil.getSubstitutionValues(loadedObject, type.getProperty("groupHead"));
createdObject = hc.getDataFactory().create(nsURI, "TestObject");
createdObject.set("groupHead", groupHeadSubstitutionValues.getValue(0));
createdObject.setString("nonGroupHead", loadedObject.getString("nonGroupHead"));
assertTrue(hc.getEqualityHelper().equal(loadedObject, createdObject));
}