james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r412433 - in /james/server/trunk/src/test/org/apache/james/transport/matchers: AbstractSubjectIsTest.java SubjectIsTest.java SubjectStartsWithTest.java
Date Wed, 07 Jun 2006 15:48:03 GMT
Author: norman
Date: Wed Jun  7 08:48:02 2006
New Revision: 412433

URL: http://svn.apache.org/viewvc?rev=412433&view=rev
Log:
Junit tests for SubjectIs and SubjectStartsWith matcher

Added:
    james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectIsTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectStartsWithTest.java

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSubjectIsTest.java?rev=412433&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
Wed Jun  7 08:48:02 2006
@@ -0,0 +1,93 @@
+/***********************************************************************
+ * 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.matchers;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import junit.framework.TestCase;
+
+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.Matcher;
+
+public abstract class AbstractSubjectIsTest extends TestCase {
+
+    protected MockMail mockedMail;
+
+    protected Matcher matcher;
+
+    private String subject = null;
+
+    private MockMimeMessage mockedMimeMessage;
+
+    public AbstractSubjectIsTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    protected void setSubject(String subject) {
+        this.subject = subject;
+    }
+
+    protected void setupMockedMail(MimeMessage m) {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+
+    }
+
+    protected void setupMockedMimeMessage() throws MessagingException {
+        String sender = "test@james.apache.org";
+        String rcpt = "test2@james.apache.org";
+
+        mockedMimeMessage = new MockMimeMessage();
+        mockedMimeMessage.setFrom(new InternetAddress(sender));
+        mockedMimeMessage.setRecipients(RecipientType.TO, rcpt);
+        if (subject != null) {
+            mockedMimeMessage.setSubject(subject);
+        }
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    protected void setupMatcher() throws MessagingException {
+        matcher = createMatcher();
+        MockMatcherConfig mci = new MockMatcherConfig(getConfigOption()
+                + getSubjectName(), new MockMailContext());
+        matcher.init(mci);
+    }
+
+    protected void setupAll() throws MessagingException {
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+    }
+
+    protected abstract String getConfigOption();
+
+    protected abstract String getSubjectName();
+
+    protected abstract Matcher createMatcher();
+}

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectIsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectIsTest.java?rev=412433&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectIsTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectIsTest.java Wed
Jun  7 08:48:02 2006
@@ -0,0 +1,70 @@
+/***********************************************************************
+ * 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.matchers;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Matcher;
+
+public class SubjectIsTest extends AbstractSubjectIsTest {
+
+    private final String SUBJECT_NAME = "testSubject";
+
+    public SubjectIsTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    // test if the recipients get returned as matched
+    public void testHostIsMatchedAllRecipients() throws MessagingException {
+        setSubject(SUBJECT_NAME);
+
+        setupAll();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if no recipient get returned cause it not match
+    public void testHostIsNotMatch() throws MessagingException {
+        setSubject("test");
+
+        setupAll();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+
+    protected Matcher createMatcher() {
+        return new SubjectIs();
+    }
+
+    protected String getConfigOption() {
+        return "SubjectIs=";
+    }
+
+    protected String getSubjectName() {
+        return SUBJECT_NAME;
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectStartsWithTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectStartsWithTest.java?rev=412433&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectStartsWithTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/SubjectStartsWithTest.java
Wed Jun  7 08:48:02 2006
@@ -0,0 +1,71 @@
+/***********************************************************************
+ * 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.matchers;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Matcher;
+
+public class SubjectStartsWithTest extends AbstractSubjectIsTest {
+
+    private final String SUBJECT_NAME = "testSubject";
+
+    public SubjectStartsWithTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    // test if the recipients get returned as matched
+    public void testHostIsMatchedAllRecipients() throws MessagingException {
+        setSubject(SUBJECT_NAME);
+
+        setupAll();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if no recipient get returned cause it not match
+    public void testHostIsNotMatch() throws MessagingException {
+        setSubject("FOOBAR");
+
+        setupAll();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+
+    protected Matcher createMatcher() {
+        return new SubjectStartsWith();
+    }
+
+    protected String getConfigOption() {
+        return "SubjectIs=";
+    }
+
+    protected String getSubjectName() {
+        return "test";
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message