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