Author: norman
Date: Sat Jan 8 14:33:29 2011
New Revision: 1056715
URL: http://svn.apache.org/viewvc?rev=1056715&view=rev
Log:
One more unit test for CamelMailProcessor
Modified:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
Modified:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java?rev=1056715&r1=1056714&r2=1056715&view=diff
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
(original)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
Sat Jan 8 14:33:29 2011
@@ -46,10 +46,10 @@ public abstract class AbstractStateMaile
- private HierarchicalConfiguration createConfig() throws
ConfigurationException {
+ private HierarchicalConfiguration createConfig(int count) throws
ConfigurationException {
StringBuilder sb = new StringBuilder();
sb.append("<processor state=\"" + Mail.DEFAULT + "\">");
- sb.append("<mailet
match=\"").append(MockMatcher.class.getName()).append("=t...@localhost\"").append("
class=\"").append(MockMailet.class.getName()).append("\">");
+ sb.append("<mailet
match=\"").append(MockMatcher.class.getName()).append("=").append(count).append("\"").append("
class=\"").append(MockMailet.class.getName()).append("\">");
sb.append("<state>test</state>");
sb.append("</mailet>");
@@ -67,7 +67,7 @@ public abstract class AbstractStateMaile
mail.setSender(new MailAddress("t...@localhost"));
mail.setRecipients(Arrays.asList(new MailAddress("t...@localhost"),
new MailAddress("te...@localhost")));
- AbstractStateMailetProcessor processor =
createProcessor(createConfig());
+ AbstractStateMailetProcessor processor =
createProcessor(createConfig(1));
processor.addListener(new MailetProcessorListener() {
public void afterMatcher(Matcher m, String mailName,
Collection<MailAddress> recipients, Collection<MailAddress> matches, long
processTime, MessagingException e) {
@@ -100,6 +100,51 @@ public abstract class AbstractStateMaile
// the source mail should be ghosted as it reached the end of
processor as only one recipient matched
assertEquals(Mail.GHOST, mail.getState());
latch.await();
+ processor.destroy();
+
+ }
+
+ public void testSimpleRoutingMatchAll() throws ConfigurationException,
Exception {
+ final CountDownLatch latch = new CountDownLatch(2);
+ final MailImpl mail = new MailImpl();
+ mail.setName(MailImpl.getId());
+ mail.setSender(new MailAddress("t...@localhost"));
+ mail.setRecipients(Arrays.asList(new MailAddress("t...@localhost"),
new MailAddress("te...@localhost")));
+
+ AbstractStateMailetProcessor processor =
createProcessor(createConfig(2));
+ processor.addListener(new MailetProcessorListener() {
+
+ public void afterMatcher(Matcher m, String mailName,
Collection<MailAddress> recipients, Collection<MailAddress> matches, long
processTime, MessagingException e) {
+ if (MockMatcher.class.equals(m.getClass())) {
+ assertEquals(mail.getName(), mailName);
+ // match one recipient
+ assertEquals(2, matches.size());
+ assertNull(e);
+ latch.countDown();
+ }
+
+ }
+
+ public void afterMailet(Mailet m, String mailName, String state,
long processTime, MessagingException e) {
+ // check for class name as the terminating mailet will kick
in too
+
+ if (MockMailet.class.equals(m.getClass())) {
+ //assertEquals(mail.getName(), mailName);
+ assertEquals("test", state);
+ assertNull(e);
+ latch.countDown();
+ }
+ }
+ });
+
+ assertEquals(Mail.DEFAULT, mail.getState());
+ processor.service(mail);
+
+
+ // the source mail should have the new state as it was a full match
+ assertEquals("test", mail.getState());
+ latch.await();
+ processor.destroy();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]