[jboss-svn-commits] JBL Code SVN: r22740 - in labs/jbossrules/trunk/drools-process/drools-process-task/src: test/java/org/drools/task/service and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Sep 13 14:50:53 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-09-13 14:50:53 -0400 (Sat, 13 Sep 2008)
New Revision: 22740
Added:
labs/jbossrules/trunk/drools-process/drools-process-task/src/main/resources/META-INF/drools.client.conf
Modified:
labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/service/IcalTest.java
Log:
JBRULES-1745 WS-Human-Task
-Added more comprehensive testing for ICal
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/main/resources/META-INF/drools.client.conf
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/main/resources/META-INF/drools.client.conf (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/main/resources/META-INF/drools.client.conf 2008-09-13 18:50:53 UTC (rev 22740)
@@ -0,0 +1,8 @@
+from = from at domain.com
+replyTo = replyTo at domain.com
+host = localhost
+#host = smtp.corp.redhat.com
+port = 25
+defaultLanguage = en-UK
+#userName =
+#password =
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/service/IcalTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/service/IcalTest.java 2008-09-13 18:43:41 UTC (rev 22739)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/service/IcalTest.java 2008-09-13 18:50:53 UTC (rev 22740)
@@ -1,5 +1,8 @@
package org.drools.task.service;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.io.StringReader;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@@ -8,8 +11,10 @@
import java.util.List;
import java.util.Map;
+import javax.mail.BodyPart;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeMessage.RecipientType;
import org.apache.commons.collections.map.HashedMap;
@@ -23,9 +28,9 @@
public class IcalTest extends BaseTest {
MinaTaskServer server;
MinaTaskClient client;
-
- Wiser wiser;
+ Wiser wiser;
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -41,7 +46,7 @@
9123 );
client.connect( connector,
address );
-
+
wiser = new Wiser();
wiser.start();
}
@@ -50,18 +55,21 @@
super.tearDown();
client.disconnect();
server.stop();
-
+
wiser.stop();
}
-
- public void test1() throws Exception {
- Map vars = new HashedMap();
- vars.put( "users", users );
- vars.put( "groups", groups );
- vars.put( "now", new Date() );
-
- String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, createdBy = users['tony'], activationTime = now}), ";
- str += "peopleAssignments = (with ( new PeopleAssignments() ) {potentialOwners = [users['steve' ], users['tony' ]]}), ";
+
+ public void testSendWithStartandEndDeadline() throws Exception {
+ Map vars = new HashedMap();
+ vars.put( "users",
+ users );
+ vars.put( "groups",
+ groups );
+ vars.put( "now",
+ new Date() );
+
+ String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, createdBy = users['tony'], activationTime = now}), ";
+ str += "peopleAssignments = (with ( new PeopleAssignments() ) {potentialOwners = [users['steve' ], users['tony' ]]}), ";
str += "names = [ new I18NText( 'en-UK', 'This is my task name')],";
str += "subjects = [ new I18NText( 'en-UK', 'This is my task subject')],";
str += "descriptions = [ new I18NText( 'en-UK', 'This is my task description')],";
@@ -70,44 +78,351 @@
str += " (with (new Deadline()) {";
str += " date = now";
str += " } ) ],";
- str += " endDeadlines = [";
+ str += " endDeadlines = [";
str += " (with (new Deadline()) {";
str += " date = new Date( now.time + ( 1000 * 60 * * 60 * 24 ) )"; // set to tomorrow
str += " } ) ]";
str += "} ) })";
+
+ MockUserInfo userInfo = new MockUserInfo();
+ userInfo.getEmails().put( users.get( "tony" ),
+ "tony at domain.com" );
+ userInfo.getEmails().put( users.get( "steve" ),
+ "steve at domain.com" );
+
+ userInfo.getLanguages().put( users.get( "tony" ),
+ "en-UK" );
+ userInfo.getLanguages().put( users.get( "steve" ),
+ "en-UK" );
+ taskService.setUserinfo( userInfo );
+
+ BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();
+ Task task = (Task) eval( new StringReader( str ),
+ vars );
+ client.addTask( task,
+ addTaskResponseHandler );
+
+ long taskId = addTaskResponseHandler.getTaskId();
+
+ client.claim( taskId,
+ users.get( "steve" ).getId() );
+
+ Thread.sleep( 3000 );
+
+ assertEquals( 2,
+ wiser.getMessages().size() );
+ assertEquals( "steve at domain.com", wiser.getMessages().get( 0 ).getEnvelopeReceiver() );
+ assertEquals( "steve at domain.com", wiser.getMessages().get( 1 ).getEnvelopeReceiver() );
+
+ String subject = "Summary\n-------\n\nThis is my task subject\n\n";
+ String description = "Description\n-----------\n\nThis is my task description";
+
+ MimeMessage msg = ((WiserMessage) wiser.getMessages().get( 0 )).getMimeMessage();
+ assertEqualsIgnoreWhitespace( "multipart/alternative;boundary=\"----=_Part_",
+ msg.getContentType(),
+ 0,
+ 47 );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getFrom()[0]).getAddress() );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getReplyTo()[0]).getAddress() );
+ assertEquals( "steve at domain.com",
+ ((InternetAddress) msg.getRecipients( RecipientType.TO )[0]).getAddress() );
+ assertEquals( "Task Assignment Start Event: This is my task name",
+ msg.getSubject() );
+
+ MimeMultipart multiPart = (MimeMultipart) msg.getContent();
+
+ BodyPart messageBodyPart = multiPart.getBodyPart( 0 );
+ assertEquals( "text/plain; charset=UTF8;", messageBodyPart.getDataHandler().getContentType() );
+ String content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( subject + description, content );
+
+ messageBodyPart = multiPart.getBodyPart( 1 );
+ assertEquals( "text/calendar; charset=UTF8; name=ical-Start-1.ics", messageBodyPart.getDataHandler().getContentType() );
+ content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( "BEGIN:VCALENDARPRODID:-//iCal4j 1.0//ENCALSCALE:GREGORIANVERSION:2.0METHOD:REQUESTBEGIN:VEVENTDTSTART;TZID=UTC:", content.substring( 0, 123) );
+ assertEqualsIgnoreWhitespace( "SUMMARY:\"Task Start : This is my task subject\"DESCRIPTION:\"This is my task description\"PRIORITY:55END:VEVENTEND:VCALENDAR", content.substring( content.length()-131, content.length()) );
+
+
+ msg = ((WiserMessage) wiser.getMessages().get( 1 )).getMimeMessage();
+ assertEqualsIgnoreWhitespace( "multipart/alternative;boundary=\"----=_Part_",
+ msg.getContentType(),
+ 0,
+ 47 );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getFrom()[0]).getAddress() );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getReplyTo()[0]).getAddress() );
+ assertEquals( "steve at domain.com",
+ ((InternetAddress) msg.getRecipients( RecipientType.TO )[0]).getAddress() );
+ assertEquals( "Task Assignment End Event: This is my task name",
+ msg.getSubject() );
+
+ multiPart = (MimeMultipart) msg.getContent();
+
+ messageBodyPart = multiPart.getBodyPart( 0 );
+ assertEquals( "text/plain; charset=UTF8;", messageBodyPart.getDataHandler().getContentType() );
+ content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( subject + description, content );
+
+ messageBodyPart = multiPart.getBodyPart( 1 );
+ assertEquals( "text/calendar; charset=UTF8; name=ical-End-1.ics", messageBodyPart.getDataHandler().getContentType() );
+ content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( "BEGIN:VCALENDARPRODID:-//iCal4j 1.0//ENCALSCALE:GREGORIANVERSION:2.0METHOD:REQUESTBEGIN:VEVENTDTSTART;TZID=UTC:", content.substring( 0, 123) );
+ assertEqualsIgnoreWhitespace( "SUMMARY:\"Task End : This is my task subject\"DESCRIPTION:\"This is my task description\"PRIORITY:55END:VEVENTEND:VCALENDAR", content.substring( content.length()-131, content.length()) );
+ }
+
+ public void testSendWithStartDeadline() throws Exception {
+ Map vars = new HashedMap();
+ vars.put( "users",
+ users );
+ vars.put( "groups",
+ groups );
+ vars.put( "now",
+ new Date() );
+
+ String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, createdBy = users['tony'], activationTime = now}), ";
+ str += "peopleAssignments = (with ( new PeopleAssignments() ) {potentialOwners = [users['steve' ], users['tony' ]]}), ";
+ str += "names = [ new I18NText( 'en-UK', 'This is my task name')],";
+ str += "subjects = [ new I18NText( 'en-UK', 'This is my task subject')],";
+ str += "descriptions = [ new I18NText( 'en-UK', 'This is my task description')],";
+ str += "deadlines = (with (new Deadlines() ) {";
+ str += " startDeadlines = [ ";
+ str += " (with (new Deadline()) {";
+ str += " date = now";
+ str += " } ) ]";
+ str += "} ) })";
+
MockUserInfo userInfo = new MockUserInfo();
- userInfo.getEmails().put( users.get("tony"), "tony at domain.com" );
- userInfo.getEmails().put( users.get("steve"), "steve at domain.com" );
-
- userInfo.getLanguages().put( users.get("tony"), "en-UK" );
- userInfo.getLanguages().put( users.get("steve"), "en-UK" );
- taskService.setUserinfo( userInfo );
-
+ userInfo.getEmails().put( users.get( "tony" ),
+ "tony at domain.com" );
+ userInfo.getEmails().put( users.get( "steve" ),
+ "steve at domain.com" );
+
+ userInfo.getLanguages().put( users.get( "tony" ),
+ "en-UK" );
+ userInfo.getLanguages().put( users.get( "steve" ),
+ "en-UK" );
+ taskService.setUserinfo( userInfo );
+
BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();
- Task task = ( Task ) eval( new StringReader( str ), vars );
- client.addTask( task, addTaskResponseHandler );
+ Task task = (Task) eval( new StringReader( str ),
+ vars );
+ client.addTask( task,
+ addTaskResponseHandler );
+
+ long taskId = addTaskResponseHandler.getTaskId();
+
+ client.claim( taskId,
+ users.get( "steve" ).getId() );
+
+ Thread.sleep( 3000 );
+
+ assertEquals( 1,
+ wiser.getMessages().size() );
+
+ assertEquals( "steve at domain.com", wiser.getMessages().get( 0 ).getEnvelopeReceiver() );
+
+ String subject = "Summary\n-------\n\nThis is my task subject\n\n";
+ String description = "Description\n-----------\n\nThis is my task description";
+
+ MimeMessage msg = ((WiserMessage) wiser.getMessages().get( 0 )).getMimeMessage();
+ assertEqualsIgnoreWhitespace( "multipart/alternative;boundary=\"----=_Part_",
+ msg.getContentType(),
+ 0,
+ 47 );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getFrom()[0]).getAddress() );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getReplyTo()[0]).getAddress() );
+ assertEquals( "steve at domain.com",
+ ((InternetAddress) msg.getRecipients( RecipientType.TO )[0]).getAddress() );
+ assertEquals( "Task Assignment Start Event: This is my task name",
+ msg.getSubject() );
- long taskId = addTaskResponseHandler.getTaskId();
+ MimeMultipart multiPart = (MimeMultipart) msg.getContent();
+
+ BodyPart messageBodyPart = multiPart.getBodyPart( 0 );
+ assertEquals( "text/plain; charset=UTF8;", messageBodyPart.getDataHandler().getContentType() );
+ String content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( subject + description, content );
- client.claim( taskId, users.get( "steve" ).getId() );
+ messageBodyPart = multiPart.getBodyPart( 1 );
+ assertEquals( "text/calendar; charset=UTF8; name=ical-Start-1.ics", messageBodyPart.getDataHandler().getContentType() );
+ content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( "BEGIN:VCALENDARPRODID:-//iCal4j 1.0//ENCALSCALE:GREGORIANVERSION:2.0METHOD:REQUESTBEGIN:VEVENTDTSTART;TZID=UTC:", content.substring( 0, 123) );
+ assertEqualsIgnoreWhitespace( "SUMMARY:\"Task Start : This is my task subject\"DESCRIPTION:\"This is my task description\"PRIORITY:55END:VEVENTEND:VCALENDAR", content.substring( content.length()-131, content.length()) );
+ }
+
+ private static void assertEqualsIgnoreWhitespace(final String expected,
+ final String actual) {
+ assertEqualsIgnoreWhitespace(expected, actual, 0, actual.length());
+ }
+
+ private static void assertEqualsIgnoreWhitespace(final String expected,
+ final String actual,
+ int beginIndex,
+ int endIndex) {
+ final String cleanExpected = expected.replaceAll( "\\s+",
+ "" ).replaceAll( "\\n", "" ).replaceAll( "\\r", "" );
+ final String cleanActual = actual.substring( beginIndex,
+ endIndex ).replaceAll( "\\s+",
+ "" ).replaceAll( "\\n", "" ).replaceAll( "\\r", "" );
+ System.out.println( cleanActual );
+ assertEquals( cleanExpected,
+ cleanActual );
+ }
+
+ public void testSendWithEndDeadline() throws Exception {
+ Map vars = new HashedMap();
+ vars.put( "users",
+ users );
+ vars.put( "groups",
+ groups );
+ vars.put( "now",
+ new Date() );
+
+ String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, createdBy = users['tony'], activationTime = now}), ";
+ str += "peopleAssignments = (with ( new PeopleAssignments() ) {potentialOwners = [users['steve' ], users['tony' ]]}), ";
+ str += "names = [ new I18NText( 'en-UK', 'This is my task name')],";
+ str += "subjects = [ new I18NText( 'en-UK', 'This is my task subject')],";
+ str += "descriptions = [ new I18NText( 'en-UK', 'This is my task description')],";
+ str += "deadlines = (with (new Deadlines() ) {";
+ str += " endDeadlines = [";
+ str += " (with (new Deadline()) {";
+ str += " date = new Date( now.time + ( 1000 * 60 * * 60 * 24 ) )"; // set to tomorrow
+ str += " } ) ]";
+ str += "} ) })";
+
+ MockUserInfo userInfo = new MockUserInfo();
+ userInfo.getEmails().put( users.get( "tony" ),
+ "tony at domain.com" );
+ userInfo.getEmails().put( users.get( "steve" ),
+ "steve at domain.com" );
+
+ userInfo.getLanguages().put( users.get( "tony" ),
+ "en-UK" );
+ userInfo.getLanguages().put( users.get( "steve" ),
+ "en-UK" );
+ taskService.setUserinfo( userInfo );
+
+ BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();
+ Task task = (Task) eval( new StringReader( str ),
+ vars );
+ client.addTask( task,
+ addTaskResponseHandler );
+
+ long taskId = addTaskResponseHandler.getTaskId();
+
+ client.claim( taskId,
+ users.get( "steve" ).getId() );
+
Thread.sleep( 3000 );
+
+ assertEquals( 1,
+ wiser.getMessages().size() );
- assertEquals(2, wiser.getMessages().size() );
+ assertEquals( "steve at domain.com", wiser.getMessages().get( 0 ).getEnvelopeReceiver() );
+
+ String subject = "Summary\n-------\n\nThis is my task subject\n\n";
+ String description = "Description\n-----------\n\nThis is my task description";
+
+ MimeMessage msg = ((WiserMessage) wiser.getMessages().get( 0 )).getMimeMessage();
+ assertEqualsIgnoreWhitespace( "multipart/alternative;boundary=\"----=_Part_",
+ msg.getContentType(),
+ 0,
+ 47 );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getFrom()[0]).getAddress() );
+ assertEquals( "tony at domain.com",
+ ((InternetAddress) msg.getReplyTo()[0]).getAddress() );
+ assertEquals( "steve at domain.com",
+ ((InternetAddress) msg.getRecipients( RecipientType.TO )[0]).getAddress() );
+ assertEquals( "Task Assignment End Event: This is my task name",
+ msg.getSubject() );
- List<String> list = new ArrayList<String>(2);
- list.add( wiser.getMessages().get( 0 ).getEnvelopeReceiver() );
- list.add( wiser.getMessages().get( 1 ).getEnvelopeReceiver() );
+ MimeMultipart multiPart = (MimeMultipart) msg.getContent();
+
+ BodyPart messageBodyPart = multiPart.getBodyPart( 0 );
+ assertEquals( "text/plain; charset=UTF8;", messageBodyPart.getDataHandler().getContentType() );
+ String content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( subject + description, content );
- assertTrue( list.contains("steve at domain.com"));
- assertTrue( list.contains("steve at domain.com"));
- MimeMessage msg = (( WiserMessage ) wiser.getMessages().get( 0 )).getMimeMessage();
+ messageBodyPart = multiPart.getBodyPart( 1 );
+ assertEquals( "text/calendar; charset=UTF8; name=ical-End-1.ics", messageBodyPart.getDataHandler().getContentType() );
+ content = new String( getBytes( messageBodyPart.getDataHandler().getInputStream() ) );
+ assertEqualsIgnoreWhitespace( "BEGIN:VCALENDARPRODID:-//iCal4j 1.0//ENCALSCALE:GREGORIANVERSION:2.0METHOD:REQUESTBEGIN:VEVENTDTSTART;TZID=UTC:", content.substring( 0, 123) );
+ assertEqualsIgnoreWhitespace( "SUMMARY:\"Task End : This is my task subject\"DESCRIPTION:\"This is my task description\"PRIORITY:55END:VEVENTEND:VCALENDAR", content.substring( content.length()-131, content.length()) );
+ }
+
+ public void testSendWithNoDeadline() throws Exception {
+ Map vars = new HashedMap();
+ vars.put( "users",
+ users );
+ vars.put( "groups",
+ groups );
+ vars.put( "now",
+ new Date() );
+
+ String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, createdBy = users['tony'], activationTime = now}), ";
+ str += "peopleAssignments = (with ( new PeopleAssignments() ) {potentialOwners = [users['steve' ], users['tony' ]]}), ";
+ str += "names = [ new I18NText( 'en-UK', 'This is my task name')],";
+ str += "subjects = [ new I18NText( 'en-UK', 'This is my task subject')],";
+ str += "descriptions = [ new I18NText( 'en-UK', 'This is my task description')]";
+ str += "})";
+
+ MockUserInfo userInfo = new MockUserInfo();
+ userInfo.getEmails().put( users.get( "tony" ),
+ "tony at domain.com" );
+ userInfo.getEmails().put( users.get( "steve" ),
+ "steve at domain.com" );
+
+ userInfo.getLanguages().put( users.get( "tony" ),
+ "en-UK" );
+ userInfo.getLanguages().put( users.get( "steve" ),
+ "en-UK" );
+ taskService.setUserinfo( userInfo );
+
+ BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();
+ Task task = (Task) eval( new StringReader( str ),
+ vars );
+ client.addTask( task,
+ addTaskResponseHandler );
+
+ long taskId = addTaskResponseHandler.getTaskId();
+
+ client.claim( taskId,
+ users.get( "steve" ).getId() );
+
+ Thread.sleep( 3000 );
+
+ assertEquals( 0,
+ wiser.getMessages().size() );
+ }
+
+ private static byte[] getBytes(InputStream inputStream) throws Exception {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
+ byte[] bytes = new byte[512];
+
+ // Read bytes from the input stream in bytes.length-sized chunks and write
+ // them into the output stream
+ int readBytes;
+ while ((readBytes = inputStream.read(bytes)) > 0) {
+ outputStream.write(bytes, 0, readBytes);
+ }
+
+ // Convert the contents of the output stream into a byte array
+ byte[] byteData = outputStream.toByteArray();
-// assertEquals( "My Body", msg.getContent() );
-// assertEquals( "My Subject", msg.getSubject() );
- assertEquals( "tony at domain.com", ((InternetAddress)msg.getFrom()[0]).getAddress() );
- assertEquals( "tony at domain.com", ((InternetAddress)msg.getReplyTo()[0]).getAddress() );
- assertEquals( "steve at domain.com", ((InternetAddress)msg.getRecipients( RecipientType.TO )[0]).getAddress() );
+ // Close the streams
+ inputStream.close();
+ outputStream.close();
+
+ return byteData;
+
}
+
}
More information about the jboss-svn-commits
mailing list