]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCollectionCastorTest.java
Introduce org.argeo.slc.specs
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / test / java / org / argeo / slc / core / test / tree / TreeTestResultCollectionCastorTest.java
1 package org.argeo.slc.core.test.tree;
2
3 import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createCompleteTreeTestResult;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.slc.unit.AbstractSpringTestCase;
8 import org.argeo.slc.unit.UnitXmlUtils;
9 import org.argeo.slc.unit.test.tree.UnitTestTreeUtil;
10 import org.springframework.oxm.Marshaller;
11 import org.springframework.oxm.Unmarshaller;
12 import org.springframework.xml.transform.StringResult;
13 import org.springframework.xml.transform.StringSource;
14 import org.springframework.xml.validation.XmlValidator;
15
16 public class TreeTestResultCollectionCastorTest extends AbstractSpringTestCase {
17 private Log log = LogFactory.getLog(getClass());
18
19 private Marshaller marshaller;
20 private Unmarshaller unmarshaller;
21
22 @Override
23 public void setUp() {
24 marshaller = getBean(Marshaller.class);
25 unmarshaller = getBean(Unmarshaller.class);
26 }
27
28 public void testMarshUnmarsh() throws Exception {
29 TreeTestResult ttr = createCompleteTreeTestResult();
30 TreeTestResult ttr2 = createCompleteTreeTestResult();
31
32 TreeTestResultCollection ttrc = new TreeTestResultCollection();
33 ttrc.setId("testCollection");
34 ttrc.getResults().add(ttr);
35 ttrc.getResults().add(ttr2);
36
37 StringResult xml = marshallAndValidate(ttrc);
38
39 TreeTestResultCollection ttrcUnm = (TreeTestResultCollection) unmarshaller
40 .unmarshal(new StringSource(xml.toString()));
41
42 assertEquals(ttrc.getId(), ttrcUnm.getId());
43 assertEquals(ttrc.getResults().size(), ttrcUnm.getResults().size());
44 for (TreeTestResult ttrT : ttrc.getResults()) {
45 if (ttrT.getUuid().equals(ttr.getUuid()))
46 UnitTestTreeUtil.assertTreeTestResult(ttr, ttrT);
47 else
48 UnitTestTreeUtil.assertTreeTestResult(ttr2, ttrT);
49 }
50 }
51
52 private StringResult marshallAndValidate(Object obj) throws Exception {
53 StringResult xml = new StringResult();
54 marshaller.marshal(obj, xml);
55
56 log.info("Marshalled ResultPart Request: " + xml);
57
58 UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class),
59 new StringSource(xml.toString()));
60 return xml;
61 }
62 }