2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.unit
.process
;
19 import static junit
.framework
.Assert
.assertEquals
;
20 import static junit
.framework
.Assert
.assertNotNull
;
21 import static org
.argeo
.slc
.unit
.UnitUtils
.assertDateSec
;
23 import java
.util
.ArrayList
;
24 import java
.util
.List
;
25 import java
.util
.UUID
;
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
;
34 public abstract class SlcExecutionTestUtils
{
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");
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
);
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());
71 assertEquals(expected
.getAttributes().size(), reached
.getAttributes()
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
);
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
);
87 // FIXME: compare realized flows
88 // assertEquals(expected.getRealizedFlows().size(), reached
89 // .getRealizedFlows().size());
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()
104 for (int i
= 0; i
< slcExpected
.getLogLines().size(); i
++) {
105 assertEquals(slcExpected
.getLogLines().get(i
), slcReached
106 .getLogLines().get(i
));
111 private SlcExecutionTestUtils() {