]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java
Adapt to new Commons structure
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.castor / src / test / java / org / argeo / slc / castor / SlcExecutionCastorTest.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.castor;
17
18 import java.text.SimpleDateFormat;
19 import java.util.UUID;
20
21 import org.argeo.slc.msg.process.SlcExecutionRequest;
22 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
23 import org.argeo.slc.process.SlcExecution;
24 import org.argeo.slc.process.SlcExecutionStep;
25 import org.argeo.slc.unit.process.SlcExecutionTestUtils;
26 import org.springframework.xml.transform.StringResult;
27
28 public class SlcExecutionCastorTest extends AbstractCastorTestCase {
29 public void testMarshalling() throws Exception {
30 SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();
31
32 SlcExecutionRequest msgSave = new SlcExecutionRequest();
33 msgSave.setSlcExecution(slcExec);
34
35 StringResult msgSaveXml = marshalAndValidate(msgSave);
36
37 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
38 SlcExecutionStep step0 = new SlcExecutionStep();
39 step0.setUuid(UUID.randomUUID().toString());
40 step0.setTimestamp(sdf.parse("2008-04-17 18:21"));
41 step0.setType("LOG");
42 step0.addLog("A log message\nand another line");
43
44 SlcExecutionStep step1 = new SlcExecutionStep();
45 step1.setUuid(UUID.randomUUID().toString());
46 step1.setTimestamp(sdf.parse("2008-04-17 18:25"));
47 step1.setType("LOG");
48 step1.addLog("A nother log message");
49
50 SlcExecutionStepsRequest msgNotif = new SlcExecutionStepsRequest();
51 msgNotif.addStep(step0);
52 msgNotif.addStep(step1);
53 msgNotif.setSlcExecutionUuid(slcExec.getUuid());
54
55 StringResult msgNotifXml = marshalAndValidate(msgNotif);
56
57 SlcExecutionRequest msgSaveUnm = unmarshal(msgSaveXml);
58 assertNotNull(msgSaveUnm);
59 SlcExecutionTestUtils.assertSlcExecution(slcExec, msgSaveUnm
60 .getSlcExecution());
61
62 SlcExecutionStepsRequest msgNotifUnm = unmarshal(msgNotifXml);
63 assertNotNull(msgNotifUnm);
64 assertEquals(slcExec.getUuid(), msgNotifUnm.getSlcExecutionUuid());
65 assertEquals(2, msgNotifUnm.getSteps().size());
66 SlcExecutionTestUtils.assertSlcExecutionStep(step0, msgNotifUnm
67 .getSteps().get(0));
68 SlcExecutionTestUtils.assertSlcExecutionStep(step1, msgNotifUnm
69 .getSteps().get(1));
70
71 SlcExecution slcExecUnm = msgSaveUnm.getSlcExecution();
72 slcExecUnm.getSteps().addAll(msgNotifUnm.getSteps());
73
74 SlcExecutionRequest msgUpdate = new SlcExecutionRequest();
75 msgUpdate.setSlcExecution(slcExecUnm);
76 StringResult msgUpdateXml = marshalAndValidate(msgUpdate);
77
78 SlcExecutionRequest msgUpdateUnm = unmarshal(msgUpdateXml);
79 assertNotNull(msgUpdateUnm);
80 }
81
82 public void testMarshUnmarsh() throws Exception {
83 SlcExecution slcExec = SlcExecutionTestUtils
84 .createSlcExecutionWithRealizedFlows();
85 marshUnmarsh(slcExec, false);
86 }
87 }