[jbpm-commits] JBoss JBPM SVN: r5305 - in jbpm4/trunk/modules: test-base/src/main/java/org/jbpm/test and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Jul 16 02:58:08 EDT 2009
Author: jbarrez
Date: 2009-07-16 02:58:08 -0400 (Thu, 16 Jul 2009)
New Revision: 5305
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/JoinTest.java
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
jbpm4/trunk/modules/test-concurrent/src/test/java/org/jbpm/test/concurrent/BasicUsageTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SubProcessTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskPropertiesTest.java
Log:
Fix for JBPM-2407 + added some test convience methods
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java 2009-07-16 06:18:49 UTC (rev 5304)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java 2009-07-16 06:58:08 UTC (rev 5305)
@@ -31,6 +31,10 @@
* @author Tom Baeyens
*/
public class JoinBinding extends JpdlBinding {
+
+ private static final String MULTIPLICITY = "multiplicity";
+
+ private static final String LOCKMODE = "lockmode";
public JoinBinding() {
super("join");
@@ -38,22 +42,22 @@
public Object parse(Element element, Parse parse, Parser parser) {
JoinActivity joinActivity = new JoinActivity();
-
- if (element.hasAttribute("multiplicicty")) {
- String multiplicictyText = element.getAttribute("multiplicicty");
+
+ if (element.hasAttribute(MULTIPLICITY)) {
+ String multiplicictyText = element.getAttribute(MULTIPLICITY);
try {
int multiplicity = Integer.parseInt(multiplicictyText);
joinActivity.setMultiplicity(multiplicity);
} catch (NumberFormatException e) {
- parse.addProblem("multiplicity "+multiplicictyText+" is not a valid integer", element);
+ parse.addProblem(MULTIPLICITY + " " + multiplicictyText + " is not a valid integer", element);
}
}
- if (element.hasAttribute("lockmode")) {
- String lockModeText = element.getAttribute("lockmode");
+ if (element.hasAttribute(LOCKMODE)) {
+ String lockModeText = element.getAttribute(LOCKMODE);
LockMode lockMode = LockMode.parse(lockModeText.toUpperCase());
if (lockMode==null) {
- parse.addProblem("lockmode "+lockModeText+" is not a valid lock mode", element);
+ parse.addProblem(LOCKMODE + " " + lockModeText + " is not a valid lock mode", element);
} else {
joinActivity.setLockMode(lockMode);
}
Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java 2009-07-16 06:18:49 UTC (rev 5304)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java 2009-07-16 06:58:08 UTC (rev 5305)
@@ -36,7 +36,6 @@
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
-import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.task.Task;
/** base class for persistent jBPM tests.
@@ -203,7 +202,7 @@
// execution helper methods //////////////////////////////////////////
public void assertExecutionEnded(String processInstanceId) {
- assertNull("Error: a process instance with id " + processInstanceId + " was found",
+ assertNull("Error: an active process instance with id " + processInstanceId + " was found",
executionService.findProcessInstanceById(processInstanceId));
}
@@ -215,22 +214,49 @@
assertExecutionEnded(processInstance.getId());
}
- public void assertActiveActivity(String activityName, String executionId) {
- Execution execution = executionService.findExecutionById(executionId);
- assertTrue("The given execution (or any child execution) isn't in the activity '" + activityName
- + "' (current activities : " + listAllActiveActivites(executionId) + ")",
- execution.isActive(activityName));
+ public void assertProcessInstanceActive(String processInstanceId) {
+ assertNotNull("Error: an active process instance with id " + processInstanceId + " was not found",
+ executionService.findProcessInstanceById(processInstanceId));
}
- public void assertExecutionInActivity(String executionId, String activityName) {
+ public void assertActivityActive(String executionId, String activityName) {
assertTrue("The execution with id '" + executionId +
"' is not active in the activity '" + activityName + "'." +
"Current activitites are: " + listAllActiveActivites(executionId),
executionService.findExecutionById(executionId).isActive(activityName));
}
- private String listAllActiveActivites(String executionId) {
+ public void assertNotActivityActive(String executionId, String activityName) {
Execution execution = executionService.findExecutionById(executionId);
+ assertFalse(execution.isActive(activityName));
+ }
+
+ public void assertActivitiesActive(String executionId, String ... activityNames) {
+ for (String activityName : activityNames) {
+ assertActivityActive(executionId, activityName);
+ }
+ }
+
+ /** Checks if the given execution is active in one (or more) of the given activities */
+ public void assertExecutionInOneOrMoreActivitiesActive(String executionId, String ... activityNames) {
+
+ boolean inOneActivityActive = false;
+ Execution execution = executionService.findExecutionById(executionId);
+
+ for (String activityName : activityNames) {
+ if (execution.isActive(activityName)) {
+ inOneActivityActive = true;
+ }
+ }
+
+ assertTrue("The execution with id '" + executionId +
+ "' is not active in one of these activities: " + activityNames +
+ "Current activitites are: " + listAllActiveActivites(executionId),
+ inOneActivityActive);
+ }
+
+ protected String listAllActiveActivites(String executionId) {
+ Execution execution = executionService.findExecutionById(executionId);
Set<String> activeActivities = execution.findActiveActivityNames();
StringBuilder result = new StringBuilder();
for (String activeActivity : activeActivities) {
Modified: jbpm4/trunk/modules/test-concurrent/src/test/java/org/jbpm/test/concurrent/BasicUsageTest.java
===================================================================
--- jbpm4/trunk/modules/test-concurrent/src/test/java/org/jbpm/test/concurrent/BasicUsageTest.java 2009-07-16 06:18:49 UTC (rev 5304)
+++ jbpm4/trunk/modules/test-concurrent/src/test/java/org/jbpm/test/concurrent/BasicUsageTest.java 2009-07-16 06:58:08 UTC (rev 5305)
@@ -52,7 +52,7 @@
);
ProcessInstance processInstance = executionService.startProcessInstanceByKey("TimerTest");
- assertActiveActivity("wait", processInstance.getId());
+ assertActivityActive("wait", processInstance.getId());
Job job = managementService.createJobQuery()
.processInstanceId(processInstance.getId())
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/JoinTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/JoinTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/JoinTest.java 2009-07-16 06:58:08 UTC (rev 5305)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.activities;
+
+import org.jbpm.api.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * Test case for basic functionality of Join activity.
+ *
+ * @author jbarrez
+ */
+public class JoinTest extends JbpmTestCase {
+
+
+ public void testMultiplicityLessThanIncomingTransitions() {
+ deployJpdlXmlString(
+ "<process name='multiplicityProcess'>" +
+ " <start>" +
+ " <transition to='theFork' />" +
+ " </start>" +
+ " <fork name='theFork'>" +
+ " <transition to='stateOne' />" +
+ " <transition to='stateTwo' />" +
+ " <transition to='stateThree' />" +
+ " </fork>" +
+ " <state name='stateOne'>" +
+ " <transition to='theJoin' />" +
+ " </state> " +
+ " <state name='stateTwo'>" +
+ " <transition to='theJoin' />" +
+ " </state> " +
+ " <state name='stateThree'>" +
+ " <transition to='theJoin' />" +
+ " </state> " +
+ " <join name='theJoin' multiplicity='2'>" +
+ " <transition to='end' />" +
+ " </join>" +
+ " <end name='end' />" +
+ "</process>"
+ );
+ String processInstanceId = executionService.startProcessInstanceByKey("multiplicityProcess").getId();
+ assertActivitiesActive(processInstanceId, "stateOne", "stateTwo", "stateThree");
+
+ // Signalling 'stateOne' will should not end the process instance
+ Execution executionInStateOne = executionService.findExecutionById(processInstanceId)
+ .findActiveExecutionIn("stateOne");
+ executionService.signalExecutionById(executionInStateOne.getId());
+ assertProcessInstanceActive(processInstanceId);
+
+ // Signalling 'stateTwo' should end the process instance
+ Execution executionInStateTwo = executionService.findExecutionById(processInstanceId)
+ .findActiveExecutionIn("stateTwo");
+ executionService.signalExecutionById(executionInStateTwo.getId());
+ assertProcessInstanceEnded(processInstanceId);
+ }
+
+ public void testNoMultiplicity() {
+ deployJpdlXmlString(
+ "<process name='multiplicityProcess'>" +
+ " <start>" +
+ " <transition to='theFork' />" +
+ " </start>" +
+ " <fork name='theFork'>" +
+ " <transition to='stateOne' />" +
+ " <transition to='stateTwo' />" +
+ " <transition to='stateThree' />" +
+ " </fork>" +
+ " <state name='stateOne'>" +
+ " <transition to='theJoin' />" +
+ " </state> " +
+ " <state name='stateTwo'>" +
+ " <transition to='theJoin' />" +
+ " </state> " +
+ " <state name='stateThree'>" +
+ " <transition to='theJoin' />" +
+ " </state> " +
+ " <join name='theJoin'>" +
+ " <transition to='end' />" +
+ " </join>" +
+ " <end name='end' />" +
+ "</process>"
+ );
+
+ String processInstanceId = executionService.startProcessInstanceByKey("multiplicityProcess").getId();
+ assertActivitiesActive(processInstanceId, "stateOne", "stateTwo", "stateThree");
+
+ executionService.signalExecutionById(executionService.findExecutionById(processInstanceId).findActiveExecutionIn("stateOne").getId());
+ assertProcessInstanceActive(processInstanceId);
+ executionService.signalExecutionById(executionService.findExecutionById(processInstanceId).findActiveExecutionIn("stateTwo").getId());
+ assertProcessInstanceActive(processInstanceId);
+ executionService.signalExecutionById(executionService.findExecutionById(processInstanceId).findActiveExecutionIn("stateThree").getId());
+ assertProcessInstanceEnded(processInstanceId);
+ }
+
+}
Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/JoinTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SubProcessTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SubProcessTest.java 2009-07-16 06:18:49 UTC (rev 5304)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SubProcessTest.java 2009-07-16 06:58:08 UTC (rev 5305)
@@ -71,7 +71,7 @@
ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
Task task = taskService.findPersonalTasks("johndoe").get(0);
taskService.completeTask(task.getId(), "nok");
- assertExecutionInActivity(processInstance.getId(), "update");
+ assertActivityActive(processInstance.getId(), "update");
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskPropertiesTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskPropertiesTest.java 2009-07-16 06:18:49 UTC (rev 5304)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskPropertiesTest.java 2009-07-16 06:58:08 UTC (rev 5305)
@@ -30,6 +30,8 @@
/**
+ * Testcase to check if properties can be resolved through a {@link Task}.
+ *
* @author Joram Barrez
*/
public class TaskPropertiesTest extends JbpmTestCase {
More information about the jbpm-commits
mailing list