1 package org
.argeo
.slc
.core
.test
.tree
;
3 import org
.springframework
.oxm
.Marshaller
;
4 import org
.springframework
.oxm
.Unmarshaller
;
5 import org
.springframework
.xml
.transform
.StringResult
;
6 import org
.springframework
.xml
.transform
.StringSource
;
7 import org
.springframework
.xml
.validation
.XmlValidator
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
12 import static org
.argeo
.slc
.core
.test
.tree
.TreeTestResultTestUtils
.createCompleteTreeTestResult
;
13 import static org
.argeo
.slc
.core
.test
.tree
.TreeTestResultTestUtils
.createSimpleResultPartRequest
;
15 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
16 import org
.argeo
.slc
.core
.test
.SimpleResultPart
;
17 import org
.argeo
.slc
.msg
.test
.tree
.CreateTreeTestResultRequest
;
18 import org
.argeo
.slc
.msg
.test
.tree
.ResultPartRequest
;
19 import org
.argeo
.slc
.unit
.AbstractSpringTestCase
;
20 import org
.argeo
.slc
.unit
.UnitXmlUtils
;
21 import org
.argeo
.slc
.unit
.test
.tree
.UnitTestTreeUtil
;
23 public class TreeTestResultCastorTest
extends AbstractSpringTestCase
{
24 private Log log
= LogFactory
.getLog(getClass());
26 private Marshaller marshaller
;
27 private Unmarshaller unmarshaller
;
31 marshaller
= getBean(Marshaller
.class);
32 unmarshaller
= getBean(Unmarshaller
.class);
35 public void testMarshUnmarsh() throws Exception
{
36 TreeTestResult ttr
= createCompleteTreeTestResult();
38 StringResult xml
= marshallAndValidate(ttr
);
40 TreeTestResult ttrUnm
= (TreeTestResult
) unmarshaller
41 .unmarshal(new StringSource(xml
.toString()));
43 UnitTestTreeUtil
.assertTreeTestResult(ttr
, ttrUnm
);
46 public void testCreateTreeTestResultRequest() throws Exception
{
47 CreateTreeTestResultRequest req
= new CreateTreeTestResultRequest();
48 req
.setTreeTestResult(createCompleteTreeTestResult());
50 StringResult xml
= marshallAndValidate(req
);
52 CreateTreeTestResultRequest reqUnm
= (CreateTreeTestResultRequest
) unmarshaller
53 .unmarshal(new StringSource(xml
.toString()));
55 UnitTestTreeUtil
.assertTreeTestResult(req
.getTreeTestResult(), reqUnm
56 .getTreeTestResult());
59 public void testResultPartRequest() throws Exception
{
60 TreeTestResult ttr
= createCompleteTreeTestResult();
61 ResultPartRequest req
= createSimpleResultPartRequest(ttr
);
63 StringResult xml
= marshallAndValidate(req
);
65 ResultPartRequest reqUnm
= (ResultPartRequest
) unmarshaller
66 .unmarshal(new StringSource(xml
.toString()));
69 .assertPart(req
.getResultPart(), reqUnm
.getResultPart());
72 private StringResult
marshallAndValidate(Object obj
) throws Exception
{
73 StringResult xml
= new StringResult();
74 marshaller
.marshal(obj
, xml
);
76 log
.info("Marshalled ResultPart Request: " + xml
);
78 UnitXmlUtils
.assertXmlValidation(getBean(XmlValidator
.class),
79 new StringSource(xml
.toString()));