]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java
Change in ExecutionParameterPostProcessor to avoid instantiation problem with osgi
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / test / java / org / argeo / slc / core / execution / ExecutionFlowTest.java
1 package org.argeo.slc.core.execution;
2
3 import org.argeo.slc.core.test.SimpleTestResult;
4 import org.argeo.slc.execution.ExecutionFlow;
5 import org.argeo.slc.test.TestStatus;
6 import org.argeo.slc.unit.AbstractSpringTestCase;
7 import org.springframework.beans.factory.BeanCreationException;
8 import org.springframework.context.ConfigurableApplicationContext;
9 import org.springframework.context.support.ClassPathXmlApplicationContext;
10
11 public class ExecutionFlowTest extends AbstractSpringTestCase {
12
13 public void testSimpleExecution() throws Exception {
14 configureAndExecuteSlcFlow("applicationContext.xml", "main");
15 }
16
17 public void testCanonic() throws Exception {
18 // Parameter without default value in specification
19 /* configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
20 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
21
22 try {
23 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
24 fail("Parameter not set - should be rejected.");
25 } catch (BeanCreationException e) {
26 // exception expected
27 logException(e);
28 }*/
29
30 /* try {
31 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
32 fail("Unknown parameter set - should be rejected.");
33 } catch (BeanCreationException e) {
34 // exception expected
35 logException(e);
36 } */
37 }
38
39 /* public void testRecursive() throws Exception {
40 ConfigurableApplicationContext applicationContext = prepareExecution("test.xml");
41 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("first");
42 executionFlow.execute();
43 SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("basicTestResult");
44 if(res.getParts().get(0).getStatus() != TestStatus.PASSED) {
45 fail("Unexpected string returned");
46 }
47 applicationContext.close();
48 }*/
49
50 protected void logException(Throwable ex) {
51 log.info("Got Exception of class " + ex.getClass().toString()
52 + " with message '" + ex.getMessage() + "'.");
53 }
54
55 protected void initExecutionContext() {
56 /* // if an execution context was registered, unregister it
57 if(MapExecutionContext.getCurrent() != null) {
58 MapExecutionContext.unregisterExecutionContext();
59 }
60 // register a new ExecutionContext
61 MapExecutionContext.registerExecutionContext(new MapExecutionContext()); */
62 }
63
64 protected ConfigurableApplicationContext prepareExecution(String applicationContextSuffix) {
65 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));
66 applicationContext.start();
67 initExecutionContext();
68 return applicationContext;
69 }
70
71 protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {
72 ConfigurableApplicationContext applicationContext = prepareExecution(applicationContextSuffix);
73 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);
74 executionFlow.execute();
75 applicationContext.close();
76 }
77 }