1 package org.smartcomps.twister.engine.core.definition; 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.util.BeanTester; 9 import org.smartcomps.twister.engine.priv.core.definition.ActivityFactory; 10 import org.smartcomps.twister.engine.priv.core.definition.Wait; 11 import org.smartcomps.twister.engine.priv.core.definition.ProcessFactory; 12 13 import java.util.Date; 14 import java.util.Calendar; 15 16 import com.sun.msv.datatype.xsd.DatatypeFactory; 17 18 public class TestWait extends TestCase { 19 20 public static Wait wait = null; 21 22 private BeanTester beanTester = new BeanTester(new String[] {"Id", "Index"}); 23 private TestProcess testProcess = new TestProcess(); 24 25 protected void setUp() throws Exception { 26 LifecycleManager.getLifecycleManager().createResources(); 27 LifecycleManager.getLifecycleManager().startResources(); 28 29 SchemaExport schemaExport = new SchemaExport(new Configuration().configure()); 30 schemaExport.create(true, true); 31 32 TransactionManager.beginTransaction(); 33 testProcess.testCreate(); 34 } 35 36 protected void tearDown() throws Exception { 37 TransactionManager.commitTransaction(); 38 39 LifecycleManager.getLifecycleManager().stopResources(); 40 LifecycleManager.getLifecycleManager().destroyResources(); 41 } 42 43 public void testCreate() throws Exception { 44 wait = (Wait) ActivityFactory.createActivity(Wait.class, TestProcess.testProcess); 45 beanTester.initializeProperties("testWait", wait); 46 47 TransactionManager.commitTransaction(); 48 TransactionManager.beginTransaction(); 49 50 Wait resultWait = (Wait) ProcessFactory.getByName(TestProcess.testProcess.getName()).getActivity(); 51 assertTrue("Wait attributes values have been changed.", beanTester.testValues("testWait", resultWait)); 52 wait = resultWait; 53 } 54 55 /*** 56 * Creates a wait configured to wait one minute from the execution time. 57 */ 58 public void testCreateOneMn() throws Exception { 59 Calendar nowPlusOne = Calendar.getInstance(); 60 nowPlusOne.add(Calendar.SECOND, 30); 61 String nowPlusOneStr = DatatypeFactory.getTypeByName("dateTime").serializeJavaObject(nowPlusOne, null); 62 wait = (Wait) ActivityFactory.createActivity(Wait.class, TestProcess.testProcess); 63 wait.setDuration(false); 64 wait.setTime(nowPlusOneStr); 65 66 TransactionManager.commitTransaction(); 67 TransactionManager.beginTransaction(); 68 69 Wait resultWait = (Wait) ProcessFactory.getByName(TestProcess.testProcess.getName()).getActivity(); 70 assertEquals("Wait duration has been changed.", false, resultWait.isDuration()); 71 assertEquals("Wait time has been changed.", nowPlusOneStr, resultWait.getTime()); 72 wait = resultWait; 73 } 74 75 }

This page was automatically generated by Maven