]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.spring/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java
Rename SLC Core into SLC Spring.
[gpl/argeo-slc.git] / org.argeo.slc.spring / ext / test / org / argeo / slc / core / execution / AbstractExecutionFlowTestCase.java
diff --git a/org.argeo.slc.spring/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java b/org.argeo.slc.spring/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java
new file mode 100644 (file)
index 0000000..004605c
--- /dev/null
@@ -0,0 +1,83 @@
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.core.execution;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.test.SimpleTestResult;\r
+import org.argeo.slc.execution.ExecutionContext;\r
+import org.argeo.slc.execution.ExecutionFlow;\r
+import org.argeo.slc.test.TestResultPart;\r
+import org.argeo.slc.test.TestStatus;\r
+import org.springframework.context.ConfigurableApplicationContext;\r
+import org.springframework.context.support.ClassPathXmlApplicationContext;\r
+\r
+public abstract class AbstractExecutionFlowTestCase extends TestCase {\r
+\r
+       protected final Log log = LogFactory.getLog(getClass());\r
+\r
+       protected void logException(Throwable ex) {\r
+               log.info("Got Exception of class " + ex.getClass().toString()\r
+                               + " with message '" + ex.getMessage() + "'.");\r
+       }\r
+\r
+       protected void validateTestResult(SimpleTestResult testResult) {\r
+               validateTestResult(testResult, TestStatus.PASSED);\r
+       }\r
+\r
+       protected void validateTestResult(SimpleTestResult testResult,\r
+                       int expectedStatus) {\r
+               for (TestResultPart part : testResult.getParts()) {\r
+                       if (part.getStatus() != expectedStatus) {\r
+                               fail("Error found in TestResult: " + part.getMessage());\r
+                       }\r
+               }\r
+       }\r
+\r
+       protected ConfigurableApplicationContext createApplicationContext(\r
+                       String applicationContextSuffix) {\r
+               ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(\r
+                               inPackage(applicationContextSuffix));\r
+               // applicationContext.start();\r
+               return applicationContext;\r
+       }\r
+\r
+       protected void configureAndExecuteSlcFlow(String applicationContextSuffix,\r
+                       String beanName) {\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);\r
+               ExecutionContext executionContext = (ExecutionContext) applicationContext\r
+                               .getBean("executionContext");\r
+               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext\r
+                               .getBean(beanName);\r
+               if (executionFlow instanceof DefaultExecutionFlow)\r
+                       ((DefaultExecutionFlow) executionFlow)\r
+                                       .setExecutionContext(executionContext);\r
+               try {\r
+                       executionContext.beforeFlow(executionFlow);\r
+                       executionFlow.run();\r
+               } finally {\r
+                       executionContext.afterFlow(executionFlow);\r
+               }\r
+               applicationContext.close();\r
+       }\r
+\r
+       protected String inPackage(String suffix) {\r
+               String prefix = getClass().getPackage().getName().replace('.', '/');\r
+               return prefix + '/' + suffix;\r
+       }\r
+}\r