[jbpm-commits] JBoss JBPM SVN: r3264 - jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Dec 8 06:43:09 EST 2008


Author: thomas.diesler at jboss.com
Date: 2008-12-08 06:43:08 -0500 (Mon, 08 Dec 2008)
New Revision: 3264

Modified:
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/MailTest.java
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java
Log:
Share code for SimpleMailServer creation

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/MailTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/MailTest.java	2008-12-08 11:31:42 UTC (rev 3263)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/MailTest.java	2008-12-08 11:43:08 UTC (rev 3264)
@@ -7,8 +7,6 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.jbpm.AbstractJbpmTestCase;
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmContext;
@@ -22,12 +20,10 @@
 
 public class MailTest extends AbstractJbpmTestCase
 {
-  private static Log log = LogFactory.getLog(MailTest.class);
-
   private static final int SMTP_PORT = 23583;
 
   private static SimpleSmtpServer server;
-  JbpmContext jbpmContext;
+  private JbpmContext jbpmContext;
   
   static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
     "<jbpm-configuration>" +
@@ -71,9 +67,7 @@
      * SimpleSmtpServer.start(int) blocks the calling thread until the server socket is created. If the socket is
      * created too quickly (seems to happen on Linux and Mac) then the notification is sent too early and the calling
      * thread blocks forever.
-     */
-    // return SimpleSmtpServer.start(port);
-    /*
+     * 
      * The code below corresponds to SimpleSmtpServer.start(int) except that the thread start has been moved inside of
      * the synchronized block.
      */

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java	2008-12-08 11:31:42 UTC (rev 3263)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java	2008-12-08 11:43:08 UTC (rev 3264)
@@ -4,8 +4,10 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
 import org.jbpm.AbstractJbpmTestCase;
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmContext;
@@ -28,7 +30,7 @@
 
 public class TaskMailTest extends AbstractJbpmTestCase 
 {
-  private static Log log = LogFactory.getLog(TaskMailTest.class);
+  private static final int SMTP_PORT = 23583;
 
   static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
     "<jbpm-configuration>" +
@@ -40,13 +42,28 @@
     "</jbpm-configuration>"
   );
 
-  SimpleSmtpServer server = null;
-  JbpmContext jbpmContext = null;
+  private static SimpleSmtpServer server;
+  private JbpmContext jbpmContext;
 
+  public static Test suite()
+  {
+    return new TestSetup(new TestSuite(TaskMailTest.class))
+    {
+      protected void setUp() throws Exception
+      {
+        server = MailTest.startSmtpServer(SMTP_PORT);
+      }
+
+      protected void tearDown() throws Exception
+      {
+        server.stop();
+      }
+    };
+  }
+  
   protected void setUp() throws Exception
   {
     super.setUp();
-    server = MailTest.startSmtpServer(23583);
     TestSchedulerService testSchedulerService = (TestSchedulerService) jbpmConfiguration.getServiceFactory("scheduler");
     testSchedulerService.reset();
     jbpmContext = jbpmConfiguration.createJbpmContext();
@@ -55,26 +72,21 @@
   protected void tearDown() throws Exception
   {
     jbpmContext.close();
-    try
-    {
-      server.stop();
-    }
-    catch (RuntimeException rte)
-    {
-      // This is an intermittent issue that we can safely ignore
-      log.error("Cannot stop server: " + rte);
-    }
     super.tearDown();
   }
 
-  public static class RoundRobinAssigner implements AssignmentHandler {
+  public static class RoundRobinAssigner implements AssignmentHandler
+  {
     private static final long serialVersionUID = 1L;
-    public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
+
+    public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception
+    {
       assignable.setActorId("you");
     }
   }
 
-  public void testTaskInstanceNotification() {
+  public void testTaskInstanceNotification() 
+  {
     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition>" +
       "  <start-state>" +
@@ -101,36 +113,54 @@
     assertTrue(-1!=email.getBody().indexOf("http://localhost:8080/jbpm/home?taskId=0")); 
   }
   
-  public static class TestSchedulerService implements SchedulerService, ServiceFactory {
+  public static class TestSchedulerService implements SchedulerService, ServiceFactory
+  {
     private static final long serialVersionUID = 1L;
     List createdTimers = null;
     List cancelledTimers = null;
-    public TestSchedulerService() {
+
+    public TestSchedulerService()
+    {
       reset();
     }
-    public void reset() {
+
+    public void reset()
+    {
       createdTimers = new ArrayList();
       cancelledTimers = new ArrayList();
     }
-    public void createTimer(Timer timer) {
+
+    public void createTimer(Timer timer)
+    {
       createdTimers.add(timer);
     }
-    public void deleteTimer(Timer timer) {
+
+    public void deleteTimer(Timer timer)
+    {
       cancelledTimers.add(timer.getName());
     }
-    public void deleteTimersByName(String timerName, Token token) {
+
+    public void deleteTimersByName(String timerName, Token token)
+    {
       cancelledTimers.add(timerName);
     }
-    public void deleteTimersByProcessInstance(ProcessInstance processInstance) {
+
+    public void deleteTimersByProcessInstance(ProcessInstance processInstance)
+    {
     }
-    public Service openService() {
+
+    public Service openService()
+    {
       return this;
     }
-    public void close() {
+
+    public void close()
+    {
     }
   }
 
-  public void testTaskInstanceReminder() throws Exception {
+  public void testTaskInstanceReminder() throws Exception 
+  {
     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition>" +
       "  <start-state>" +
@@ -175,9 +205,12 @@
     assertEquals(1, testSchedulerService.cancelledTimers.size());
   }
   
-  public static class GhostAssigner implements AssignmentHandler {
+  public static class GhostAssigner implements AssignmentHandler
+  {
     private static final long serialVersionUID = 1L;
-    public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
+
+    public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception
+    {
       assignable.setActorId("ghost");
     }
   }




More information about the jbpm-commits mailing list