]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java
First working version of SLC Runtime v2
[gpl/argeo-slc.git] / org.argeo.slc.core / ext / test / org / argeo / slc / core / execution / AbstractExecutionFlowTestCase.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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 package org.argeo.slc.core.execution;
17
18 import junit.framework.TestCase;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.argeo.slc.core.test.SimpleTestResult;
23 import org.argeo.slc.execution.ExecutionContext;
24 import org.argeo.slc.execution.ExecutionFlow;
25 import org.argeo.slc.test.TestResultPart;
26 import org.argeo.slc.test.TestStatus;
27 import org.springframework.context.ConfigurableApplicationContext;
28 import org.springframework.context.support.ClassPathXmlApplicationContext;
29
30 public abstract class AbstractExecutionFlowTestCase extends TestCase {
31
32 protected final Log log = LogFactory.getLog(getClass());
33
34 protected void logException(Throwable ex) {
35 log.info("Got Exception of class " + ex.getClass().toString()
36 + " with message '" + ex.getMessage() + "'.");
37 }
38
39 protected void validateTestResult(SimpleTestResult testResult) {
40 validateTestResult(testResult, TestStatus.PASSED);
41 }
42
43 protected void validateTestResult(SimpleTestResult testResult,
44 int expectedStatus) {
45 for (TestResultPart part : testResult.getParts()) {
46 if (part.getStatus() != expectedStatus) {
47 fail("Error found in TestResult: " + part.getMessage());
48 }
49 }
50 }
51
52 protected ConfigurableApplicationContext createApplicationContext(
53 String applicationContextSuffix) {
54 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
55 inPackage(applicationContextSuffix));
56 // applicationContext.start();
57 return applicationContext;
58 }
59
60 protected void configureAndExecuteSlcFlow(String applicationContextSuffix,
61 String beanName) {
62 ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);
63 ExecutionContext executionContext = (ExecutionContext) applicationContext
64 .getBean("executionContext");
65 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext
66 .getBean(beanName);
67 if (executionFlow instanceof DefaultExecutionFlow)
68 ((DefaultExecutionFlow) executionFlow)
69 .setExecutionContext(executionContext);
70 try {
71 executionContext.beforeFlow(executionFlow);
72 executionFlow.run();
73 } finally {
74 executionContext.afterFlow(executionFlow);
75 }
76 applicationContext.close();
77 }
78
79 protected String inPackage(String suffix) {
80 String prefix = getClass().getPackage().getName().replace('.', '/');
81 return prefix + '/' + suffix;
82 }
83 }