]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java
First draft of DAO implementation for JCR.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.unit / src / main / java / org / argeo / slc / unit / process / SlcExecutionTestUtils.java
1 package org.argeo.slc.unit.process;
2
3 import static junit.framework.Assert.assertEquals;
4 import static junit.framework.Assert.assertNotNull;
5 import static org.argeo.slc.unit.UnitUtils.assertDateSec;
6
7 import java.util.ArrayList;
8 import java.util.List;
9 import java.util.UUID;
10
11 import org.argeo.slc.execution.ExecutionFlowDescriptor;
12 import org.argeo.slc.process.RealizedFlow;
13 import org.argeo.slc.process.SlcExecution;
14 import org.argeo.slc.process.SlcExecutionStep;
15 import org.argeo.slc.unit.execution.ExecutionFlowDescriptorTestUtils;
16
17 public abstract class SlcExecutionTestUtils {
18
19 public static SlcExecution createSimpleSlcExecution() {
20 SlcExecution slcExec = new SlcExecution();
21 slcExec.setUuid(UUID.randomUUID().toString());
22 slcExec.setHost("localhost");
23 slcExec.setUser("user");
24 slcExec.setType("slcAnt");
25 slcExec.setStatus("STARTED");
26 slcExec.getAttributes().put("ant.file", "/test");
27 return slcExec;
28 }
29
30 public static SlcExecution createSlcExecutionWithRealizedFlows() {
31 SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();
32 List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
33 RealizedFlow realizedFlow = new RealizedFlow();
34 ExecutionFlowDescriptor flowDescriptor = ExecutionFlowDescriptorTestUtils
35 .createSimpleExecutionFlowDescriptor();
36 realizedFlow.setModuleName("test.module");
37 realizedFlow.setModuleVersion("1.0.0");
38 realizedFlow.setFlowDescriptor(flowDescriptor);
39 realizedFlow.setExecutionSpec(flowDescriptor.getExecutionSpec());
40 realizedFlows.add(realizedFlow);
41 slcExec.setRealizedFlows(realizedFlows);
42 return slcExec;
43 }
44
45 public static void assertSlcExecution(SlcExecution expected,
46 SlcExecution reached) {
47 assertNotNull(reached);
48 assertEquals(expected.getHost(), reached.getHost());
49 assertEquals(expected.getUser(), reached.getUser());
50 assertEquals(expected.getType(), reached.getType());
51 assertEquals(expected.getStatus(), reached.getStatus());
52
53 // Attributes
54 assertEquals(expected.getAttributes().size(), reached.getAttributes()
55 .size());
56 for (String key : expected.getAttributes().keySet()) {
57 String expectedValue = expected.getAttributes().get(key);
58 String reachedValue = reached.getAttributes().get(key);
59 assertNotNull(reachedValue);
60 assertEquals(expectedValue, reachedValue);
61 }
62
63 assertEquals(expected.getSteps().size(), reached.getSteps().size());
64 for (int i = 0; i < expected.getSteps().size(); i++) {
65 SlcExecutionStep stepExpected = expected.getSteps().get(i);
66 SlcExecutionStep stepReached = reached.getSteps().get(i);
67 assertSlcExecutionStep(stepExpected, stepReached);
68 }
69
70 // FIXME: compare realized flows
71 // assertEquals(expected.getRealizedFlows().size(), reached
72 // .getRealizedFlows().size());
73
74 }
75
76 public static void assertSlcExecutionStep(SlcExecutionStep expected,
77 SlcExecutionStep reached) {
78 assertNotNull(reached);
79 assertEquals(expected.getUuid(), reached.getUuid());
80 assertEquals(expected.getType(), reached.getType());
81 assertDateSec(expected.getBegin(), reached.getBegin());
82 }
83
84 private SlcExecutionTestUtils() {
85
86 }
87 }