2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.unit
.process
;
18 import static junit
.framework
.Assert
.assertEquals
;
19 import static junit
.framework
.Assert
.assertNotNull
;
20 import static org
.argeo
.slc
.unit
.UnitUtils
.assertDateSec
;
22 import java
.util
.ArrayList
;
23 import java
.util
.List
;
24 import java
.util
.UUID
;
26 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
27 import org
.argeo
.slc
.execution
.ExecutionStep
;
28 import org
.argeo
.slc
.execution
.RealizedFlow
;
29 import org
.argeo
.slc
.process
.SlcExecution
;
30 import org
.argeo
.slc
.process
.SlcExecutionStep
;
31 import org
.argeo
.slc
.unit
.execution
.ExecutionFlowDescriptorTestUtils
;
33 public abstract class SlcExecutionTestUtils
{
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");
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
);
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());
70 assertEquals(expected
.getAttributes().size(), reached
.getAttributes()
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
);
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
);
86 // FIXME: compare realized flows
87 // assertEquals(expected.getRealizedFlows().size(), reached
88 // .getRealizedFlows().size());
92 public static void assertSlcExecutionStep(ExecutionStep expected
,
93 ExecutionStep reached
) {
94 assertNotNull(reached
);
95 assertEquals(expected
.getType(), reached
.getType());
96 assertDateSec(expected
.getTimestamp(), reached
.getTimestamp());
97 if (expected
instanceof SlcExecutionStep
) {
98 SlcExecutionStep slcExpected
= (SlcExecutionStep
)expected
;
99 SlcExecutionStep slcReached
= (SlcExecutionStep
)reached
;
100 assertEquals(slcExpected
.getUuid(), slcReached
.getUuid());
101 assertEquals(slcExpected
.getLogLines().size(), slcReached
.getLogLines()
103 for (int i
= 0; i
< slcExpected
.getLogLines().size(); i
++) {
104 assertEquals(slcExpected
.getLogLines().get(i
), slcReached
105 .getLogLines().get(i
));
110 private SlcExecutionTestUtils() {