1 package org
.argeo
.slc
.core
.test
.tree
;
3 import static org
.argeo
.slc
.unit
.test
.tree
.TreeTestResultTestUtils
.createCompleteTreeTestResult
;
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
;
16 public class TreeTestResultCollectionCastorTest
extends AbstractSpringTestCase
{
17 private Log log
= LogFactory
.getLog(getClass());
19 private Marshaller marshaller
;
20 private Unmarshaller unmarshaller
;
24 marshaller
= getBean(Marshaller
.class);
25 unmarshaller
= getBean(Unmarshaller
.class);
28 public void testMarshUnmarsh() throws Exception
{
29 TreeTestResult ttr
= createCompleteTreeTestResult();
30 TreeTestResult ttr2
= createCompleteTreeTestResult();
32 TreeTestResultCollection ttrc
= new TreeTestResultCollection();
33 ttrc
.setId("testCollection");
34 ttrc
.getResults().add(ttr
);
35 ttrc
.getResults().add(ttr2
);
37 StringResult xml
= marshallAndValidate(ttrc
);
39 TreeTestResultCollection ttrcUnm
= (TreeTestResultCollection
) unmarshaller
40 .unmarshal(new StringSource(xml
.toString()));
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
);
48 UnitTestTreeUtil
.assertTreeTestResult(ttr2
, ttrT
);
52 private StringResult
marshallAndValidate(Object obj
) throws Exception
{
53 StringResult xml
= new StringResult();
54 marshaller
.marshal(obj
, xml
);
56 log
.info("Marshalled ResultPart Request: " + xml
);
58 UnitXmlUtils
.assertXmlValidation(getBean(XmlValidator
.class),
59 new StringSource(xml
.toString()));