]> git.argeo.org Git - gpl/argeo-slc.git/blob - AbstractExecutionFlowTestCase.java
7cc8705f53ec4f4c1a7595e6dcfc1e89869ff4d3
[gpl/argeo-slc.git] / 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.ExecutionFlow;
24 import org.argeo.slc.test.TestResultPart;
25 import org.argeo.slc.test.TestStatus;
26 import org.springframework.context.ConfigurableApplicationContext;
27 import org.springframework.context.support.ClassPathXmlApplicationContext;
28
29 public abstract class AbstractExecutionFlowTestCase extends TestCase {
30
31 protected final Log log = LogFactory.getLog(getClass());
32
33 protected void logException(Throwable ex) {
34 log.info("Got Exception of class " + ex.getClass().toString()
35 + " with message '" + ex.getMessage() + "'.");
36 }
37
38 protected void validateTestResult(SimpleTestResult testResult) {
39 validateTestResult(testResult, TestStatus.PASSED);
40 }
41
42 protected void validateTestResult(SimpleTestResult testResult,
43 int expectedStatus) {
44 for (TestResultPart part : testResult.getParts()) {
45 if (part.getStatus() != expectedStatus) {
46 fail("Error found in TestResult: " + part.getMessage());
47 }
48 }
49 }
50
51 protected ConfigurableApplicationContext createApplicationContext(
52 String applicationContextSuffix) {
53 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
54 inPackage(applicationContextSuffix));
55 // applicationContext.start();
56 return applicationContext;
57 }
58
59 protected void configureAndExecuteSlcFlow(String applicationContextSuffix,
60 String beanName) {
61 ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);
62 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext
63 .getBean(beanName);
64 executionFlow.run();
65 applicationContext.close();
66 }
67
68 protected String inPackage(String suffix) {
69 String prefix = getClass().getPackage().getName().replace('.', '/');
70 return prefix + '/' + suffix;
71 }
72 }