String input = loadStreamToString(getClass().getResourceAsStream("status1.xml"));
Multistatus multistatus = read(input);
List<Response> responses = multistatus.getResponse();
Assert.assertEquals(multistatus.getResponsedescription(), RESP1_DESC);
Assert.assertEquals(responses.size(), 1); // one response
Response response = responses.get(0);
Assert.assertNotNull(response);
List<Propstat> propstats = response.getPropstat();
Assert.assertEquals(propstats.size(), 2);
Propstat propstat = propstats.get(0);
Assert.assertEquals(propstat.getStatusCode(), 200);
Prop prop = propstat.getProp();
Element element = prop.getAnyByName(RESP1_PROPS[0]);
Assert.assertNotNull(element);
Assert.assertEquals(element.getLocalName(), RESP1_PROPS[0].getLocalPart());
Assert.assertEquals(element.getNamespaceURI(), RESP1_PROPS[0].getNamespaceURI());
element = prop.getAnyByName(RESP1_PROPS[1]);
Assert.assertNotNull(element);
Assert.assertEquals(element.getLocalName(), RESP1_PROPS[1].getLocalPart());
Assert.assertEquals(element.getNamespaceURI(), RESP1_PROPS[1].getNamespaceURI());
propstat = propstats.get(1);
Assert.assertEquals(propstat.getStatusCode(), 403);
Assert.assertEquals(propstat.getResponsedescription(), RESP1_PROPS_DESC);
prop = propstat.getProp();
element = prop.getAnyByName(RESP1_PROPS[2]);
Assert.assertNotNull(element);
Assert.assertEquals(element.getLocalName(), RESP1_PROPS[2].getLocalPart());
Assert.assertEquals(element.getNamespaceURI(), RESP1_PROPS[2].getNamespaceURI());
element = prop.getAnyByName(RESP1_PROPS[3]);
Assert.assertNotNull(element);
Assert.assertEquals(element.getLocalName(), RESP1_PROPS[3].getLocalPart());
Assert.assertEquals(element.getNamespaceURI(), RESP1_PROPS[3].getNamespaceURI());
// test write
String write = write(multistatus);
Diff diff = new Diff(input, write);
Assert.assertTrue(diff.toString(), diff.similar());
// test runtime creation
multistatus = new Multistatus();
multistatus.setResponsedescription(RESP1_DESC);
response = new Response(RESP1_HREF);
multistatus.getResponse().add(response);
propstat = response.getOrCreatePropstat(200, null, null);
prop = propstat.getProp();
prop.setProperty(RESP1_PROPS[0], WebDAVModelHelper.createElement(NS1,
"R:BoxType",
"Box type A"));
prop.setProperty(RESP1_PROPS[1], WebDAVModelHelper.createElement(NS1,
"R:Name",
"J.J. Johnson"));
propstat = response.getOrCreatePropstat(403, RESP1_PROPS_DESC, null);
prop = propstat.getProp();
prop.setProperty(RESP1_PROPS[2]);
prop.setProperty(RESP1_PROPS[3]);
write = write(multistatus);