[jbpm-commits] JBoss JBPM SVN: r6464 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/task and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jul 6 02:46:35 EDT 2010
Author: rebody
Date: 2010-07-06 02:46:35 -0400 (Tue, 06 Jul 2010)
New Revision: 6464
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java
Removed:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/ExceptionTaskTest.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java
Log:
JBPM-2891 let notification element support expr attribute
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java 2010-07-06 06:29:15 UTC (rev 6463)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java 2010-07-06 06:46:35 UTC (rev 6464)
@@ -39,14 +39,14 @@
import org.w3c.dom.Element;
/** parses a descriptor for creating a java object through reflection.
- *
+ *
* See schema docs for more details.
- *
+ *
* @author Tom Baeyens
* @author Guillaume Porcher (documentation)
*/
public class ObjectBinding extends WireDescriptorBinding {
-
+
public static final String TAG = "object";
public ObjectBinding() {
@@ -54,15 +54,18 @@
}
public static boolean isObjectDescriptor(Element element) {
- if (XmlUtil.attribute(element, "class")!=null) {
+ if (XmlUtil.attribute(element, "class") != null) {
return true;
}
- if (XmlUtil.attribute(element, "factory")!=null) {
+ if (XmlUtil.attribute(element, "expr") != null) {
return true;
}
- if (XmlUtil.element(element, "factory")!=null) {
+ if (XmlUtil.attribute(element, "factory") != null) {
return true;
}
+ if (XmlUtil.element(element, "factory") != null) {
+ return true;
+ }
return false;
}
@@ -78,43 +81,49 @@
String factoryObjectName = XmlUtil.attribute(element, "factory");
Element factoryElement = XmlUtil.element(element, "factory");
- if (className!=null) {
+ if (className != null) {
descriptor.setClassName(className);
- if (factoryObjectName!=null) {
- parse.addProblem("attribute 'factory' is specified together with attribute 'class' in element 'object': "+XmlUtil.toString(element), element);
+ if (factoryObjectName != null) {
+ parse.addProblem("attribute 'factory' is specified together with attribute 'class' in element 'object': "
+ + XmlUtil.toString(element), element);
}
- if (factoryElement!=null) {
- parse.addProblem("element 'factory' is specified together with attribute 'class' in element 'object': "+XmlUtil.toString(element), element);
+ if (factoryElement != null) {
+ parse.addProblem("element 'factory' is specified together with attribute 'class' in element 'object': "
+ + XmlUtil.toString(element), element);
}
Element constructorElement = XmlUtil.element(element, "constructor");
- if (constructorElement!=null) {
+ if (constructorElement != null) {
List<Element> argElements = XmlUtil.elements(constructorElement, "arg");
List<ArgDescriptor> argDescriptors = parser.parseArgs(argElements, parse);
descriptor.setArgDescriptors(argDescriptors);
if (element.hasAttribute("method")) {
- parse.addProblem("attributes 'class' and 'method' indicate static method and also a 'constructor' element is specified for element 'object': "+XmlUtil.toString(element), element);
+ parse.addProblem("attributes 'class' and 'method' indicate static method and also a 'constructor' element is specified for element 'object': "
+ + XmlUtil.toString(element), element);
}
}
- } else if (factoryObjectName!=null) {
+ } else if (factoryObjectName != null) {
descriptor.setFactoryObjectName(factoryObjectName);
if (factoryElement!=null) {
- parse.addProblem("element 'factory' is specified together with attribute 'factory' in element 'object': "+XmlUtil.toString(element), element);
+ parse.addProblem("element 'factory' is specified together with attribute 'factory' in element 'object': "
+ + XmlUtil.toString(element), element);
}
- } else if (factoryElement!=null) {
+ } else if (factoryElement != null) {
Element factoryDescriptorElement = XmlUtil.element(factoryElement);
- Descriptor factoryDescriptor = (Descriptor) parser.parseElement(factoryDescriptorElement, parse, WireParser.CATEGORY_DESCRIPTOR);
+ Descriptor factoryDescriptor = (Descriptor) parser.parseElement(factoryDescriptorElement,
+ parse, WireParser.CATEGORY_DESCRIPTOR);
descriptor.setFactoryDescriptor(factoryDescriptor);
- } else if (expr!=null) {
+ } else if (expr != null) {
String exprType = XmlUtil.attribute(element, "expr-type");
descriptor.setExpression(Expression.create(expr, exprType));
-
+
} else {
- parse.addProblem("element 'object' must have one of {attribute 'class', attribute 'expr', attribute 'factory' or element 'factory'}: "+XmlUtil.toString(element), element);
+ parse.addProblem("element 'object' must have one of {attribute 'class', attribute 'expr', attribute 'factory' or element 'factory'}: "
+ + XmlUtil.toString(element), element);
}
// method
@@ -124,22 +133,24 @@
List<Element> argElements = XmlUtil.elements(element, "arg");
List<ArgDescriptor> argDescriptors = parser.parseArgs(argElements, parse);
descriptor.setArgDescriptors(argDescriptors);
- } else if ( (factoryObjectName!=null)
- || (factoryElement!=null)
+ } else if ( (factoryObjectName != null)
+ || (factoryElement != null)
) {
- parse.addProblem("element 'object' with a element 'factory' or a attribute 'factory' must have a attribute 'method': "+XmlUtil.toString(element), element);
+ parse.addProblem("element 'object' with a element 'factory' or a attribute 'factory' must have a attribute 'method': "
+ + XmlUtil.toString(element), element);
}
- if( (className == null)
+ if( (className == null)
&& (XmlUtil.element(element, "constructor") != null)
) {
- parse.addProblem("element 'object' with a 'constructor' element must have 'class' attribute: "+XmlUtil.toString(element), element);
+ parse.addProblem("element 'object' with a 'constructor' element must have 'class' attribute: "
+ + XmlUtil.toString(element), element);
}
// read the operations elements
List<Operation> operations = null;
List<Element> elements = XmlUtil.elements(element);
-
+
Set<String> operationTagNames = null;
Bindings bindings = parser.getBindings();
if (bindings!=null) {
@@ -148,10 +159,10 @@
operationTagNames = Collections.emptySet();
}
- for (Element childElement: elements) {
+ for (Element childElement : elements) {
if (operationTagNames.contains(childElement.getTagName())) {
Operation operation = (Operation) parser.parseElement(childElement, parse, WireParser.CATEGORY_OPERATION);
- if (operations==null) {
+ if (operations == null) {
operations = new ArrayList<Operation>();
}
operations.add(operation);
@@ -161,7 +172,7 @@
// autowiring
Boolean isAutoWireEnabled = XmlUtil.attributeBoolean(element, "auto-wire", parse);
- if (isAutoWireEnabled!=null) {
+ if (isAutoWireEnabled != null) {
descriptor.setAutoWireEnabled(isAutoWireEnabled);
}
return descriptor;
Deleted: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/ExceptionTaskTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/ExceptionTaskTest.java 2010-07-06 06:29:15 UTC (rev 6463)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/ExceptionTaskTest.java 2010-07-06 06:46:35 UTC (rev 6464)
@@ -1,61 +0,0 @@
-package org.jbpm.test.task;
-
-import java.util.*;
-
-import org.jbpm.api.*;
-import org.jbpm.api.job.*;
-import org.jbpm.api.task.*;
-
-import org.jbpm.test.*;
-
-
-public class ExceptionTaskTest extends JbpmTestCase {
- protected void setUp() throws Exception {
- super.setUp();
- identityService.createUser("johnsmith", "johnsmith", "johnsmith");
- deployJpdlXmlString(
- "<process name='X10ExceptionTaskTest' xmlns='http://jbpm.org/4.3/jpdl'>"
- + " <start name='start1' g='93,78,48,48' continue='async'>"
- + " <transition name='to Test Task' to='Test Task' g='1,-20'/>"
- + " </start>" + " <end name='end1' g='315,236,48,48'/>"
- + " <task name='Test Task' g='178,159,92,52' assignee='johnsmith'>"
- + " <notification>" + " <to users='${task.assignee}'/>"
- + " <cc addresses='invalid at email@address'/>"
- + " <subject>${task.name}</subject>" + " <text>"
- + " <![CDATA[Hi ${task.assignee},"
- + " Task '${task.name}' has been assigned to you."
- + " ${task.description}" + " Sent by JBoss jBPM"
- + " ]]>" + " </text>" + " </notification>"
- + " <transition name='to end1' to='end1' g='-6,-22'/>"
- + " </task>" + "</process>");
- }
-
- protected void tearDown() throws Exception {
- identityService.deleteUser("johnsmith");
- super.tearDown();
- }
-
- public void testDefault() throws Exception {
- ProcessInstance processInstance = executionService
- .startProcessInstanceByKey("X10ExceptionTaskTest");
- String processInstanceId = processInstance.getId();
- int retries = 0;
-
- while (retries < 3) {
- retries++;
-
- try {
- List<Job> jobs = managementService.createJobQuery().list();
- Job job = jobs.get(0);
- managementService.executeJob(job.getId());
-
- break;
- } catch (Exception e) {
- System.out.println(e);
- }
- }
-
- List<Task> tasks = taskService.createTaskQuery().list();
- assertEquals(0, tasks.size());
- }
-}
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java (from rev 6462, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/ExceptionTaskTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/NotificationTest.java 2010-07-06 06:46:35 UTC (rev 6464)
@@ -0,0 +1,100 @@
+package org.jbpm.test.task;
+
+import java.io.*;
+import java.util.*;
+import javax.mail.Message;
+
+import org.jbpm.api.*;
+import org.jbpm.api.job.*;
+import org.jbpm.api.task.*;
+import org.jbpm.pvm.internal.email.spi.*;
+import org.jbpm.test.*;
+
+/**
+ * @author Huisheng Xu
+ */
+public class NotificationTest extends JbpmTestCase {
+ protected void setUp() throws Exception {
+ super.setUp();
+ identityService.createUser("johnsmith", "johnsmith", "johnsmith");
+ }
+
+ protected void tearDown() throws Exception {
+ identityService.deleteUser("johnsmith");
+ super.tearDown();
+ }
+
+ public void testDefault() throws Exception {
+ deployJpdlXmlString(
+ "<process name='X10ExceptionTaskTest'>"
+ + " <start name='start1' g='93,78,48,48' continue='async'>"
+ + " <transition name='to Test Task' to='Test Task' g='1,-20'/>"
+ + " </start>"
+ + " <end name='end1' g='315,236,48,48'/>"
+ + " <task name='Test Task' g='178,159,92,52' assignee='johnsmith'>"
+ + " <notification>"
+ + " <to users='${task.assignee}'/>"
+ + " <cc addresses='invalid at email@address'/>"
+ + " <subject>${task.name}</subject>"
+ + " <text>"
+ + " <![CDATA[Hi ${task.assignee},"
+ + " Task '${task.name}' has been assigned to you."
+ + " ${task.description}"
+ + " Sent by JBoss jBPM"
+ + " ]]>"
+ + " </text>"
+ + " </notification>"
+ + " <transition name='to end1' to='end1' g='-6,-22'/>"
+ + " </task>" + "</process>");
+
+ ProcessInstance processInstance = executionService
+ .startProcessInstanceByKey("X10ExceptionTaskTest");
+ String processInstanceId = processInstance.getId();
+ int retries = 0;
+
+ while (retries < 3) {
+ retries++;
+
+ try {
+ List<Job> jobs = managementService.createJobQuery().list();
+ Job job = jobs.get(0);
+ managementService.executeJob(job.getId());
+
+ break;
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+
+ List<Task> tasks = taskService.createTaskQuery().list();
+ assertEquals(0, tasks.size());
+ }
+
+ public void testSupportExpr() {
+ deployJpdlXmlString(
+ "<process name='NotificationTaskTest' xmlns='http://jbpm.org/4.3/jpdl'>"
+ + " <start name='start1' g='93,78,48,48'>"
+ + " <transition name='to Test Task' to='Test Task' g='1,-20'/>"
+ + " </start>"
+ + " <end name='end1' g='315,236,48,48'/>"
+ + " <task name='Test Task' g='178,159,92,52' assignee='johnsmith'>"
+ + " <notification expr='#{jbpmCustomMailProducer}'>"
+ + " <field name='templateName'><string value='planning-approval-start-notifcation'/></field>"
+ + " </notification>"
+ + " <transition name='to end1' to='end1' g='-6,-22'/>"
+ + " </task>"
+ + "</process>");
+
+ ProcessInstance processInstance = executionService
+ .startProcessInstanceByKey("NotificationTaskTest",
+ Collections.singletonMap("jbpmCustomMailProducer", new JbpmCustomMailProducer()));
+ String processInstanceId = processInstance.getId();
+ }
+
+ public static class JbpmCustomMailProducer implements MailProducer, Serializable {
+ private String templateName;
+ public Collection<Message> produce(Execution execution) {
+ return Collections.EMPTY_SET;
+ }
+ }
+}
More information about the jbpm-commits
mailing list