[jbpm-commits] JBoss JBPM SVN: r4658 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples/mail/inline and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Apr 28 21:28:05 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-04-28 21:28:05 -0400 (Tue, 28 Apr 2009)
New Revision: 4658

Added:
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/template/
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/template/process.jpdl.xml
Modified:
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java
   jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/inline/process.jpdl.xml
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailTemplate.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java
Log:
[JBPM-2058] mail example with external template

Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java	2009-04-28 19:25:30 UTC (rev 4657)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java	2009-04-29 01:28:05 UTC (rev 4658)
@@ -23,7 +23,9 @@
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
+import java.util.Random;
 
 import javax.mail.Address;
 import javax.mail.Message;
@@ -40,29 +42,22 @@
  */
 public class InlineMailTest extends JbpmTestCase {
 
-  long deploymentDbid;
-
   protected void setUp() throws Exception {
     super.setUp();
-
-    deploymentDbid =
-        repositoryService.createDeployment().addResourceFromClasspath(
-            "org/jbpm/examples/mail/inline/process.jpdl.xml").deploy();
+    long deploymentDbid = repositoryService.createDeployment().addResourceFromClasspath(
+        "org/jbpm/examples/mail/inline/process.jpdl.xml").deploy();
+    registerDeployment(deploymentDbid);
   }
 
-  protected void tearDown() throws Exception {
-    repositoryService.deleteDeploymentCascade(deploymentDbid);
-
-    super.tearDown();
-  }
-
   public void testInlineMail() throws MessagingException, IOException {
     Wiser wiser = new Wiser();
-    wiser.setPort(2525); // default is 25, but has security problems
+    wiser.setPort(2525); // default is 25, but has security restrictions
     wiser.start();
     try {
       // start process instance
-      executionService.startProcessInstanceByKey("InlineMail");
+      Object orderId = new Random().nextInt(1000) + 1;
+      executionService.startProcessInstanceByKey("InlineMail", Collections.singletonMap("orderId",
+          orderId));
 
       // examine produced message
       List<WiserMessage> wiserMessages = wiser.getMessages();
@@ -81,7 +76,8 @@
         // subject
         assertEquals("bureaucracy", message.getSubject());
         // text
-        assertEquals("plain text content", message.getContent());
+        assertEquals("Order http://example.com/order/" + orderId + " is stalled.",
+            message.getContent());
       }
     }
     finally {

Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java	2009-04-29 01:28:05 UTC (rev 4658)
@@ -0,0 +1,87 @@
+/*
+ * 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.examples.mail.template;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Message.RecipientType;
+import javax.mail.internet.InternetAddress;
+
+import org.jbpm.test.JbpmTestCase;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class TemplateMailTest extends JbpmTestCase {
+
+  protected void setUp() throws Exception {
+    super.setUp();
+    long deploymentDbid = repositoryService.createDeployment().addResourceFromClasspath(
+        "org/jbpm/examples/mail/template/process.jpdl.xml").deploy();
+    registerDeployment(deploymentDbid);
+  }
+
+  public void testTemplateMail() throws MessagingException, IOException {
+    Wiser wiser = new Wiser();
+    wiser.setPort(2525); // default is 25, but has security restrictions
+    wiser.start();
+    try {
+      // start process instance
+      Object orderId = new Random().nextInt(1000) + 1;
+      executionService.startProcessInstanceByKey("TemplateMail", Collections.singletonMap(
+          "orderId", orderId));
+
+      // examine produced message
+      List<WiserMessage> wiserMessages = wiser.getMessages();
+      assertEquals(3, wiserMessages.size());
+
+      for (WiserMessage wiserMessage : wiserMessages) {
+        Message message = wiserMessage.getMimeMessage();
+        // from
+        Address[] from = message.getFrom();
+        assertEquals(1, from.length);
+        assertEquals("noreply at jbpm.org", from[0].toString());
+        // to
+        Address[] expectedTo = InternetAddress.parse("dilbert at office, alice at work, dogbert at house");
+        Address[] to = message.getRecipients(RecipientType.TO);
+        assert Arrays.equals(expectedTo, to) : to;
+        // subject
+        assertEquals("bureaucracy", message.getSubject());
+        // text
+        assertEquals("Order http://example.com/order/" + orderId + " is stalled.",
+            message.getContent());
+      }
+    }
+    finally {
+      wiser.stop();
+    }
+  }
+}

Modified: jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml	2009-04-28 19:25:30 UTC (rev 4657)
+++ jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml	2009-04-29 01:28:05 UTC (rev 4658)
@@ -7,4 +7,14 @@
   <import resource="jbpm.jpdl.cfg.xml" />
   <import resource="jbpm.identity.cfg.xml" />
 
+  <process-engine-context>
+
+    <mail-template name="MemoTemplate">
+      <to addresses='dilbert at office, alice at work, dogbert at house' />
+      <subject>bureaucracy</subject>
+      <text>Order http://example.com/order/#{orderId} is stalled.</text>
+    </mail-template>
+
+  </process-engine-context>
+
 </jbpm-configuration>

Modified: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/inline/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/inline/process.jpdl.xml	2009-04-28 19:25:30 UTC (rev 4657)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/inline/process.jpdl.xml	2009-04-29 01:28:05 UTC (rev 4658)
@@ -3,13 +3,13 @@
 <process name="InlineMail">
 
   <start>
-    <transition to="SendMemo" />
+    <transition to="SendMemo"/>
   </start>
-
+        
   <mail name="SendMemo">
      <to addresses='dilbert at office, alice at work, dogbert at house'/>
      <subject>bureaucracy</subject>
-     <text>plain text content</text>
+     <text>Order http://example.com/order/#{orderId} is stalled.</text>
      <transition to="End" />
   </mail>
   

Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/template/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/template/process.jpdl.xml	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/mail/template/process.jpdl.xml	2009-04-29 01:28:05 UTC (rev 4658)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="TemplateMail">
+
+  <start>
+    <transition to="SendMemo" />
+  </start>
+
+  <mail name="SendMemo" template="MemoTemplate">
+     <transition to="End" />
+  </mail>
+  
+  <state name="End"/>
+
+</process>
\ No newline at end of file

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailTemplate.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailTemplate.java	2009-04-28 19:25:30 UTC (rev 4657)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailTemplate.java	2009-04-29 01:28:05 UTC (rev 4658)
@@ -35,7 +35,6 @@
  */
 public class MailTemplate {
 
-  private String name;
   private String language;
   private AddressTemplate from;
   private Map<RecipientType, AddressTemplate> recipientTemplates =
@@ -46,17 +45,6 @@
   private List<AttachmentTemplate> attachmentTemplates = new ArrayList<AttachmentTemplate>();
 
   /**
-   * Name of this template, useful for referencing it from mail activities.
-   */
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  /**
    * Templating engine meant to produce dynamic content.
    */
   public String getLanguage() {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java	2009-04-28 19:25:30 UTC (rev 4657)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java	2009-04-29 01:28:05 UTC (rev 4658)
@@ -51,7 +51,7 @@
     // name
     String name = element.getAttribute("name");
     if (name != null) {
-      templateDescriptor.addInjection("name", new StringDescriptor(name));
+      templateDescriptor.setName(name);
     }
     else {
       parse.addProblem("template has no name");

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java	2009-04-28 19:25:30 UTC (rev 4657)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java	2009-04-29 01:28:05 UTC (rev 4658)
@@ -40,8 +40,8 @@
             + "</mail-template>"
             + "</objects>");
 
-    MailTemplate template = wireContext.get(MailTemplate.class);
-    assertEquals("memo", template.getName());
+    Object template = wireContext.get("memo");
+    assertTrue(template instanceof MailTemplate);
   }
 
   public void testLanguage() {




More information about the jbpm-commits mailing list