]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java
d621d292174b271041e7c0ba8dfa86f5cf1b6985
[gpl/argeo-slc.git] / runtime / org.argeo.slc.unit / src / main / java / org / argeo / slc / unit / process / SlcExecutionTestUtils.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.unit.process;
18
19 import static junit.framework.Assert.assertEquals;
20 import static junit.framework.Assert.assertNotNull;
21 import static org.argeo.slc.unit.UnitUtils.assertDateSec;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.UUID;
26
27 import org.argeo.slc.execution.ExecutionFlowDescriptor;
28 import org.argeo.slc.execution.ExecutionStep;
29 import org.argeo.slc.process.RealizedFlow;
30 import org.argeo.slc.process.SlcExecution;
31 import org.argeo.slc.process.SlcExecutionStep;
32 import org.argeo.slc.unit.execution.ExecutionFlowDescriptorTestUtils;
33
34 public abstract class SlcExecutionTestUtils {
35
36 public static SlcExecution createSimpleSlcExecution() {
37 SlcExecution slcExec = new SlcExecution();
38 slcExec.setUuid(UUID.randomUUID().toString());
39 slcExec.setHost("localhost");
40 slcExec.setUser("user");
41 slcExec.setType("slcAnt");
42 slcExec.setStatus("STARTED");
43 slcExec.getAttributes().put("ant.file", "/test");
44 return slcExec;
45 }
46
47 public static SlcExecution createSlcExecutionWithRealizedFlows() {
48 SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();
49 List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
50 RealizedFlow realizedFlow = new RealizedFlow();
51 ExecutionFlowDescriptor flowDescriptor = ExecutionFlowDescriptorTestUtils
52 .createSimpleExecutionFlowDescriptor();
53 realizedFlow.setModuleName("test.module");
54 realizedFlow.setModuleVersion("1.0.0");
55 realizedFlow.setFlowDescriptor(flowDescriptor);
56 realizedFlow.setExecutionSpec(flowDescriptor.getExecutionSpec());
57 realizedFlows.add(realizedFlow);
58 slcExec.setRealizedFlows(realizedFlows);
59 return slcExec;
60 }
61
62 public static void assertSlcExecution(SlcExecution expected,
63 SlcExecution reached) {
64 assertNotNull(reached);
65 assertEquals(expected.getHost(), reached.getHost());
66 assertEquals(expected.getUser(), reached.getUser());
67 assertEquals(expected.getType(), reached.getType());
68 assertEquals(expected.getStatus(), reached.getStatus());
69
70 // Attributes
71 assertEquals(expected.getAttributes().size(), reached.getAttributes()
72 .size());
73 for (String key : expected.getAttributes().keySet()) {
74 String expectedValue = expected.getAttributes().get(key);
75 String reachedValue = reached.getAttributes().get(key);
76 assertNotNull(reachedValue);
77 assertEquals(expectedValue, reachedValue);
78 }
79
80 assertEquals(expected.getSteps().size(), reached.getSteps().size());
81 for (int i = 0; i < expected.getSteps().size(); i++) {
82 SlcExecutionStep stepExpected = expected.getSteps().get(i);
83 SlcExecutionStep stepReached = reached.getSteps().get(i);
84 assertSlcExecutionStep(stepExpected, stepReached);
85 }
86
87 // FIXME: compare realized flows
88 // assertEquals(expected.getRealizedFlows().size(), reached
89 // .getRealizedFlows().size());
90
91 }
92
93 public static void assertSlcExecutionStep(ExecutionStep expected,
94 ExecutionStep reached) {
95 assertNotNull(reached);
96 assertEquals(expected.getType(), reached.getType());
97 assertDateSec(expected.getTimestamp(), reached.getTimestamp());
98 if (expected instanceof SlcExecutionStep) {
99 SlcExecutionStep slcExpected = (SlcExecutionStep)expected;
100 SlcExecutionStep slcReached = (SlcExecutionStep)reached;
101 assertEquals(slcExpected.getUuid(), slcReached.getUuid());
102 assertEquals(slcExpected.getLogLines().size(), slcReached.getLogLines()
103 .size());
104 for (int i = 0; i < slcExpected.getLogLines().size(); i++) {
105 assertEquals(slcExpected.getLogLines().get(i), slcReached
106 .getLogLines().get(i));
107 }
108 }
109 }
110
111 private SlcExecutionTestUtils() {
112
113 }
114 }