@Test
public void test1() throws Exception {
// test read
String input = loadStreamToString(getClass().getResourceAsStream("proppatch1.xml"));
Propertyupdate propupdate = read(input);
// set properties
List<Prop> props = propupdate.getPropsToSet();
Assert.assertEquals(1, props.size());
Prop prop = props.get(0);
Set<QName> propertyNames = new HashSet<QName>();
WebDAVModelHelper.extractPropertyNames(prop, propertyNames);
Assert.assertArrayEquals(propertyNames.toArray(new QName[propertyNames.size()]),
new QName[] {SET_PROPERTY});
Element element = prop.getAny().get(0);
Element child = (Element)element.getFirstChild();
Assert.assertNotNull(child);
Assert.assertEquals(SET_PROPERTY_CHILD.getNamespaceURI(), child.getNamespaceURI());
Assert.assertEquals(SET_PROPERTY_CHILD.getLocalPart(), child.getLocalName());
Assert.assertEquals(SET_PROPERTY_CHILD_VALUES[0], child.getTextContent());
child = (Element)child.getNextSibling();
Assert.assertNotNull(child);
Assert.assertEquals(SET_PROPERTY_CHILD.getNamespaceURI(), child.getNamespaceURI());
Assert.assertEquals(SET_PROPERTY_CHILD.getLocalPart(), child.getLocalName());
Assert.assertEquals(SET_PROPERTY_CHILD_VALUES[1], child.getTextContent());
// remove properties
props = propupdate.getPropsToRemove();
Assert.assertEquals(1, props.size());
prop = props.get(0);
propertyNames = new HashSet<QName>();
WebDAVModelHelper.extractPropertyNames(prop, propertyNames);
Assert.assertArrayEquals(propertyNames.toArray(new QName[propertyNames.size()]),
new QName[] {REMOVE_PROPERTY});
// test write
Diff diff = new Diff(input, write(propupdate));
Assert.assertTrue(diff.toString(), diff.similar());
// test runtime creation
propupdate = new Propertyupdate();
// set properties
org.apache.wink.webdav.model.Set set = new org.apache.wink.webdav.model.Set();
prop = new Prop();
set.setProp(prop);
propupdate.getRemoveOrSet().add(set);
element = prop.setProperty(SET_PROPERTY);
Element child1 =
WebDAVModelHelper.createElement(SET_PROPERTY_CHILD, SET_PROPERTY_CHILD_VALUES[0]);
Element child2 =
WebDAVModelHelper.createElement(SET_PROPERTY_CHILD, SET_PROPERTY_CHILD_VALUES[1]);
element.appendChild(child1);
element.appendChild(child2);
// remove properties
Remove remove = new Remove();
prop = new Prop();
prop.setProperty(REMOVE_PROPERTY);
remove.setProp(prop);
propupdate.getRemoveOrSet().add(remove);
diff = new Diff(input, write(propupdate));
Assert.assertTrue(diff.toString(), diff.similar());
}