1 package org
.argeo
.slc
.castor
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.slc
.unit
.AbstractSpringTestCase
;
6 import org
.argeo
.slc
.unit
.UnitXmlUtils
;
7 import org
.springframework
.oxm
.Marshaller
;
8 import org
.springframework
.oxm
.Unmarshaller
;
9 import org
.springframework
.xml
.transform
.StringResult
;
10 import org
.springframework
.xml
.transform
.StringSource
;
11 import org
.springframework
.xml
.validation
.XmlValidator
;
13 public abstract class AbstractCastorTestCase
extends AbstractSpringTestCase
{
14 protected Log log
= LogFactory
.getLog(getClass());
16 private Marshaller marshaller
;
17 private Unmarshaller unmarshaller
;
21 marshaller
= getBean(Marshaller
.class);
22 unmarshaller
= getBean(Unmarshaller
.class);
25 protected StringResult
marshal(Object obj
) throws Exception
{
26 return marshal(obj
, false);
29 protected StringResult
marshalAndValidate(Object obj
) throws Exception
{
30 return marshal(obj
, true);
33 protected StringResult
marshal(Object obj
, boolean validate
)
35 StringResult xml
= new StringResult();
36 marshaller
.marshal(obj
, xml
);
38 log
.info("Marshalled ResultPart Request: " + xml
);
41 UnitXmlUtils
.assertXmlValidation(getBean(XmlValidator
.class),
42 new StringSource(xml
.toString()));
46 @SuppressWarnings("unchecked")
47 protected <T
> T
unmarshal(StringResult xml
) throws Exception
{
48 return (T
) unmarshaller
.unmarshal(new StringSource(xml
.toString()));
51 @SuppressWarnings("unchecked")
52 protected <T
> T
marshUnmarsh(Object obj
, boolean validate
) throws Exception
{
53 StringResult xml
= marshal(obj
, validate
);
54 return (T
) unmarshal(xml
);
57 @SuppressWarnings("unchecked")
58 protected <T
> T
marshUnmarsh(Object obj
) throws Exception
{
59 return (T
) marshUnmarsh(obj
, true);