From 66a8dc805e2edf46a9d73452d5d9af1d4656eea4 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 8 Dec 2008 14:31:57 +0000 Subject: [PATCH] Introduce ExecutionAnswer ASSIGNED - bug 71: Extend capabilities of web services https://www.argeo.org/bugzilla/show_bug.cgi?id=71 git-svn-id: https://svn.argeo.org/slc/trunk@1954 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../resources/org/argeo/slc/castor/msg.xml | 169 +++++++++--------- .../slc/castor/AbstractCastorTestCase.java | 44 +++++ .../slc/castor/ExecutionAnswerCastorTest.java | 25 +++ .../SlcExecutionCastorTest.java | 62 +------ .../slc/castor/TreeTestResultCastorTest.java | 63 +++++++ .../TreeTestResultCollectionCastorTest.java | 33 ++++ .../core/structure/tree/TreeSPathTest.java | 58 ------ .../test/tree/TreeTestResultCastorTest.java | 96 ---------- .../TreeTestResultCollectionCastorTest.java | 62 ------- .../argeo/slc/castor/applicationContext.xml | 10 +- .../slc/core/process/applicationContext.xml | 11 -- .../slc/core/test/tree/applicationContext.xml | 11 -- 12 files changed, 262 insertions(+), 382 deletions(-) create mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java create mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionAnswerCastorTest.java rename runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/{core/process => castor}/SlcExecutionCastorTest.java (50%) create mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCastorTest.java create mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCollectionCastorTest.java delete mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/structure/tree/TreeSPathTest.java delete mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCastorTest.java delete mode 100644 runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCollectionCastorTest.java delete mode 100644 runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/process/applicationContext.xml delete mode 100644 runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/test/tree/applicationContext.xml diff --git a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/msg.xml b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/msg.xml index fafc89af0..de723df74 100644 --- a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/msg.xml +++ b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/msg.xml @@ -1,99 +1,98 @@ - Message objects XML mapping + Message objects XML mapping - - - - - - + + + + + + - - - - - + + + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + - - - - + + + + + + + + + + \ No newline at end of file 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 new file mode 100644 index 000000000..d558083ec --- /dev/null +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java @@ -0,0 +1,44 @@ +package org.argeo.slc.castor; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.unit.AbstractSpringTestCase; +import org.argeo.slc.unit.UnitXmlUtils; +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.Unmarshaller; +import org.springframework.xml.transform.StringResult; +import org.springframework.xml.transform.StringSource; +import org.springframework.xml.validation.XmlValidator; + +public abstract class AbstractCastorTestCase extends AbstractSpringTestCase { + protected Log log = LogFactory.getLog(getClass()); + + private Marshaller marshaller; + private Unmarshaller unmarshaller; + + @Override + public void setUp() { + marshaller = getBean(Marshaller.class); + unmarshaller = getBean(Unmarshaller.class); + } + + protected StringResult marshalAndValidate(Object obj) 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())); + return xml; + } + + protected T unmarshal(StringResult xml) throws Exception { + return (T) unmarshaller.unmarshal(new StringSource(xml.toString())); + } + + protected T marshUnmarsh(Object obj) throws Exception { + StringResult xml = marshalAndValidate(obj); + return unmarshal(xml); + } +} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionAnswerCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionAnswerCastorTest.java new file mode 100644 index 000000000..a9bc16024 --- /dev/null +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionAnswerCastorTest.java @@ -0,0 +1,25 @@ +package org.argeo.slc.castor; + +import org.argeo.slc.msg.ExecutionAnswer; + +public class ExecutionAnswerCastorTest extends AbstractCastorTestCase { + public void testMarshUnmarshOk() throws Exception { + ExecutionAnswer answer = new ExecutionAnswer(ExecutionAnswer.OK, + "No problem!"); + ExecutionAnswer answerUnm = marshUnmarsh(answer); + assertExecutionAnswer(answer, answerUnm); + } + + public void testMarshUnmarshError() throws Exception { + ExecutionAnswer answer = new ExecutionAnswer(ExecutionAnswer.ERROR, + "Oooops..."); + ExecutionAnswer answerUnm = marshUnmarsh(answer); + assertExecutionAnswer(answer, answerUnm); + } + + public static void assertExecutionAnswer(ExecutionAnswer expected, + ExecutionAnswer reached) { + assertEquals(expected.getStatus(), reached.getStatus()); + assertEquals(expected.getMessage(), reached.getMessage()); + } +} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/process/SlcExecutionCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java similarity index 50% rename from runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/process/SlcExecutionCastorTest.java rename to runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java index 5c70382a6..a8f724f25 100644 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/process/SlcExecutionCastorTest.java +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java @@ -1,47 +1,23 @@ -package org.argeo.slc.core.process; +package org.argeo.slc.castor; -import java.io.IOException; -import java.io.StringReader; import java.text.SimpleDateFormat; import java.util.UUID; -import javax.xml.transform.stream.StreamSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.argeo.slc.msg.process.SlcExecutionRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.process.SlcExecutionStep; -import org.argeo.slc.unit.AbstractSpringTestCase; -import org.argeo.slc.unit.UnitXmlUtils; import org.argeo.slc.unit.process.SlcExecutionTestUtils; -import org.springframework.oxm.Marshaller; -import org.springframework.oxm.Unmarshaller; import org.springframework.xml.transform.StringResult; -import org.springframework.xml.transform.StringSource; -import org.springframework.xml.validation.XmlValidator; - -public class SlcExecutionCastorTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - private Marshaller marshaller; - private Unmarshaller unmarshaller; - - @Override - public void setUp() { - marshaller = getBean(Marshaller.class); - unmarshaller = getBean(Unmarshaller.class); - } +public class SlcExecutionCastorTest extends AbstractCastorTestCase { public void testMarshalling() throws Exception { SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution(); SlcExecutionRequest msgSave = new SlcExecutionRequest(); msgSave.setSlcExecution(slcExec); - String msgSaveXml = marshallAndLog(marshaller, msgSave); + StringResult msgSaveXml = marshalAndValidate(msgSave); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); SlcExecutionStep step0 = new SlcExecutionStep(); @@ -61,15 +37,14 @@ public class SlcExecutionCastorTest extends AbstractSpringTestCase { msgNotif.addStep(step1); msgNotif.setSlcExecutionUuid(slcExec.getUuid()); - String msgNotifXml = marshallAndLog(marshaller, msgNotif); + StringResult msgNotifXml = marshalAndValidate(msgNotif); - SlcExecutionRequest msgSaveUnm = unmarshall(unmarshaller, msgSaveXml); + SlcExecutionRequest msgSaveUnm = unmarshal(msgSaveXml); assertNotNull(msgSaveUnm); SlcExecutionTestUtils.assertSlcExecution(slcExec, msgSaveUnm .getSlcExecution()); - SlcExecutionStepsRequest msgNotifUnm = unmarshall(unmarshaller, - msgNotifXml); + SlcExecutionStepsRequest msgNotifUnm = unmarshal(msgNotifXml); assertNotNull(msgNotifUnm); assertEquals(slcExec.getUuid(), msgNotifUnm.getSlcExecutionUuid()); assertEquals(2, msgNotifUnm.getSteps().size()); @@ -83,30 +58,9 @@ public class SlcExecutionCastorTest extends AbstractSpringTestCase { SlcExecutionRequest msgUpdate = new SlcExecutionRequest(); msgUpdate.setSlcExecution(slcExecUnm); - String msgUpdateXml = marshallAndLog(marshaller, msgUpdate); + StringResult msgUpdateXml = marshalAndValidate(msgUpdate); - SlcExecutionRequest msgUpdateUnm = unmarshall(unmarshaller, - msgUpdateXml); + SlcExecutionRequest msgUpdateUnm = unmarshal(msgUpdateXml); assertNotNull(msgUpdateUnm); } - - private String marshallAndLog(Marshaller marshaller, Object obj) - throws IOException { - StringResult xml = new StringResult(); - marshaller.marshal(obj, xml); - log.info("Marshalled object: " + xml); - - UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class), - new StringSource(xml.toString())); - - return xml.toString(); - } - - private T unmarshall(Unmarshaller unmarshaller, String xml) - throws IOException { - StringReader reader = new StringReader(xml); - Object obj = unmarshaller.unmarshal(new StreamSource(reader)); - IOUtils.closeQuietly(reader); - return (T) obj; - } } diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCastorTest.java new file mode 100644 index 000000000..b43fb9953 --- /dev/null +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCastorTest.java @@ -0,0 +1,63 @@ +package org.argeo.slc.castor; + +import static org.argeo.slc.unit.UnitUtils.assertDateSec; +import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createCompleteTreeTestResult; +import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createSimpleResultPartRequest; + +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest; +import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest; +import org.argeo.slc.msg.test.tree.ResultPartRequest; +import org.argeo.slc.unit.test.tree.UnitTestTreeUtil; +import org.springframework.xml.transform.StringResult; + +public class TreeTestResultCastorTest extends AbstractCastorTestCase { + public void testMarshUnmarsh() throws Exception { + TreeTestResult ttr = createCompleteTreeTestResult(); + + StringResult xml = marshalAndValidate(ttr); + + TreeTestResult ttrUnm = unmarshal(xml); + + UnitTestTreeUtil.assertTreeTestResult(ttr, ttrUnm); + } + + public void testCreateTreeTestResultRequest() throws Exception { + CreateTreeTestResultRequest req = new CreateTreeTestResultRequest(); + req.setTreeTestResult(createCompleteTreeTestResult()); + + StringResult xml = marshalAndValidate(req); + + CreateTreeTestResultRequest reqUnm = unmarshal(xml); + + UnitTestTreeUtil.assertTreeTestResult(req.getTreeTestResult(), reqUnm + .getTreeTestResult()); + } + + public void testResultPartRequest() throws Exception { + TreeTestResult ttr = createCompleteTreeTestResult(); + ResultPartRequest req = createSimpleResultPartRequest(ttr); + + StringResult xml = marshalAndValidate(req); + + ResultPartRequest reqUnm = unmarshal(xml); + + UnitTestTreeUtil + .assertPart(req.getResultPart(), reqUnm.getResultPart()); + } + + public void testCloseTreeTestResultRequest() throws Exception { + TreeTestResult ttr = createCompleteTreeTestResult(); + ttr.close(); + + CloseTreeTestResultRequest req = new CloseTreeTestResultRequest(ttr + .getUuid(), ttr.getCloseDate()); + + StringResult xml = marshalAndValidate(req); + + CloseTreeTestResultRequest reqUnm = unmarshal(xml); + + assertEquals(ttr.getUuid(), reqUnm.getResultUuid()); + assertDateSec(ttr.getCloseDate(), ttr.getCloseDate()); + } +} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCollectionCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCollectionCastorTest.java new file mode 100644 index 000000000..242845a4f --- /dev/null +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/TreeTestResultCollectionCastorTest.java @@ -0,0 +1,33 @@ +package org.argeo.slc.castor; + +import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createCompleteTreeTestResult; + +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.core.test.tree.TreeTestResultCollection; +import org.argeo.slc.unit.test.tree.UnitTestTreeUtil; +import org.springframework.xml.transform.StringResult; + +public class TreeTestResultCollectionCastorTest extends AbstractCastorTestCase { + public void testMarshUnmarsh() throws Exception { + TreeTestResult ttr = createCompleteTreeTestResult(); + TreeTestResult ttr2 = createCompleteTreeTestResult(); + + TreeTestResultCollection ttrc = new TreeTestResultCollection(); + ttrc.setId("testCollection"); + ttrc.getResults().add(ttr); + ttrc.getResults().add(ttr2); + + StringResult xml = marshalAndValidate(ttrc); + + TreeTestResultCollection ttrcUnm = unmarshal(xml); + + assertEquals(ttrc.getId(), ttrcUnm.getId()); + assertEquals(ttrc.getResults().size(), ttrcUnm.getResults().size()); + for (TreeTestResult ttrT : ttrc.getResults()) { + if (ttrT.getUuid().equals(ttr.getUuid())) + UnitTestTreeUtil.assertTreeTestResult(ttr, ttrT); + else + UnitTestTreeUtil.assertTreeTestResult(ttr2, ttrT); + } + } +} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/structure/tree/TreeSPathTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/structure/tree/TreeSPathTest.java deleted file mode 100644 index f24abc580..000000000 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/structure/tree/TreeSPathTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.argeo.slc.core.structure.tree; - -import junit.framework.TestCase; - -public class TreeSPathTest extends TestCase { - - public void testNew() { - TreeSPath path = new TreeSPath("/test"); - assertEquals("test", path.getName()); - assertNull(path.getParent()); - - path = new TreeSPath("/root/subdir"); - assertEquals("subdir", path.getName()); - assertEquals(new TreeSPath("/root"), path.getParent()); - } - - public void testEquals() { - TreeSPath path1 = new TreeSPath("/test"); - TreeSPath path2 = new TreeSPath("/test"); - assertEquals(path1, path2); - - path1 = new TreeSPath("/test/subdir/anotherdir"); - path2 = new TreeSPath("/test/subdir/anotherdir"); - assertEquals(path1, path2); - - path1 = new TreeSPath("/test/subdir/anotherd"); - path2 = new TreeSPath("/test/subdir/anotherdir"); - assertNotSame(path1, path2); - - path1 = new TreeSPath("/test/subdir"); - path2 = new TreeSPath("/test/subdir/anotherdir"); - assertNotSame(path1, path2); - - path1 = new TreeSPath("/test/subd/anotherdir"); - path2 = new TreeSPath("/test/subdir/anotherdir"); - assertNotSame(path1, path2); - } - - public void testCheckFormat() { - try { - new TreeSPath("hello"); - fail("Bad format should be rejected"); - } catch (Exception e) { - // exception expected - } - - try { - new TreeSPath("/"); - fail("Bad format should be rejected"); - } catch (Exception e) { - // exception expected - } - - assertEquals(new TreeSPath("/test"), new TreeSPath("/test/")); - assertEquals(new TreeSPath("/test/dir"), new TreeSPath( - "//test///dir////")); - } -} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCastorTest.java deleted file mode 100644 index baf8e3b7e..000000000 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCastorTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.argeo.slc.core.test.tree; - -import static org.argeo.slc.unit.UnitUtils.assertDateSec; -import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createCompleteTreeTestResult; -import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createSimpleResultPartRequest; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest; -import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest; -import org.argeo.slc.msg.test.tree.ResultPartRequest; -import org.argeo.slc.unit.AbstractSpringTestCase; -import org.argeo.slc.unit.UnitXmlUtils; -import org.argeo.slc.unit.test.tree.UnitTestTreeUtil; -import org.springframework.oxm.Marshaller; -import org.springframework.oxm.Unmarshaller; -import org.springframework.xml.transform.StringResult; -import org.springframework.xml.transform.StringSource; -import org.springframework.xml.validation.XmlValidator; - -public class TreeTestResultCastorTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - private Marshaller marshaller; - private Unmarshaller unmarshaller; - - @Override - public void setUp() { - marshaller = getBean(Marshaller.class); - unmarshaller = getBean(Unmarshaller.class); - } - - public void testMarshUnmarsh() throws Exception { - TreeTestResult ttr = createCompleteTreeTestResult(); - - StringResult xml = marshallAndValidate(ttr); - - TreeTestResult ttrUnm = (TreeTestResult) unmarshaller - .unmarshal(new StringSource(xml.toString())); - - UnitTestTreeUtil.assertTreeTestResult(ttr, ttrUnm); - } - - public void testCreateTreeTestResultRequest() throws Exception { - CreateTreeTestResultRequest req = new CreateTreeTestResultRequest(); - req.setTreeTestResult(createCompleteTreeTestResult()); - - StringResult xml = marshallAndValidate(req); - - CreateTreeTestResultRequest reqUnm = (CreateTreeTestResultRequest) unmarshaller - .unmarshal(new StringSource(xml.toString())); - - UnitTestTreeUtil.assertTreeTestResult(req.getTreeTestResult(), reqUnm - .getTreeTestResult()); - } - - public void testResultPartRequest() throws Exception { - TreeTestResult ttr = createCompleteTreeTestResult(); - ResultPartRequest req = createSimpleResultPartRequest(ttr); - - StringResult xml = marshallAndValidate(req); - - ResultPartRequest reqUnm = (ResultPartRequest) unmarshaller - .unmarshal(new StringSource(xml.toString())); - - UnitTestTreeUtil - .assertPart(req.getResultPart(), reqUnm.getResultPart()); - } - - public void testCloseTreeTestResultRequest() throws Exception { - TreeTestResult ttr = createCompleteTreeTestResult(); - ttr.close(); - - CloseTreeTestResultRequest req = new CloseTreeTestResultRequest(ttr - .getUuid(), ttr.getCloseDate()); - - StringResult xml = marshallAndValidate(req); - - CloseTreeTestResultRequest reqUnm = (CloseTreeTestResultRequest) unmarshaller - .unmarshal(new StringSource(xml.toString())); - - assertEquals(ttr.getUuid(), reqUnm.getResultUuid()); - assertDateSec(ttr.getCloseDate(), ttr.getCloseDate()); - } - - private StringResult marshallAndValidate(Object obj) 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())); - return xml; - } -} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCollectionCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCollectionCastorTest.java deleted file mode 100644 index 29ee30d82..000000000 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/core/test/tree/TreeTestResultCollectionCastorTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.argeo.slc.core.test.tree; - -import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createCompleteTreeTestResult; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.unit.AbstractSpringTestCase; -import org.argeo.slc.unit.UnitXmlUtils; -import org.argeo.slc.unit.test.tree.UnitTestTreeUtil; -import org.springframework.oxm.Marshaller; -import org.springframework.oxm.Unmarshaller; -import org.springframework.xml.transform.StringResult; -import org.springframework.xml.transform.StringSource; -import org.springframework.xml.validation.XmlValidator; - -public class TreeTestResultCollectionCastorTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - private Marshaller marshaller; - private Unmarshaller unmarshaller; - - @Override - public void setUp() { - marshaller = getBean(Marshaller.class); - unmarshaller = getBean(Unmarshaller.class); - } - - public void testMarshUnmarsh() throws Exception { - TreeTestResult ttr = createCompleteTreeTestResult(); - TreeTestResult ttr2 = createCompleteTreeTestResult(); - - TreeTestResultCollection ttrc = new TreeTestResultCollection(); - ttrc.setId("testCollection"); - ttrc.getResults().add(ttr); - ttrc.getResults().add(ttr2); - - StringResult xml = marshallAndValidate(ttrc); - - TreeTestResultCollection ttrcUnm = (TreeTestResultCollection) unmarshaller - .unmarshal(new StringSource(xml.toString())); - - assertEquals(ttrc.getId(), ttrcUnm.getId()); - assertEquals(ttrc.getResults().size(), ttrcUnm.getResults().size()); - for (TreeTestResult ttrT : ttrc.getResults()) { - if (ttrT.getUuid().equals(ttr.getUuid())) - UnitTestTreeUtil.assertTreeTestResult(ttr, ttrT); - else - UnitTestTreeUtil.assertTreeTestResult(ttr2, ttrT); - } - } - - private StringResult marshallAndValidate(Object obj) 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())); - return xml; - } -} diff --git a/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/castor/applicationContext.xml b/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/castor/applicationContext.xml index 7a89af927..9601c3301 100644 --- a/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/castor/applicationContext.xml +++ b/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/castor/applicationContext.xml @@ -1,11 +1,11 @@ + - - + resource="classpath:/org/argeo/slc/castor/spring/applicationContext.xml" /> + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/process/applicationContext.xml b/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/process/applicationContext.xml deleted file mode 100644 index 899daf548..000000000 --- a/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/process/applicationContext.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/test/tree/applicationContext.xml b/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/test/tree/applicationContext.xml deleted file mode 100644 index 9601c3301..000000000 --- a/runtime/org.argeo.slc.support.castor/src/test/resources/org/argeo/slc/core/test/tree/applicationContext.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file -- 2.39.2