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.TestSwitch; 10 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContextFactory; 11 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory; 12 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance; 13 import org.smartcomps.twister.engine.priv.core.dynamic.SwitchEC; 14 import org.smartcomps.twister.engine.priv.core.dynamic.impl.SwitchECImpl; 15 import org.smartcomps.twister.engine.priv.messaging.impl.DefaultMessageBrokerImpl; 16 import org.smartcomps.twister.engine.TwisterEngineFactory; 17 import org.smartcomps.twister.deployer.TwisterDeployer; 18 import org.smartcomps.twister.deployer.TwisterDeployerFactory; 19 import org.dom4j.Document; 20 import org.dom4j.DocumentHelper; 21 22 /*** 23 * Testing the Switch execution context. 24 */ 25 public class TestSwitchEC extends TestCase { 26 27 private TwisterDeployer deployer; 28 29 private TestProcess testProcess = new TestProcess(); 30 private TestSwitch testSwitch = new TestSwitch(); 31 32 protected void setUp() throws Exception { 33 LifecycleManager.getLifecycleManager().createResources(); 34 LifecycleManager.getLifecycleManager().startResources(); 35 36 SchemaExport schemaExport = new SchemaExport(new Configuration().configure()); 37 schemaExport.create(true, true); 38 39 deployer = TwisterDeployerFactory.getTwisterDeployer(); 40 } 41 42 protected void tearDown() throws Exception { 43 LifecycleManager.getLifecycleManager().stopResources(); 44 LifecycleManager.getLifecycleManager().destroyResources(); 45 } 46 47 public void testExecuteNoOtherwise() throws Exception { 48 TransactionManager.beginTransaction(); 49 testProcess.testCreate(); 50 51 testSwitch.testCreateNoOtherwise(); 52 TransactionManager.commitTransaction(); 53 TransactionManager.beginTransaction(); 54 55 ProcessInstance pi = ProcessInstanceFactory.createProcessInstance(TestSwitch.testSwitch.getProcess(), null, null); 56 SwitchEC switchEC = (SwitchEC) ExecutionContextFactory.createExecutionContext(TestSwitch.testSwitch, pi); 57 switchEC.execute(); 58 59 assertEquals("The Switch executed the wrong activity.", 1, ((SwitchECImpl)switchEC).getExecutedActivityIndex()); 60 TransactionManager.commitTransaction(); 61 } 62 63 public void testExecuteWithOtherwise() throws Exception { 64 TransactionManager.beginTransaction(); 65 testProcess.testCreate(); 66 67 testSwitch.testCreateWithOtherwise(); 68 TransactionManager.commitTransaction(); 69 TransactionManager.beginTransaction(); 70 71 ProcessInstance pi = ProcessInstanceFactory.createProcessInstance(TestSwitch.testSwitch.getProcess(), null, null); 72 SwitchEC switchEC = (SwitchEC) ExecutionContextFactory.createExecutionContext(TestSwitch.testSwitch, pi); 73 switchEC.execute(); 74 75 assertEquals("The Switch executed the wrong activity.", 2, ((SwitchECImpl)switchEC).getExecutedActivityIndex()); 76 TransactionManager.commitTransaction(); 77 } 78 79 public void testWithDescription() throws Exception { 80 deployer.deploy(getClass().getClassLoader().getResource("test-switch.xml")); 81 82 // Testing otherwise 83 Document doc = DocumentHelper.createDocument(); 84 doc.addElement("message").addElement("main").addElement("value").setText("6"); 85 int result = TwisterEngineFactory.getEngine().acknowledge("switchPartner", "switchPort", "switchOp", doc); 86 assertEquals("A problem occured when the message as been sent", 0, result); 87 88 Thread.sleep(10000); 89 90 Document receivedDoc = DefaultMessageBrokerImpl.getMessage("smallPartner", "smallPort", "smallOp"); 91 assertNotNull("Document received ", receivedDoc); 92 93 // Testing first condition 94 doc = DocumentHelper.createDocument(); 95 doc.addElement("message").addElement("main").addElement("value").setText("54"); 96 result = TwisterEngineFactory.getEngine().acknowledge("switchPartner", "switchPort", "switchOp", doc); 97 assertEquals("A problem occured when the message as been sent", 0, result); 98 99 Thread.sleep(10000); 100 101 receivedDoc = DefaultMessageBrokerImpl.getMessage("bigPartner", "bigPort", "bigOp"); 102 assertNotNull("Document received ", receivedDoc); 103 104 // Testing second condition 105 doc = DocumentHelper.createDocument(); 106 doc.addElement("message").addElement("main").addElement("value").setText("291"); 107 result = TwisterEngineFactory.getEngine().acknowledge("switchPartner", "switchPort", "switchOp", doc); 108 assertEquals("A problem occured when the message as been sent", 0, result); 109 110 Thread.sleep(10000); 111 112 receivedDoc = DefaultMessageBrokerImpl.getMessage("hugePartner", "hugePort", "hugeOp"); 113 assertNotNull("Document received ", receivedDoc); 114 115 } 116 }

This page was automatically generated by Maven