[jbpm-commits] JBoss JBPM SVN: r3633 - in jbpm3/trunk/modules: enterprise/scripts and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 13 13:03:40 EST 2009


Author: alex.guizar at jboss.com
Date: 2009-01-13 13:03:40 -0500 (Tue, 13 Jan 2009)
New Revision: 3633

Modified:
   jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
   jbpm3/trunk/modules/enterprise/scripts/antrun-test-jars.xml
   jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/ejb-jar.xml
   jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/jboss.xml
   jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
   jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
   jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
   jbpm3/trunk/modules/enterprise/src/test/resources/enterprise/WEB-INF/jboss-web.xml
Log:
eliminate code redundancies in JtaDbPersistenceTest
fix jndi names of jbpm beans
minor edits to other enterprise tests

Modified: jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml	2009-01-13 18:03:40 UTC (rev 3633)
@@ -6,7 +6,6 @@
     <!-- JTA transaction properties (begin) ===
     <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
     <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
-    <property name="jta.UserTransaction">UserTransaction</property>
     ==== JTA transaction properties (end) -->
 
     <!-- CMT transaction properties (begin) ===

Modified: jbpm3/trunk/modules/enterprise/scripts/antrun-test-jars.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/scripts/antrun-test-jars.xml	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/scripts/antrun-test-jars.xml	2009-01-13 18:03:40 UTC (rev 3633)
@@ -34,7 +34,7 @@
         <include name="org/jbpm/enterprise/config/AppServerConfigurationsTest.class"/>
         <include name="org/jbpm/enterprise/ejbtimer/EjbSchedulerTest*.class"/>
         <include name="org/jbpm/enterprise/jms/JmsMessageTest*.class"/>
-        <include name="org/jbpm/enterprise/jta/JtaDbPersistenceTest.class"/>
+        <include name="org/jbpm/enterprise/jta/JtaDbPersistenceTest*.class"/>
       </classes>
       <lib dir="${tests.output.dir}/test-dependencies">
         <include name="aspectjrt*.jar"/>

Modified: jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/ejb-jar.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/ejb-jar.xml	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/ejb-jar.xml	2009-01-13 18:03:40 UTC (rev 3633)
@@ -12,7 +12,7 @@
 
     <session>
       <description>Executes commands in a separate context.</description>
-      <display-name>jBPM Command Service Session Bean</display-name>
+      <display-name>jBPM Command Service</display-name>
       <ejb-name>CommandServiceBean</ejb-name>
       <home>org.jbpm.ejb.RemoteCommandServiceHome</home>
       <remote>org.jbpm.ejb.RemoteCommandService</remote>
@@ -36,8 +36,8 @@
 
       <ejb-local-ref>
         <description>
-          Link to the local entity bean that implements the scheduler service. Required for
-          processes that contain timers.
+          Link to the local entity bean that implements the scheduler service.
+          Required for that contain timers.
         </description>
         <ejb-ref-name>ejb/TimerEntityBean</ejb-ref-name>
         <ejb-ref-type>Entity</ejb-ref-type>
@@ -49,8 +49,8 @@
       <!-- Timer service bean ==>
       <ejb-local-ref>
         <description>
-          Link to the local session bean that implements the scheduler service. Deprecated, replaced
-          by the LocalTimerEntityBean.
+          Link to the local session bean that implements the scheduler service.
+          Deprecated, replaced by LocalTimerEntityBean.
         </description>
         <ejb-ref-name>ejb/LocalTimerServiceBean</ejb-ref-name>
         <ejb-ref-type>Session</ejb-ref-type>
@@ -62,8 +62,8 @@
 
       <resource-ref>
         <description>
-          Logical name of the data source that provides connections to the persistence service. Must
-          match the hibernate.connection.datasource property in the Hibernate configuration file.
+          Logical name of the data source that provides connections to the persistence service.
+          Must match the hibernate.connection.datasource property.
         </description>
         <res-ref-name>jdbc/JbpmDataSource</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
@@ -72,8 +72,8 @@
 
       <resource-ref>
         <description>
