1 package org.smartcomps.twister.engine.core.dynamic;
2
3 import junit.framework.TestCase;
4 import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
5 import net.sf.hibernate.cfg.Configuration;
6 import org.smartcomps.twister.common.transaction.TransactionManager;
7 import org.smartcomps.twister.common.lifecycle.LifecycleManager;
8 import org.smartcomps.twister.engine.core.definition.TestProcess;
9 import org.smartcomps.twister.engine.core.definition.TestTerminate;
10 import org.smartcomps.twister.engine.priv.core.definition.Terminate;
11 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance;
12 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext;
13 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory;
14 import org.smartcomps.twister.engine.priv.core.dynamic.SequenceEC;
15 import org.smartcomps.twister.engine.priv.core.dynamic.TerminateEC;
16
17 import java.util.Map;
18 import java.util.HashMap;
19
20 /***
21 * Tests sequence execution
22 */
23 public class TestTerminateEC extends TestCase {
24
25 private TestProcess testProcess = new TestProcess();
26 private TestTerminate testTerminate = new TestTerminate();
27
28 protected void setUp() throws Exception {
29 LifecycleManager.getLifecycleManager().createResources();
30 LifecycleManager.getLifecycleManager().startResources();
31
32 SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
33 schemaExport.create(true, true);
34
35 TransactionManager.beginTransaction();
36 testProcess.testCreateWithCorrelation();
37 testTerminate.testCreate();
38 TransactionManager.commitTransaction();
39 TransactionManager.beginTransaction();
40
41 }
42
43 protected void tearDown() throws Exception {
44 TransactionManager.commitTransaction();
45
46 LifecycleManager.getLifecycleManager().stopResources();
47 LifecycleManager.getLifecycleManager().destroyResources();
48 }
49
50 public void testExecute() throws Exception {
51 Map corrProp = new HashMap();
52 corrProp.put(TestProcess.CORRELATION_PROP1, "2578");
53 corrProp.put(TestProcess.CORRELATION_PROP2, "12");
54
55 ((Terminate)TestTerminate.testSequence.getActivities().get(0)).execute(TestProcess.CORRELATION_NAME, corrProp);
56
57 TransactionManager.commitTransaction();
58 TransactionManager.beginTransaction();
59
60 try {
61 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp);
62 assertEquals("Process is not canceled after execution ended", ProcessInstance.CANCELED, createdInstance.getStatus());
63 assertTrue("Instance child execution context is not a sequence", createdInstance.getChildExecutionContext() instanceof SequenceEC);
64 assertEquals("Sequence is not canceled after execution ended", ExecutionContext.ENDED_CANCELED, createdInstance.getChildExecutionContext().getStatus());
65
66 assertTrue("Sequence first child execution context is not a terminate", ((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(0) instanceof TerminateEC);
67 assertEquals("First terminate is not canceled after execution ended", ExecutionContext.ENDED_CANCELED, ((TerminateEC)((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(0)).getStatus());
68 } catch (Exception e) {
69 e.printStackTrace();
70 }
71 }
72
73 }
This page was automatically generated by Maven