]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java
b9f18b6ae01bfa454c99ef0cb0cbeb999b57ad7a
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.castor / src / test / java / org / argeo / slc / castor / SlcExecutionCastorTest.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
17 package org.argeo.slc.castor;
18
19 import java.text.SimpleDateFormat;
20 import java.util.UUID;
21
22 import org.argeo.slc.msg.process.SlcExecutionRequest;
23 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
24 import org.argeo.slc.process.SlcExecution;
25 import org.argeo.slc.process.SlcExecutionStep;
26 import org.argeo.slc.unit.process.SlcExecutionTestUtils;
27 import org.springframework.xml.transform.StringResult;
28
29 public class SlcExecutionCastorTest extends AbstractCastorTestCase {
30 public void testMarshalling() throws Exception {
31 SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();
32
33 SlcExecutionRequest msgSave = new SlcExecutionRequest();
34 msgSave.setSlcExecution(slcExec);
35
36 StringResult msgSaveXml = marshalAndValidate(msgSave);
37
38 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
39 SlcExecutionStep step0 = new SlcExecutionStep();
40 step0.setUuid(UUID.randomUUID().toString());
41 step0.setBegin(sdf.parse("2008-04-17 18:21"));
42 step0.setType("LOG");
43 step0.addLog("A log message\nand another line");
44
45 SlcExecutionStep step1 = new SlcExecutionStep();
46 step1.setUuid(UUID.randomUUID().toString());
47 step1.setBegin(sdf.parse("2008-04-17 18:25"));
48 step1.setType("LOG");
49 step1.addLog("A nother log message");
50
51 SlcExecutionStepsRequest msgNotif = new SlcExecutionStepsRequest();
52 msgNotif.addStep(step0);
53 msgNotif.addStep(step1);
54 msgNotif.setSlcExecutionUuid(slcExec.getUuid());
55
56 StringResult msgNotifXml = marshalAndValidate(msgNotif);
57
58 SlcExecutionRequest msgSaveUnm = unmarshal(msgSaveXml);
59 assertNotNull(msgSaveUnm);
60 SlcExecutionTestUtils.assertSlcExecution(slcExec, msgSaveUnm
61 .getSlcExecution());
62
63 SlcExecutionStepsRequest msgNotifUnm = unmarshal(msgNotifXml);
64 assertNotNull(msgNotifUnm);
65 assertEquals(slcExec.getUuid(), msgNotifUnm.getSlcExecutionUuid());
66 assertEquals(2, msgNotifUnm.getSteps().size());
67 SlcExecutionTestUtils.assertSlcExecutionStep(step0, msgNotifUnm
68 .getSteps().get(0));
69 SlcExecutionTestUtils.assertSlcExecutionStep(step1, msgNotifUnm
70 .getSteps().get(1));
71
72 SlcExecution slcExecUnm = msgSaveUnm.getSlcExecution();
73 slcExecUnm.getSteps().addAll(msgNotifUnm.getSteps());
74
75 SlcExecutionRequest msgUpdate = new SlcExecutionRequest();
76 msgUpdate.setSlcExecution(slcExecUnm);
77 StringResult msgUpdateXml = marshalAndValidate(msgUpdate);
78
79 SlcExecutionRequest msgUpdateUnm = unmarshal(msgUpdateXml);
80 assertNotNull(msgUpdateUnm);
81 }
82
83 public void testMarshUnmarsh() throws Exception {
84 SlcExecution slcExec = SlcExecutionTestUtils
85 .createSlcExecutionWithRealizedFlows();
86 marshUnmarsh(slcExec, false);
87 }
88 }