-          Logical name of the factory that provides JMS connections to the message service. Required
-          for processes that contain asynchronous continuations.
+          Logical name of the factory that provides JMS connections to the message service.
+          Required for processes that contain asynchronous continuations.
         </description>
         <res-ref-name>jms/JbpmConnectionFactory</res-ref-name>
         <res-type>javax.jms.ConnnectionFactory</res-type>
@@ -112,7 +112,7 @@
         Interacts with the EJB timer service to schedule jBPM timers. Deprecated, replaced by the
         TimerEntityBean.
       </description>
-      <display-name>jBPM Timer Service Session Bean</display-name>
+      <display-name>jBPM Timer Service</display-name>
       <ejb-name>TimerServiceBean</ejb-name>
       <local-home>org.jbpm.scheduler.ejbtimer.LocalTimerServiceHome</local-home>
       <local>org.jbpm.scheduler.ejbtimer.LocalTimerService</local>
@@ -137,7 +137,7 @@
       <description>
         Listens for serialized commands and routes them to the command service session bean.
       </description>
-      <display-name>jBPM Command Listener Message Driven Bean</display-name>
+      <display-name>jBPM Command Listener</display-name>
       <ejb-name>CommandListenerBean</ejb-name>
       <ejb-class>org.jbpm.ejb.impl.CommandListenerBean</ejb-class>
       <transaction-type>Container</transaction-type>
@@ -167,8 +167,8 @@
 
       <message-destination-ref>
         <description>
-          Messages that do not contain a command are sent to the queue referenced here. Optional;
-          if absent, such messages are rejected, which may cause the container to redeliver.
+          Messages that do not contain a command are sent to the queue referenced here.
+          If absent, said messages are rejected, which may cause the container to redeliver.
         </description>
         <message-destination-ref-name>jms/DeadLetterQueue</message-destination-ref-name>
         <message-destination-type>javax.jms.Queue</message-destination-type>
@@ -181,7 +181,7 @@
         Listens for job references and delegates execution of the referenced Job to the command
         service session bean.
       </description>
-      <display-name>jBPM Job Listener Message Driven Bean</display-name>
+      <display-name>jBPM Job Listener</display-name>
       <ejb-name>JobListenerBean</ejb-name>
       <ejb-class>org.jbpm.ejb.impl.JobListenerBean</ejb-class>
       <transaction-type>Container</transaction-type>
@@ -222,7 +222,7 @@
 
     <entity>
       <description>Interacts with the EJB timer service to schedule jBPM timers.</description>
-      <display-name>jBPM Timer Entity Bean</display-name>
+      <display-name>jBPM Timer</display-name>
       <ejb-name>TimerEntityBean</ejb-name>
       <home>org.jbpm.ejb.TimerEntityHome</home>
       <remote>org.jbpm.ejb.TimerEntity</remote>

Modified: jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/jboss.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/jboss.xml	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/src/main/resources/META-INF/jboss.xml	2009-01-13 18:03:40 UTC (rev 3633)
@@ -9,11 +9,11 @@
 
     <session>
       <ejb-name>CommandServiceBean</ejb-name>
-      <jndi-name>ejb/CommandServiceBean</jndi-name>
-      <local-jndi-name>java:ejb/CommandServiceBean</local-jndi-name>
+      <jndi-name>jbpm/CommandServiceBean</jndi-name>
+      <local-jndi-name>java:jbpm/CommandServiceBean</local-jndi-name>
       <resource-ref>
         <res-ref-name>jdbc/JbpmDataSource</res-ref-name>
-        <jndi-name>java:/JbpmDS</jndi-name>
+        <jndi-name>java:JbpmDS</jndi-name>
       </resource-ref>
       <resource-ref>
         <res-ref-name>jms/JbpmConnectionFactory</res-ref-name>
@@ -47,8 +47,8 @@
 
     <entity>
       <ejb-name>TimerEntityBean</ejb-name>
-      <jndi-name>ejb/TimerEntityBean</jndi-name>
-      <local-jndi-name>java:ejb/TimerEntityBean</local-jndi-name>
+      <jndi-name>jbpm/TimerEntityBean</jndi-name>
+      <local-jndi-name>java:jbpm/TimerEntityBean</local-jndi-name>
     </entity>
 
   </enterprise-beans>

