X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.castor%2Fsrc%2Ftest%2Fjava%2Forg%2Fargeo%2Fslc%2Fcastor%2FAbstractCastorTestCase.java;h=a2f48c1997a770e38da09938ccec51785269af35;hb=5aa18045bcdd46992b9417f7864fec455e9fc979;hp=d558083ec5b4638b3baaac99fd042145a7e920f3;hpb=66a8dc805e2edf46a9d73452d5d9af1d4656eea4;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java index d558083ec..a2f48c199 100644 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java @@ -22,23 +22,40 @@ public abstract class AbstractCastorTestCase extends AbstractSpringTestCase { unmarshaller = getBean(Unmarshaller.class); } + protected StringResult marshal(Object obj) throws Exception { + return marshal(obj, false); + } + protected StringResult marshalAndValidate(Object obj) throws Exception { + return marshal(obj, true); + } + + protected StringResult marshal(Object obj, boolean validate) + throws Exception { StringResult xml = new StringResult(); marshaller.marshal(obj, xml); log.info("Marshalled ResultPart Request: " + xml); - UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class), - new StringSource(xml.toString())); + if (validate) + UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class), + new StringSource(xml.toString())); return xml; } + @SuppressWarnings("unchecked") protected T unmarshal(StringResult xml) throws Exception { return (T) unmarshaller.unmarshal(new StringSource(xml.toString())); } + @SuppressWarnings("unchecked") + protected T marshUnmarsh(Object obj, boolean validate) throws Exception { + StringResult xml = marshal(obj, validate); + return (T) unmarshal(xml); + } + + @SuppressWarnings("unchecked") protected T marshUnmarsh(Object obj) throws Exception { - StringResult xml = marshalAndValidate(obj); - return unmarshal(xml); + return (T) marshUnmarsh(obj, true); } }