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=1cdd7be8fb3feaefb47d986f097a956b267cf611;hb=af874b12bcb864e1ee2b48e8d6e1fea3a584c53d;hp=b9dd33638b604a66c4ba1f202c7d56e925317cb7;hpb=cb0f78c49776106e6c1d6fd7990a352e46063442;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 b9dd33638..1cdd7be8f 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,14 +22,24 @@ 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); + log.info("Marshalled " + obj.getClass() + ": " + xml + "\n"); - UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class), - new StringSource(xml.toString())); + if (validate) + UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class), + new StringSource(xml.toString())); return xml; } @@ -38,9 +48,14 @@ public abstract class AbstractCastorTestCase extends AbstractSpringTestCase { 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 (T)unmarshal(xml); + return (T) marshUnmarsh(obj, true); } }