Author: norman Date: Fri Jun 2 15:40:04 2006 New Revision: 411321 URL: http://svn.apache.org/viewvc?rev=411321&view=rev Log: -Add junit test for SetMailAttribute mailet -Remove not needed code from matcher junit tests
Added: james/server/trunk/src/test/org/apache/james/transport/mailets/SetMailAttributeTest.java Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsTest.java james/server/trunk/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java Added: james/server/trunk/src/test/org/apache/james/transport/mailets/SetMailAttributeTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/mailets/SetMailAttributeTest.java?rev=411321&view=auto ============================================================================== --- james/server/trunk/src/test/org/apache/james/transport/mailets/SetMailAttributeTest.java (added) +++ james/server/trunk/src/test/org/apache/james/transport/mailets/SetMailAttributeTest.java Fri Jun 2 15:40:04 2006 @@ -0,0 +1,83 @@ +/*********************************************************************** + * Copyright (c) 2006 The Apache Software Foundation. * + * All rights reserved. * + * ------------------------------------------------------------------- * + * Licensed under the Apache License, Version 2.0 (the "License"); you * + * may not use this file except in compliance with the License. You * + * may obtain a copy of the License at: * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * + * implied. See the License for the specific language governing * + * permissions and limitations under the License. * + ***********************************************************************/ + +package org.apache.james.transport.mailets; + +import org.apache.james.test.mock.mailet.MockMail; +import org.apache.james.test.mock.mailet.MockMailContext; +import org.apache.james.test.mock.mailet.MockMailetConfig; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +import org.apache.mailet.Mailet; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.ParseException; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import junit.framework.TestCase; + +public class SetMailAttributeTest extends TestCase { + + private MimeMessage mockedMimeMessage; + + private Mail mockedMail; + + private Mailet mailet; + + private final String ATTRIBUTE_NAME1 = "org.apache.james.junit1"; + + private final String ATTRIBUTE_NAME2 = "org.apache.james.junit2"; + + public SetMailAttributeTest(String arg0) + throws UnsupportedEncodingException { + super(arg0); + } + + private void setupMockedMail(MimeMessage m) throws ParseException { + mockedMail = new MockMail(); + mockedMail.setMessage(m); + mockedMail.setRecipients(Arrays.asList(new MailAddress[] { + new MailAddress("[EMAIL PROTECTED]"), + new MailAddress("[EMAIL PROTECTED]") })); + } + + private void setupMailet() throws MessagingException { + mailet = new SetMailAttribute(); + MockMailetConfig mci = new MockMailetConfig("Test", + new MockMailContext()); + mci.setProperty(ATTRIBUTE_NAME1, "true"); + mci.setProperty(ATTRIBUTE_NAME2, "true"); + + mailet.init(mci); + } + + // test if the Header was add + public void testMailAttributeAdded() throws MessagingException { + setupMockedMail(mockedMimeMessage); + setupMailet(); + + assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME1)); + assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME2)); + mailet.service(mockedMail); + + assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME1)); + assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME2)); + } +} Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java?rev=411321&r1=411320&r2=411321&view=diff ============================================================================== --- james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java (original) +++ james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java Fri Jun 2 15:40:04 2006 @@ -17,7 +17,6 @@ package org.apache.james.transport.matchers; -import org.apache.james.test.mock.javaxmail.MockMimeMessage; import org.apache.james.test.mock.mailet.MockMail; import org.apache.james.test.mock.mailet.MockMatcherConfig; @@ -27,9 +26,7 @@ import org.apache.mailet.Matcher; import javax.mail.MessagingException; -import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; import java.io.UnsupportedEncodingException; import java.util.ArrayList; @@ -41,8 +38,6 @@ public class HostIsLocalTest extends TestCase { - private MimeMessage mockedMimeMessage; - private MockMail mockedMail; private Matcher matcher; @@ -59,22 +54,8 @@ this.recipients = recipients; } - private void setupMockedMimeMessage() throws MessagingException { - String sender = "[EMAIL PROTECTED]"; - String rcpt = "[EMAIL PROTECTED]"; - - mockedMimeMessage = new MockMimeMessage(); - mockedMimeMessage.setFrom(new InternetAddress(sender)); - mockedMimeMessage.setRecipients(RecipientType.TO, rcpt); - mockedMimeMessage.setSubject("testmail"); - mockedMimeMessage.setText("testtext"); - mockedMimeMessage.saveChanges(); - - } - - private void setupMockedMail(MimeMessage m) { + private void setupMockedMail() { mockedMail = new MockMail(); - mockedMail.setMessage(m); mockedMail.setRecipients(Arrays.asList(recipients)); } @@ -203,7 +184,6 @@ }; - setupMockedMimeMessage(); matcher = new HostIsLocal(); MockMatcherConfig mci = new MockMatcherConfig("HostIsLocal", mockMailContext); @@ -216,8 +196,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -233,8 +212,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -249,8 +227,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsTest.java?rev=411321&r1=411320&r2=411321&view=diff ============================================================================== --- james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsTest.java (original) +++ james/server/trunk/src/test/org/apache/james/transport/matchers/HostIsTest.java Fri Jun 2 15:40:04 2006 @@ -17,7 +17,6 @@ package org.apache.james.transport.matchers; -import org.apache.james.test.mock.javaxmail.MockMimeMessage; import org.apache.james.test.mock.mailet.MockMail; import org.apache.james.test.mock.mailet.MockMailContext; import org.apache.james.test.mock.mailet.MockMatcherConfig; @@ -26,9 +25,6 @@ import org.apache.mailet.Matcher; import javax.mail.MessagingException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; import java.io.UnsupportedEncodingException; import java.util.Arrays; @@ -38,8 +34,6 @@ public class HostIsTest extends TestCase { - private MimeMessage mockedMimeMessage; - private MockMail mockedMail; private Matcher matcher; @@ -56,28 +50,13 @@ this.recipients = recipients; } - private void setupMockedMimeMessage() throws MessagingException { - String sender = "[EMAIL PROTECTED]"; - String rcpt = "[EMAIL PROTECTED]"; - - mockedMimeMessage = new MockMimeMessage(); - mockedMimeMessage.setFrom(new InternetAddress(sender)); - mockedMimeMessage.setRecipients(RecipientType.TO, rcpt); - mockedMimeMessage.setSubject("testmail"); - mockedMimeMessage.setText("testtext"); - mockedMimeMessage.saveChanges(); - - } - - private void setupMockedMail(MimeMessage m) { + private void setupMockedMail() { mockedMail = new MockMail(); - mockedMail.setMessage(m); mockedMail.setRecipients(Arrays.asList(recipients)); } private void setupMatcher() throws MessagingException { - setupMockedMimeMessage(); matcher = new HostIs(); MockMatcherConfig mci = new MockMatcherConfig("HostIs=" + HOST_NAME, new MockMailContext()); @@ -90,8 +69,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -107,8 +85,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -123,8 +100,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java?rev=411321&r1=411320&r2=411321&view=diff ============================================================================== --- james/server/trunk/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java (original) +++ james/server/trunk/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java Fri Jun 2 15:40:04 2006 @@ -17,7 +17,6 @@ package org.apache.james.transport.matchers; -import org.apache.james.test.mock.javaxmail.MockMimeMessage; import org.apache.james.test.mock.mailet.MockMail; import org.apache.james.test.mock.mailet.MockMailContext; import org.apache.james.test.mock.mailet.MockMatcherConfig; @@ -26,9 +25,6 @@ import org.apache.mailet.Matcher; import javax.mail.MessagingException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; import java.io.UnsupportedEncodingException; import java.util.Arrays; @@ -38,8 +34,6 @@ public class IsSingleRecipientTest extends TestCase { - private MimeMessage mockedMimeMessage; - private MockMail mockedMail; private Matcher matcher; @@ -55,22 +49,8 @@ this.recipients = recipients; } - private void setupMockedMimeMessage() throws MessagingException { - String sender = "[EMAIL PROTECTED]"; - String rcpt = "[EMAIL PROTECTED]"; - - mockedMimeMessage = new MockMimeMessage(); - mockedMimeMessage.setFrom(new InternetAddress(sender)); - mockedMimeMessage.setRecipients(RecipientType.TO, rcpt); - mockedMimeMessage.setSubject("testmail"); - mockedMimeMessage.setText("testtext"); - mockedMimeMessage.saveChanges(); - - } - - private void setupMockedMail(MimeMessage m) { + private void setupMockedMail() { mockedMail = new MockMail(); - mockedMail.setMessage(m); mockedMail.setRecipients(Arrays.asList(recipients)); } @@ -88,8 +68,7 @@ setRecipients(new MailAddress[] { new MailAddress( "[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -103,8 +82,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java?rev=411321&r1=411320&r2=411321&view=diff ============================================================================== --- james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java (original) +++ james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java Fri Jun 2 15:40:04 2006 @@ -17,28 +17,21 @@ package org.apache.james.transport.matchers; -import org.apache.james.test.mock.javaxmail.MockMimeMessage; -import org.apache.james.test.mock.mailet.MockMail; -import org.apache.james.test.mock.mailet.MockMailContext; -import org.apache.james.test.mock.mailet.MockMatcherConfig; - -import org.apache.mailet.MailAddress; -import org.apache.mailet.Matcher; - -import javax.mail.MessagingException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; - import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Collection; +import javax.mail.MessagingException; + import junit.framework.TestCase; -public class RecipientIsRegexTest extends TestCase { +import org.apache.james.test.mock.mailet.MockMail; +import org.apache.james.test.mock.mailet.MockMailContext; +import org.apache.james.test.mock.mailet.MockMatcherConfig; +import org.apache.mailet.MailAddress; +import org.apache.mailet.Matcher; - private MimeMessage mockedMimeMessage; +public class RecipientIsRegexTest extends TestCase { private MockMail mockedMail; @@ -61,28 +54,13 @@ this.regex = regex; } - private void setupMockedMimeMessage() throws MessagingException { - String sender = "[EMAIL PROTECTED]"; - String rcpt = "[EMAIL PROTECTED]"; - - mockedMimeMessage = new MockMimeMessage(); - mockedMimeMessage.setFrom(new InternetAddress(sender)); - mockedMimeMessage.setRecipients(RecipientType.TO, rcpt); - mockedMimeMessage.setSubject("testmail"); - mockedMimeMessage.setText("testtext"); - mockedMimeMessage.saveChanges(); - - } - - private void setupMockedMail(MimeMessage m) { + private void setupMockedMail() { mockedMail = new MockMail(); - mockedMail.setMessage(m); mockedMail.setRecipients(Arrays.asList(recipients)); } private void setupMatcher() throws MessagingException { - setupMockedMimeMessage(); matcher = new RecipientIsRegex(); MockMatcherConfig mci = new MockMatcherConfig("RecipientIsRegex=" + regex, new MockMailContext()); @@ -94,8 +72,7 @@ setRecipients(new MailAddress[] { new MailAddress( "[EMAIL PROTECTED]") }); setRegex("[EMAIL PROTECTED]"); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -111,8 +88,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); setRegex("[EMAIL PROTECTED]"); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -127,8 +103,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); setRegex(".*\\+"); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -148,8 +123,7 @@ new MailAddress("[EMAIL PROTECTED]") }); setRegex(invalidRegex); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); try { setupMatcher(); @@ -158,7 +132,7 @@ m.printStackTrace(); regexException = m.getMessage(); } - + assertNull(matchedRecipients); assertEquals(regexException, exception); Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java?rev=411321&r1=411320&r2=411321&view=diff ============================================================================== --- james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java (original) +++ james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java Fri Jun 2 15:40:04 2006 @@ -17,29 +17,22 @@ package org.apache.james.transport.matchers; -import org.apache.james.test.mock.javaxmail.MockMimeMessage; -import org.apache.james.test.mock.mailet.MockMail; -import org.apache.james.test.mock.mailet.MockMailContext; -import org.apache.james.test.mock.mailet.MockMatcherConfig; - -import org.apache.mailet.MailAddress; -import org.apache.mailet.Matcher; - -import javax.mail.MessagingException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; - import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Collection; -import junit.framework.TestCase; +import javax.mail.MessagingException; -public class RecipientIsTest extends TestCase { +import junit.framework.TestCase; - private MimeMessage mockedMimeMessage; +import org.apache.james.test.mock.mailet.MockMail; +import org.apache.james.test.mock.mailet.MockMailContext; +import org.apache.james.test.mock.mailet.MockMatcherConfig; +import org.apache.mailet.MailAddress; +import org.apache.mailet.Matcher; +public class RecipientIsTest extends TestCase { + private MockMail mockedMail; private Matcher matcher; @@ -56,28 +49,13 @@ this.recipients = recipients; } - private void setupMockedMimeMessage() throws MessagingException { - String sender = "[EMAIL PROTECTED]"; - String rcpt = "[EMAIL PROTECTED]"; - - mockedMimeMessage = new MockMimeMessage(); - mockedMimeMessage.setFrom(new InternetAddress(sender)); - mockedMimeMessage.setRecipients(RecipientType.TO, rcpt); - mockedMimeMessage.setSubject("testmail"); - mockedMimeMessage.setText("testtext"); - mockedMimeMessage.saveChanges(); - - } - - private void setupMockedMail(MimeMessage m) { + private void setupMockedMail() { mockedMail = new MockMail(); - mockedMail.setMessage(m); mockedMail.setRecipients(Arrays.asList(recipients)); } private void setupMatcher() throws MessagingException { - setupMockedMimeMessage(); matcher = new RecipientIs(); MockMatcherConfig mci = new MockMatcherConfig("RecipientIs=" + RECIPIENT_NAME, new MockMailContext()); @@ -89,8 +67,7 @@ setRecipients(new MailAddress[] { new MailAddress( "[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -106,8 +83,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); @@ -122,8 +98,7 @@ new MailAddress("[EMAIL PROTECTED]"), new MailAddress("[EMAIL PROTECTED]") }); - setupMockedMimeMessage(); - setupMockedMail(mockedMimeMessage); + setupMockedMail(); setupMatcher(); Collection matchedRecipients = matcher.match(mockedMail); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]