Commits

Micha Kops committed 68f7574

Greenmail library for e-mail process testing and test example added.

Comments (0)

Files changed (4)

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>com.hascode.tutorial</groupId>
-  <artifactId>activiti-bpmn2-tutorial</artifactId>
-  <version>1.0.0</version>
-  <packaging>jar</packaging>
-  <name>hasCode.com Activiti BPMN2 - Example</name>
-  <properties>
-    <activiti-version>5.11</activiti-version>
-  </properties>
-  <dependencies>
-    <dependency>
-      <groupId>org.activiti</groupId>
-      <artifactId>activiti-engine</artifactId>
-      <version>${activiti-version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.activiti</groupId>
-      <artifactId>activiti-spring</artifactId>
-      <version>${activiti-version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.groovy</groupId>
-      <artifactId>groovy-all</artifactId>
-      <version>2.0.4</version>
-    </dependency>
-    <dependency>
-      <groupId>com.h2database</groupId>
-      <artifactId>h2</artifactId>
-      <version>1.3.168</version>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-    </dependency>
-    <dependency>
-    	<groupId>org.hamcrest</groupId>
-    	<artifactId>hamcrest-all</artifactId>
-    	<version>1.3</version>
-    	<scope>test</scope>
-    </dependency>
-  </dependencies>
-	 <repositories>
-    <repository>
-      <id>Activiti</id>
-      <url>http://maven.alfresco.com/nexus/content/repositories/activiti</url>
-	   </repository>
-	 </repositories>
-	 <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-	       <version>2.3.2</version>
-        <configuration>
-	         <source>1.6</source>
-	         <target>1.6</target>
-	       </configuration>
-	     </plugin>
-	     <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-eclipse-plugin</artifactId>
-        <inherited>true</inherited>
-        <configuration>
-	         <classpathContainers>
-	           <classpathContainer>org.eclipse.jdt.USER_LIBRARY/Activiti Designer Extensions</classpathContainer>
-	         </classpathContainers>
-	       </configuration>
-	     </plugin>
-    </plugins>
-	 </build>
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>activiti-bpmn2-tutorial</artifactId>
+	<version>1.0.0</version>
+	<packaging>jar</packaging>
+	<name>hasCode.com Activiti BPMN2 - Example</name>
+	<properties>
+		<activiti-version>5.11</activiti-version>
+	</properties>
+	<dependencies>
+		<dependency>
+			<groupId>org.activiti</groupId>
+			<artifactId>activiti-engine</artifactId>
+			<version>${activiti-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.activiti</groupId>
+			<artifactId>activiti-spring</artifactId>
+			<version>${activiti-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.codehaus.groovy</groupId>
+			<artifactId>groovy-all</artifactId>
+			<version>2.0.4</version>
+		</dependency>
+		<dependency>
+			<groupId>com.h2database</groupId>
+			<artifactId>h2</artifactId>
+			<version>1.3.168</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.11</version>
+		</dependency>
+		<dependency>
+			<groupId>org.hamcrest</groupId>
+			<artifactId>hamcrest-all</artifactId>
+			<version>1.3</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.icegreen</groupId>
+			<artifactId>greenmail</artifactId>
+			<version>1.3</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	<repositories>
+		<repository>
+			<id>Activiti</id>
+			<url>http://maven.alfresco.com/nexus/content/repositories/activiti</url>
+		</repository>
+	</repositories>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-eclipse-plugin</artifactId>
+				<inherited>true</inherited>
+				<configuration>
+					<classpathContainers>
+						<classpathContainer>org.eclipse.jdt.USER_LIBRARY/Activiti Designer
+							Extensions</classpathContainer>
+					</classpathContainers>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 </project>

src/test/java/it/IssueRequestProcessTest.java

 package it;
 
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.endsWith;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThan;
 import java.util.List;
 import java.util.Map;
 
+import javax.mail.internet.MimeMessage;
+
 import org.activiti.engine.FormService;
 import org.activiti.engine.TaskService;
 import org.activiti.engine.form.FormProperty;
 import org.activiti.engine.task.Task;
 import org.activiti.engine.test.ActivitiRule;
 import org.activiti.engine.test.Deployment;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import com.icegreen.greenmail.util.GreenMail;
+import com.icegreen.greenmail.util.ServerSetupTest;
+
 public class IssueRequestProcessTest {
 	private static final String DESCRIPTION_VALUE = "When I'm adding articles to the basket and click on 'buy' I'm getting a 404 error. I hate your fucking shop!";
 	private static final String DESCRIPTION_KEY = "description";
 	private static final String SUMMARY_VALUE = "Website Error! Shop order failed";
 	private static final String SUMMARY_KEY = "summary";
+
+	GreenMail smtpServer = new GreenMail(ServerSetupTest.SMTP);
+
 	@Rule
 	public ActivitiRule activitiRule = new ActivitiRule(
 			"activiti-test.inmemory-cfg.xml");
 
+	@Before
+	public void setUp() {
+		smtpServer.start();
+	}
+
+	@After
+	public void tearDown() {
+		smtpServer.stop();
+	}
+
 	@Test
 	@Deployment(resources = "diagrams/IssueRequestProcess.bpmn")
-	public void shouldProcessCriticalIssueRequest() {
+	public void shouldProcessCriticalIssueRequest() throws Exception {
 		ProcessDefinition definition = activitiRule.getRepositoryService()
 				.createProcessDefinitionQuery()
 				.processDefinitionKey("issueRequestProcess").singleResult();
 		Map<String, Object> taskParams = new HashMap<String, Object>();
 		taskParams.put("requestApproved", "true");
 		taskService.complete(approveCriticalIssueTask.getId(), taskParams);
+
+		smtpServer.waitForIncomingEmail(5000L, 1);
+		MimeMessage[] messages = smtpServer.getReceivedMessages();
+		assertThat(messages.length, equalTo(1));
+		MimeMessage mail = messages[0];
+		assertThat(mail.getSubject(), equalTo("Your inquiry regarding "
+				+ SUMMARY_VALUE));
+		assertThat((String) mail.getContent(), containsString(SUMMARY_VALUE));
 	}
 }

src/test/resources/activiti-test.inmemory-cfg.xml

 	<bean id="processEngineConfiguration"
 		class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
 		<property name="databaseSchemaUpdate" value="true" />
-		<property name="mailServerPort" value="1025" />
+		<property name="mailServerPort" value="3025" />
 		<property name="jobExecutorActivate" value="false" />
 	</bean>
 </beans>

src/test/resources/activiti.cfg.xml

-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-		xsi:schemaLocation="http://www.springframework.org/schema/beans
-				http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-	<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
-		<property name="databaseSchemaUpdate" value="true"/>
-	</bean>
-</beans>