[jbpm-commits] JBoss JBPM SVN: r6132 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/bpmn/test and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jan 26 07:39:12 EST 2010
Author: jbarrez
Date: 2010-01-26 07:39:12 -0500 (Tue, 26 Jan 2010)
New Revision: 6132
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/deployment/
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/deployment/Bpmn2DeploymentTest.java
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
Log:
Added test case for deployment/redeployment in BPMN2
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-01-26 11:30:19 UTC (rev 6131)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-01-26 12:39:12 UTC (rev 6132)
@@ -114,7 +114,11 @@
String id = XmlUtil.attribute(processElement, "id", false, parse);
String name = XmlUtil.attribute(processElement, "name", false, parse);
- processDefinition.setName(id);
+ if (id != null && !"".equals(id)) {
+ processDefinition.setName(id);
+ } else {
+ parse.addProblem("Process has no or an empty id");
+ }
if (name != null) {
processDefinition.setKey(name);
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/deployment/Bpmn2DeploymentTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/deployment/Bpmn2DeploymentTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/deployment/Bpmn2DeploymentTest.java 2010-01-26 12:39:12 UTC (rev 6132)
@@ -0,0 +1,145 @@
+/*
+ * 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.bpmn.test.deployment;
+
+import java.util.List;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessDefinition;
+import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.CollectionAssertions;
+
+
+/**
+ * @author Joram Barrez
+ */
+public class Bpmn2DeploymentTest extends JbpmTestCase {
+
+ private static final String TEST_PROCESS_ONLY_ID =
+ "<definitions>" +
+ " <process id='myProcess' >" +
+ " <startEvent id='start'/>" +
+ " <sequenceFlow id='flow1' sourceRef='start' targetRef='end' />" +
+ " <endEvent id='end'/>" +
+ " </process>" +
+ "</definitions>";
+
+ private static final String TEST_PROCESS_ONLY_NAME =
+ "<definitions>" +
+ " <process name='myProcess' >" +
+ " <startEvent id='start'/>" +
+ " <sequenceFlow id='flow1' sourceRef='start' targetRef='end' />" +
+ " <endEvent id='end'/>" +
+ " </process>" +
+ "</definitions>";
+
+ private static final String TEST_PROCESS_ID_AND_NAME =
+ "<definitions>" +
+ " <process id='myProcess' name='myFirstProcess'>" +
+ " <startEvent id='start'/>" +
+ " <sequenceFlow id='flow1' sourceRef='start' targetRef='end' />" +
+ " <endEvent id='end'/>" +
+ " </process>" +
+ "</definitions>";
+
+ public void testDeployProcessWithOnlyName() {
+ try {
+ deployBpmn2XmlString(TEST_PROCESS_ONLY_NAME);
+ fail();
+ } catch (JbpmException e) {
+ // Exception is to be expected
+ }
+ }
+
+ public void testDeployProcessWithOnlyId() {
+ deployBpmn2XmlString(TEST_PROCESS_ONLY_ID);
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("myProcess");
+ assertNotNull(processInstance);
+ assertProcessInstanceEnded(processInstance);
+ }
+
+ public void testDeployProcessWithIdAndName() {
+ deployBpmn2XmlString(TEST_PROCESS_ID_AND_NAME);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("myFirstProcess");
+ assertNotNull(processInstance);
+ assertProcessInstanceEnded(processInstance);
+
+ try {
+ executionService.startProcessInstanceByKey("myProcess");
+ fail();
+ } catch (JbpmException e) {
+ assertTrue(e.getMessage().contains("no process definition with key"));
+ // exception expected: when a key is given, the id can't be used as a key
+ }
+ }
+
+ /* ------------
+ * REDEPLOYMENT
+ * ------------
+ */
+
+ public void testRedeployProcessWithOnlyId() {
+ deployBpmn2XmlString(TEST_PROCESS_ONLY_ID);
+
+ ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionKey("myProcess");
+ List<ProcessDefinition> definitions = query.list();
+ assertEquals(1, definitions.size());
+
+ deployBpmn2XmlString(TEST_PROCESS_ONLY_ID);
+ query.orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION);
+ definitions = query.list();
+
+ assertEquals(2, definitions.size());
+ assertEquals(1, definitions.get(0).getVersion());
+ assertEquals(2, definitions.get(1).getVersion());
+
+ // Check if the key is replaced with the name (query should give same result)
+ List<ProcessDefinition> definitionsByName = repositoryService.createProcessDefinitionQuery()
+ .processDefinitionName("myProcess").list();
+ CollectionAssertions.assertContainsSameElements(definitions, definitionsByName);
+ }
+
+ public void testRedeployProcessWithIdAndName() {
+ deployBpmn2XmlString(TEST_PROCESS_ID_AND_NAME);
+
+ ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionName("myProcess");
+ List<ProcessDefinition> definitions = query.list();
+ assertEquals(1, definitions.size());
+
+ deployBpmn2XmlString(TEST_PROCESS_ID_AND_NAME);
+ query.orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION);
+ definitions = query.list();
+
+ assertEquals(2, definitions.size());
+ assertEquals(1, definitions.get(0).getVersion());
+ assertEquals(2, definitions.get(1).getVersion());
+
+ // Check if the key is replaced with the name (query should give same result)
+ List<ProcessDefinition> definitionsByKey = repositoryService.createProcessDefinitionQuery()
+ .processDefinitionKey("myFirstProcess").list();
+ CollectionAssertions.assertContainsSameElements(definitions, definitionsByKey);
+ }
+
+}
More information about the jbpm-commits
mailing list