[jbpm-commits] JBoss JBPM SVN: r6267 - in jbpm4/trunk/modules/test-db/src/test: resources and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Apr 20 21:31:28 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-04-20 21:31:26 -0400 (Tue, 20 Apr 2010)
New Revision: 6267

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
Modified:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java
   jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml
Log:
JBPM-2844: check in custom mail producer test

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java	2010-04-21 01:31:26 UTC (rev 6267)
@@ -0,0 +1,134 @@
+/*
+ * 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.activity.mail;
+
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.Message;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.pvm.internal.email.impl.MailProducerImpl;
+import org.jbpm.pvm.internal.email.impl.MailTemplateRegistry;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.test.JbpmTestCase;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class CustomMailProducerTest extends JbpmTestCase {
+
+  private Wiser wiser;
+  private String group1;
+  private String group2;
+
+  protected void setUp() throws Exception {
+    super.setUp();
+    // start mail server
+    wiser = new Wiser();
+    wiser.setPort(2525);
+    wiser.start();
+    // create actors
+    identityService.createUser("bb", "Big Brother", null, "bb at oceania");
+    identityService.createUser("obrien", null, "O'Brien", "obrien at miniluv");
+    identityService.createUser("charr", null, "Charrington", "charr at miniluv");
+    group1 = identityService.createGroup("thinkpol");
+    group2 = identityService.createGroup("innerparty");
+    identityService.createMembership("obrien", group2);
+    identityService.createMembership("charr", group1);
+    identityService.createMembership("obrien", group1);
+  }
+
+  protected void tearDown() throws Exception {
+    // delete actors
+    identityService.deleteGroup(group1);
+    identityService.deleteGroup(group2);
+    identityService.deleteUser("bb");
+    identityService.deleteUser("obrien");
+    identityService.deleteUser("charr");
+    // stop mail server
+    wiser.stop();
+    super.tearDown();
+  }
+
+  public void testCustomMailProducer() {
+    // deploy process
+    deployJpdlXmlString("<process name='custommail'>"
+      + "  <start>"
+      + "    <transition to='send mail' />"
+      + "  </start>"
+      + "  <mail name='send mail' class='"
+      + CustomMailProducer.class.getName()
+      + "'>"
+      + "    <field name='templateName'><string value='rectify-template'/></field>"
+      + "    <transition to='end' />"
+      + "  </mail>"
+      + "  <end name='end'/>"
+      + "</process>");
+
+    // prepare dynamic values
+    String addressee = "winston at minitrue";
+    String newspaper = "times";
+    Calendar calendar = Calendar.getInstance();
+    calendar.clear();
+    calendar.set(1983, Calendar.DECEMBER, 3);
+    Date date = calendar.getTime();
+    String details = "reporting bb dayorder doubleplusungood refs unpersons rewrite "
+      + "fullwise upsub antefiling";
+    // assemble variables
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("addressee", addressee);
+    variables.put("newspaper", newspaper);
+    variables.put("date", date);
+    variables.put("details", details);
+    // start process instance
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("custommail",
+      variables);
+    assertProcessInstanceEnded(processInstance);
+
+    // examine produced messages
+    List<WiserMessage> messages = wiser.getMessages();
+    // winston, bb, innerparty(obrien), thinkpol(charr, obrien)
+    assertEquals(5, messages.size());
+  }
+
+  public static class CustomMailProducer extends MailProducerImpl {
+
+    private String templateName;
+    private static final long serialVersionUID = 1L;
+
+    public Collection<Message> produce(Execution execution) {
+      MailTemplateRegistry templateRegistry = EnvironmentImpl
+        .getFromCurrent(MailTemplateRegistry.class);
+      setTemplate(templateRegistry.getTemplate(templateName));
+      return super.produce(execution);
+    }
+  }
+
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java	2010-04-20 18:41:23 UTC (rev 6266)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java	2010-04-21 01:31:26 UTC (rev 6267)
@@ -23,6 +23,7 @@
 
 import java.util.List;
 
+import org.jbpm.api.ProcessInstance;
 import org.jbpm.test.JbpmTestCase;
 import org.subethamail.wiser.Wiser;
 import org.subethamail.wiser.WiserMessage;
@@ -31,9 +32,9 @@
  * @author Tom Baeyens
  */
 public class MailTest extends JbpmTestCase {
-  
-  Wiser wiser = null;
 
+  private Wiser wiser;
+
   protected void setUp() throws Exception {
     super.setUp();
     // start mail server
@@ -41,30 +42,30 @@
     wiser.setPort(2525);
     wiser.start();
   }
-  
+
   protected void tearDown() throws Exception {
+    // stop mail server
     wiser.stop();
     super.tearDown();
   }
 
   public void testMailToPlainAddress() {
-    deployJpdlXmlString(
-        "<process name='MailTest'>" +
-        "  <start>" +
-        "    <transition to='mailtestmail' />" +
-        "  </start>" +
-        "  <mail name='mailtestmail'>" +
-        "    <to addresses='jos at rubensstraat' />" +
-        "    <subject>mail</subject>" +
-        "    <text>youhoooo</text>" +
-        "    <transition to='end' />" +
-        "  </mail>" +
-        "  <state name='end'/>" +
-        "</process>"
-    );
-    
-    executionService.startProcessInstanceByKey("MailTest");
-    
+    deployJpdlXmlString("<process name='plainaddress'>"
+      + "  <start>"
+      + "    <transition to='mailtestmail' />"
+      + "  </start>"
+      + "  <mail name='mailtestmail'>"
+      + "    <to addresses='jos at rubensstraat' />"
+      + "    <subject>mail</subject>"
+      + "    <text>youhoooo</text>"
+      + "    <transition to='end' />"
+      + "  </mail>"
+      + "  <end name='end'/>"
+      + "</process>");
+    ProcessInstance processInstance = executionService
+      .startProcessInstanceByKey("plainaddress");
+    assertProcessInstanceEnded(processInstance);
+
     List<WiserMessage> messages = wiser.getMessages();
     assertEquals(1, messages.size());
   }

Modified: jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml	2010-04-20 18:41:23 UTC (rev 6266)
+++ jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml	2010-04-21 01:31:26 UTC (rev 6267)
@@ -9,4 +9,6 @@
   <import resource="jbpm.bpmn.cfg.xml" />
   <import resource="jbpm.identity.cfg.xml" />
 
+  <import resource="jbpm.mail.templates.examples.xml" />
+
 </jbpm-configuration>



More information about the jbpm-commits mailing list