]> 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
Added InstantiationManager
[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.beans.factory.config.BeanDefinition;
9 import org.springframework.context.ConfigurableApplicationContext;
10 import org.springframework.context.support.ClassPathXmlApplicationContext;
11
12 public class ExecutionFlowTest extends AbstractSpringTestCase {
13
14 public void testSimpleExecution() throws Exception {
15 // prepareExecution("applicationContext.xml");
16 configureAndExecuteSlcFlow("applicationContext.xml", "main_2");
17
18 // ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage("applicationContext.xml"));
19 // String[] beanNames = applicationContext.getBeanDefinitionNames();
20 // for(String beanName : beanNames) {
21 // log.info("beanName='" + beanName + "'");
22 //// if(beanName.equals("main_temp")) {
23 // BeanDefinition beanDef = applicationContext.getBeanFactory().getBeanDefinition(beanName);
24 // String scope = beanDef.getScope();
25 // String[] attrs = beanDef.();
26 // log.info("scope=" + scope + ", nbAttr=" + attrs.length);
27 // for(String attr : attrs) {
28 // log.info(attr + "=" + beanDef.getAttribute(attr));
29 // }
30 //// }
31 // }
32
33 }
34
35 public void testCanonic() throws Exception {
36 // Parameter without default value in specification
37 // configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
38 // configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
39 //
40 // try {
41 // prepareExecution("canonic-003.error.xml");
42 // fail("Parameter not set - should be rejected.");
43 // } catch (BeanCreationException e) {
44 // // exception expected
45 // logException(e);
46 // }
47
48 /* try {
49 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
50 fail("Unknown parameter set - should be rejected.");
51 } catch (BeanCreationException e) {
52 // exception expected
53 logException(e);
54 } */
55 }
56
57 public void testRecursive() throws Exception {
58 // ConfigurableApplicationContext applicationContext = prepareExecution("test.xml");
59 // ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("first");
60 // executionFlow.execute();
61 // SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("basicTestResult");
62 // if(res.getParts().get(0).getStatus() != TestStatus.PASSED) {
63 // fail("Unexpected string returned");
64 // }
65 // applicationContext.close();
66 }
67
68 public void testCreateRef() throws Exception {
69 // configureAndExecuteSlcFlow("createRef.xml", "basic.001");
70 }
71
72 protected void logException(Throwable ex) {
73 log.info("Got Exception of class " + ex.getClass().toString()
74 + " with message '" + ex.getMessage() + "'.");
75 }
76
77 protected void initExecutionContext() {
78 /* // if an execution context was registered, unregister it
79 if(MapExecutionContext.getCurrent() != null) {
80 MapExecutionContext.unregisterExecutionContext();
81 }
82 // register a new ExecutionContext
83 MapExecutionContext.registerExecutionContext(new MapExecutionContext()); */
84 }
85
86 protected ConfigurableApplicationContext prepareExecution(String applicationContextSuffix) {
87 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));
88 applicationContext.start();
89 initExecutionContext();
90 return applicationContext;
91 }
92
93 protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {
94 ConfigurableApplicationContext applicationContext = prepareExecution(applicationContextSuffix);
95 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);
96 executionFlow.execute();
97 applicationContext.close();
98 }
99 }