Modified: jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java	2009-01-13 18:03:40 UTC (rev 3633)
@@ -67,7 +67,8 @@
     if (commandServiceHome == null) {
       Context initialContext = new InitialContext();
       try {
-        commandServiceHome = (LocalCommandServiceHome) initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
+        commandServiceHome = (LocalCommandServiceHome) initialContext
+            .lookup("java:comp/env/ejb/CommandServiceBean");
       }
       finally {
         initialContext.close();
@@ -206,10 +207,9 @@
         + "  <end-state name='end' />"
         + "</process-definition>");
     long processId = launchProcess("sequence").getId();
-    char state = 'b';
-    for (int i = 0; i < 4; i++) {
+    for (char state = 'b'; state <= 'e'; state++) {
       EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
-      assertEquals(Character.toString(state++), getProcessState(processId));
+      assertEquals(Character.toString(state), getProcessState(processId));
     }
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     assertTrue(isProcessFinished(processId));
@@ -266,14 +266,13 @@
 
   private ProcessInstance launchProcess(String processName) throws RemoteException {
     StartProcessInstanceCommand command = new StartProcessInstanceCommand();
-    command.setProcessName(processName);
+    command.setProcessDefinitionName(processName);
     command.setVariables(Collections.singletonMap("eventCallback", new EventCallback()));
     return (ProcessInstance) commandService.execute(command);
   }
 
   private void signalProcess(final long processId) throws RemoteException {
     commandService.execute(new Command() {
-
       private static final long serialVersionUID = 1L;
 
       public Object execute(JbpmContext jbpmContext) throws Exception {
@@ -285,7 +284,6 @@
 
   private String getProcessState(final long processId) throws RemoteException {
     return (String) commandService.execute(new Command() {
-
       private static final long serialVersionUID = 1L;
 
       public Object execute(JbpmContext jbpmContext) throws Exception {
@@ -296,7 +294,6 @@
 
   private boolean isProcessFinished(final long processId) throws RemoteException {
     Boolean isFinished = (Boolean) commandService.execute(new Command() {
-
       private static final long serialVersionUID = 1L;
 
       public Object execute(JbpmContext jbpmContext) throws Exception {
@@ -308,7 +305,6 @@
 
   private void cancelTimer(final String timerName, final long tokenId) throws RemoteException {
     commandService.execute(new Command() {
-
       private static final long serialVersionUID = 1L;
 
       public Object execute(JbpmContext jbpmContext) throws Exception {

Modified: jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java	2009-01-13 18:03:40 UTC (rev 3633)
@@ -52,33 +52,28 @@
  * 
  * @author Alejandro Guizar
  */
-public class JmsMessageTest extends ServletTestCase 
-{
-  private static Log log = LogFactory.getLog(JmsMessageTest.class);
-  
-  private LocalCommandService commandService;
+public class JmsMessageTest extends ServletTestCase {
 
+  private LocalCommandService commandService;
   private static LocalCommandServiceHome commandServiceHome;
 
-  static final int processExecutionCount = 5;
-  static final int maxWaitTime = 10 * 1000;
+  private static final int processExecutionCount = 5;
+  private static final int maxWaitTime = 10 * 1000;
 
-  public static Test suite() throws Exception
-  {
+  private static final Log log = LogFactory.getLog(JmsMessageTest.class);
+
+  public static Test suite() throws Exception {
     return new IntegrationTestSetup(JmsMessageTest.class, "enterprise-test.war");
   }
 
-  protected void setUp() throws Exception
-  {
-    if (commandServiceHome == null)
-    {
+  protected void setUp() throws Exception {
+    if (commandServiceHome == null) {
       Context initialContext = new InitialContext();
-      try
-      {
-        commandServiceHome = (LocalCommandServiceHome)initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
+      try {
+        commandServiceHome = (LocalCommandServiceHome) initialContext
+            .lookup("java:comp/env/ejb/CommandServiceBean");
       }
-      finally
-      {
+      finally {
         initialContext.close();
       }
     }
@@ -86,15 +81,13 @@
     log.info("### " + getName() + " started ###");
   }
 
-  protected void tearDown() throws Exception
-  {
+  protected void tearDown() throws Exception {
     log.info("### " + getName() + " done ###");
     commandService = null;
     EventCallback.clear();
   }
 
-  public void testAsyncNode() 
-  {
+  public void testAsyncNode() {
     deployProcess("<process-definition name='node'>"
         + "  <event type='process-end'>"
         + "    <action expression='#{eventCallback.processEnd}'/>"
@@ -107,14 +100,13 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
-    
+
     long processId = launchProcess("node").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  public void testAsyncAction() 
-  {
+  public void testAsyncAction() {
     deployProcess("<process-definition name='action'>"
         + "  <start-state name='start'>"
         + "    <transition to='a' />"
@@ -132,7 +124,7 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
-    
+
     long processId = launchProcess("action").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
     EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
@@ -140,8 +132,7 @@
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  public void testAsyncSequence() 
-  {
+  public void testAsyncSequence() {
     deployProcess("<process-definition name='sequence'>"
         + "  <event type='process-end'>"
         + "    <action expression='#{eventCallback.processEnd}'/>"
@@ -166,17 +157,15 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
-    
+
     long processId = launchProcess("sequence").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  public void testAsyncFork() throws Exception 
-  {
+  public void testAsyncFork() throws Exception {
     // [JBPM-1811] JmsMessageTest fails intermittently on HSQLDB
-    if (getHibernateDialect().indexOf("HSQL") != -1) 
-    {
+    if (getHibernateDialect().indexOf("HSQL") != -1) {
       return;
     }
 
@@ -214,29 +203,26 @@
         + "  </join>"
         + "  <end-state name='end' />"
         + "</process-definition>");
-    
+
     long processId = launchProcess("fork").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     Thread.sleep(1000);
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  private String getHibernateDialect()
-  {
-    return (String)commandService.execute(new Command()
-    {
+  private String getHibernateDialect() {
+    return (String) commandService.execute(new Command() {
       private static final long serialVersionUID = 1L;
 
-      public Object execute(JbpmContext jbpmContext) throws Exception
-      {
-        DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory)jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+      public Object execute(JbpmContext jbpmContext) throws Exception {
+        DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory) jbpmContext
+            .getServiceFactory(Services.SERVICENAME_PERSISTENCE);
         return factory.getConfiguration().getProperty(Environment.DIALECT);
       }
     });
   }
 
-  public void testAsyncExecutions() 
-  {
+  public void testAsyncExecutions() {
     deployProcess("<process-definition name='execution'>"
         + "  <event type='process-end'>"
         + "    <action expression='#{eventCallback.processEnd}' />"
@@ -267,63 +253,51 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
-    
+
     long[] processIds = new long[processExecutionCount];
-    for (int i = 0; i < processExecutionCount; i++)
-    {
+    for (int i = 0; i < processExecutionCount; i++) {
       processIds[i] = launchProcess("execution").getId();
       EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
     }
-    for (int i = 0; i < processExecutionCount; i++)
-    {
+    for (int i = 0; i < processExecutionCount; i++) {
       EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
     }
-    for (int i = 0; i < processExecutionCount; i++)
-    {
+    for (int i = 0; i < processExecutionCount; i++) {
       waitForProcessEnd(processIds[i]);
       assertTrue(hasProcessEnded(processIds[i]));
     }
   }
 
-  private ProcessDefinition deployProcess(String xml)
-  {
-    return (ProcessDefinition)commandService.execute(new DeployProcessCommand(xml));
+  private ProcessDefinition deployProcess(String xml) {
+    return (ProcessDefinition) commandService.execute(new DeployProcessCommand(xml));
   }
 
-  private ProcessInstance launchProcess(String processName)
-  {
+  private ProcessInstance launchProcess(String processName) {
     StartProcessInstanceCommand command = new StartProcessInstanceCommand();
     command.setProcessDefinitionName(processName);
     command.setVariables(Collections.singletonMap("eventCallback", new EventCallback()));
-    return (ProcessInstance)commandService.execute(command);
+    return (ProcessInstance) commandService.execute(command);
   }
 
-  private boolean hasProcessEnded(final long processId)
-  {
-    Boolean isFinished = (Boolean)commandService.execute(new Command()
-    {
+  private boolean hasProcessEnded(final long processId) {
+    Boolean isFinished = (Boolean) commandService.execute(new Command() {
       private static final long serialVersionUID = 1L;
 
-      public Object execute(JbpmContext jbpmContext) throws Exception
-      {
+      public Object execute(JbpmContext jbpmContext) throws Exception {
         return jbpmContext.loadProcessInstance(processId).hasEnded();
       }
     });
     return isFinished.booleanValue();
   }
 
-  private void waitForProcessEnd(long processId)
-  {
+  private void waitForProcessEnd(long processId) {
     long startTime = System.currentTimeMillis();
-    do
-    {
+    do {
       EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END, 1000);
-      if (System.currentTimeMillis() - startTime > maxWaitTime)
-      {
+      if (System.currentTimeMillis() - startTime > maxWaitTime) {
         log.warn("process " + processId + " took too long");
         break;
       }
-    }
-    while (!hasProcessEnded(processId));
+    } while (!hasProcessEnded(processId));
   }
 }

Modified: jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java	2009-01-13 18:03:40 UTC (rev 3633)
@@ -32,229 +32,157 @@
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmContext;
 import org.jboss.bpm.api.test.IntegrationTestSetup;
+import org.jbpm.command.Command;
+import org.jbpm.command.DeleteProcessDefinitionCommand;
+import org.jbpm.command.DeployProcessCommand;
+import org.jbpm.command.GetProcessInstanceCommand;
+import org.jbpm.command.StartProcessInstanceCommand;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.persistence.jta.JtaDbPersistenceService;
 
-public class JtaDbPersistenceTest extends ServletTestCase
-{
+public class JtaDbPersistenceTest extends ServletTestCase {
 
-  private JbpmConfiguration jbpmConfiguration;
-  private UserTransaction tx;
-  private boolean rollback;
+  private CommandExecutor commandExecutor;
 
-  private static long definitionId;
-
-  public static Test suite() throws Exception
-  {
+  public static Test suite() throws Exception {
     return new IntegrationTestSetup(JtaDbPersistenceTest.class, "enterprise-test.war");
   }
 
-  protected void setUp() throws Exception
-  {
-    jbpmConfiguration = JbpmConfiguration.getInstance();
+  public void testExternalTx() throws Exception {
+    commandExecutor = new CommandExecutor(getUserTransaction());
+    playTx(false);
   }
 
-  public void testUserTx() throws Exception
-  {
-    tx = getUserTransaction();
-    testServiceTx();
+  public void testExternalTxRollback() throws Exception {
+    commandExecutor = new CommandExecutor(getUserTransaction());
+    playTx(true);
   }
 
-  public void testUserTxRollback() throws Exception
-  {
-    tx = getUserTransaction();
-    testServiceTxRollback();
+  public void testInternalTx() throws Exception {
+    commandExecutor = new CommandExecutor();
+    playTx(false);
   }
 
-  public void testServiceTx() throws Exception
-  {
-    long definitionId = deployProcess();
-    long instanceId = launchProcess(definitionId);
-    signal(instanceId);
-    assertTrue(hasEnded(instanceId));
+  public void testInternalTxRollback() throws Exception {
+    commandExecutor = new CommandExecutor();
+    playTx(true);
   }
 
-  public void testServiceTxRollback() throws Exception
-  {
-    rollback = true;
+  private void playTx(boolean rollback) throws Exception {
     long definitionId = deployProcess();
     long instanceId = launchProcess(definitionId);
-    signal(instanceId);
-    assertFalse(hasEnded(instanceId));
+    signal(instanceId, rollback);
+    assertEquals(!rollback, hasEnded(instanceId));
+    deleteProcess(definitionId);
   }
 
-  private long deployProcess() throws Exception
-  {
-    if (definitionId == 0)
-    {
-      try
-      {
-        if (tx != null)
-          tx.begin();
+  private long deployProcess() throws Exception {
+    ProcessDefinition definition = (ProcessDefinition) commandExecutor
+        .execute(new DeployProcessCommand("<process-definition name='tx'>"
+            + "  <start-state name='start'>"
+            + "    <transition to='midway' />"
+            + "  </start-state>"
+            + "  <state name='midway'>"
+            + "    <transition to='end' />"
+            + "  </state>"
+            + "  <end-state name='end' />"
+            + "</process-definition>"));
+    return definition.getId();
+  }
+
+  private long launchProcess(long definitionId) throws Exception {
+    ProcessInstance instance = (ProcessInstance) commandExecutor
+        .execute(new StartProcessInstanceCommand().processDefinitionId(definitionId));
+    return instance.getId();
+  }
+
+  private void signal(final long instanceId, boolean rollback) throws Exception {
+    commandExecutor.execute(new Command() {
+      private static final long serialVersionUID = 1L;
+
+      public Object execute(JbpmContext jbpmContext) throws Exception {
+        jbpmContext.loadProcessInstance(instanceId).signal();
+        return null;
+      }
+    }, rollback);
+  }
+
+  private boolean hasEnded(long instanceId) throws Exception {
+    ProcessInstance instance = (ProcessInstance) commandExecutor
+        .execute(new GetProcessInstanceCommand(instanceId));
+    return instance.hasEnded();
+  }
+
+  private void deleteProcess(long definitionId) throws Exception {
+    commandExecutor.execute(new DeleteProcessDefinitionCommand(definitionId));
+  }
+
+  static class CommandExecutor {
+
+    private JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+    private UserTransaction tx;
+
+    public CommandExecutor() {
+    }
+
+    public CommandExecutor(UserTransaction userTransaction) {
+      tx = userTransaction;
+    }
+
+    public Object execute(Command command) throws Exception {
+      return execute(command, false);
+    }
+
+    public Object execute(Command command, boolean rollback) throws Exception {
+      if (tx != null)
+        tx.begin();
+      try {
         JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-        try
-        {
+        Object result;
+        try {
           assertEquals(tx == null, isTxCreatedByService(jbpmContext));
-          ProcessDefinition definition = ProcessDefinition.parseXmlString(
-              "<process-definition name='tx'>" + 
-              "  <start-state name='start'>" + 
-              "    <transition to='midway' />" + 
-              "  </start-state>" + 
-              "  <state name='midway'>" + 
-              "    <transition to='end' />" + 
-              "  </state>" + 
-              "  <end-state name='end' />" + 
-              "</process-definition>");
-          jbpmContext.deployProcessDefinition(definition);
-          definitionId = definition.getId();
+          result = command.execute(jbpmContext);
+          if (rollback && tx == null)
+            jbpmContext.setRollbackOnly();
         }
-        catch (RuntimeException e)
-        {
+        catch (RuntimeException e) {
           if (tx == null)
             jbpmContext.setRollbackOnly();
           throw e;
         }
-        finally
-        {
+        finally {
           jbpmContext.close();
         }
-        if (tx != null)
-          tx.commit();
+        if (tx != null) {
+          if (rollback)
+            tx.rollback();
+          else
+            tx.commit();
+        }
+        return result;
       }
-      catch (Exception e)
-      {
+      catch (Exception e) {
         if (tx != null)
           tx.rollback();
         throw e;
       }
     }
-    return definitionId;
   }
 
-  private long launchProcess(long definitionId) throws Exception
-  {
-    try
-    {
-      if (tx != null)
-        tx.begin();
-      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-      ProcessInstance instance;
-      try
-      {
-        assertEquals(tx == null, isTxCreatedByService(jbpmContext));
-        ProcessDefinition definition = jbpmContext.getGraphSession().loadProcessDefinition(definitionId);
-        instance = new ProcessInstance(definition);
-        instance.signal();
-        jbpmContext.save(instance);
-      }
-      catch (RuntimeException e)
-      {
-        if (tx == null)
-          jbpmContext.setRollbackOnly();
-        throw e;
-      }
-      finally
-      {
-        jbpmContext.close();
-      }
-      if (tx != null)
-        tx.commit();
-      return instance.getId();
-    }
-    catch (Exception e)
-    {
-      if (tx != null)
-        tx.rollback();
-      throw e;
-    }
+  private static boolean isTxCreatedByService(JbpmContext jbpmContext) {
+    JtaDbPersistenceService persistenceService = (JtaDbPersistenceService) jbpmContext
+        .getServices().getPersistenceService();
+    return persistenceService.isJtaTxCreated();
   }
 
-  private void signal(long instanceId) throws Exception
-  {
-    try
-    {
-      if (tx != null)
-        tx.begin();
-      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-      try
-      {
-        assertEquals(tx == null, isTxCreatedByService(jbpmContext));
-        ProcessInstance instance = jbpmContext.loadProcessInstanceForUpdate(instanceId);
-        instance.signal();
-        if (rollback && tx == null)
-          jbpmContext.setRollbackOnly();
-      }
-      catch (RuntimeException e)
-      {
-        if (tx == null)
-          jbpmContext.setRollbackOnly();
-        throw e;
-      }
-      finally
-      {
-        jbpmContext.close();
-      }
-      if (tx != null)
-      {
-        if (rollback)
-          tx.rollback();
-        else
-          tx.commit();
-      }
+  private static UserTransaction getUserTransaction() throws NamingException {
+    Context initial = new InitialContext();
+    try {
+      return (UserTransaction) initial.lookup("java:comp/UserTransaction");
     }
-    catch (Exception e)
-    {
-      if (tx != null)
-        tx.rollback();
-      throw e;
+    finally {
+      initial.close();
     }
   }
-
-  private boolean hasEnded(long instanceId) throws Exception
-  {
-    try
-    {
-      if (tx != null)
-        tx.begin();
-      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-      ProcessInstance instance;
-      try
-      {
-        assertEquals(tx == null, isTxCreatedByService(jbpmContext));
-        instance = jbpmContext.loadProcessInstanceForUpdate(instanceId);
-      }
-      catch (RuntimeException e)
-      {
-        if (tx == null)
-          jbpmContext.setRollbackOnly();
-        throw e;
-      }
-      finally
-      {
-        jbpmContext.close();
-      }
-      if (tx != null)
-        tx.commit();
-      return instance.hasEnded();
-    }
-    catch (Exception e)
-    {
-      if (tx != null)
-        tx.rollback();
-      throw e;
-    }
-  }
-
-  private boolean isTxCreatedByService(JbpmContext jbpmContext)
-  {
-    JtaDbPersistenceService persistenceService = (JtaDbPersistenceService)jbpmContext.getServices().getPersistenceService();
-    return persistenceService.isJtaTxCreated();
-  }
-
-  private static UserTransaction getUserTransaction() throws NamingException
-  {
-    Context initial = new InitialContext();
-    return (UserTransaction)initial.lookup("java:comp/UserTransaction");
-  }
 }

Modified: jbpm3/trunk/modules/enterprise/src/test/resources/enterprise/WEB-INF/jboss-web.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/resources/enterprise/WEB-INF/jboss-web.xml	2009-01-13 11:39:31 UTC (rev 3632)
+++ jbpm3/trunk/modules/enterprise/src/test/resources/enterprise/WEB-INF/jboss-web.xml	2009-01-13 18:03:40 UTC (rev 3633)
@@ -16,16 +16,17 @@
   
   <ejb-ref>
     <ejb-ref-name>ejb/CommandServiceBean</ejb-ref-name>
-    <jndi-name>java:ejb/CommandServiceBean</jndi-name>
+    <jndi-name>java:jbpm/CommandServiceBean</jndi-name>
   </ejb-ref>
 
   <ejb-ref>
     <ejb-ref-name>ejb/TimerEntityBean</ejb-ref-name>
-    <jndi-name>java:ejb/TimerEntityBean</jndi-name>
+    <jndi-name>java:jbpm/TimerEntityBean</jndi-name>
   </ejb-ref>
   
   <message-destination-ref>
     <message-destination-ref-name>jms/JobQueue</message-destination-ref-name>
     <jndi-name>queue/JbpmJobQueue</jndi-name>
   </message-destination-ref>
+
 </jboss-web>
\ No newline at end of file




More information about the jbpm-commits mailing list