james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r411558 - /james/server/trunk/src/test/org/apache/james/transport/matchers/
Date Sun, 04 Jun 2006 14:05:02 GMT
Author: norman
Date: Sun Jun  4 07:05:01 2006
New Revision: 411558

URL: http://svn.apache.org/viewvc?rev=411558&view=rev
Log:
-Remove creation of mockedMimeMessage from Attributes tests
-Fix a typo
-Add junit test for SMTPIsAuthNetwork matcher

Added:
    james/server/trunk/src/test/org/apache/james/transport/matchers/SMTPIsAuthNetworkTest.java
Modified:
    james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java

Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java?rev=411558&r1=411557&r2=411558&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java
(original)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java
Sun Jun  4 07:05:01 2006
@@ -18,24 +18,22 @@
 
 package org.apache.james.transport.matchers;
 
-import junit.framework.TestCase;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collection;
 
 import javax.mail.MessagingException;
-import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.ParseException;
 
-import org.apache.james.test.mock.javaxmail.MockMimeMessage;
+import junit.framework.TestCase;
+
 import org.apache.james.test.mock.mailet.MockMail;
-import org.apache.james.test.mock.mailet.MockMatcherConfig;
 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 java.util.Arrays;
-import java.util.Collection;
-import java.io.Serializable;
-
 public abstract class AbstractHasMailAttributeTest extends TestCase {
     protected MimeMessage mockedMimeMessage;
     protected MockMail mockedMail;
@@ -57,19 +55,6 @@
         this.mailAttributeValue = mailAttributeValue;
     }
 
-    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(MimeMessage.RecipientType.TO, rcpt);
-        mockedMimeMessage.setSubject("testmail");
-        mockedMimeMessage.setText("testtext");
-        mockedMimeMessage.saveChanges();
-
-    }
-
     protected void setupMockedMail(MimeMessage m) throws ParseException {
         mockedMail = new MockMail();
         mockedMail.setMessage(m);
@@ -82,7 +67,6 @@
     }
 
     protected void setupMatcher() throws MessagingException {
-        setupMockedMimeMessage();
         matcher = createMatcher();
         MockMatcherConfig mci = new MockMatcherConfig("HasMailAttribute="
                 + getHasMailAttribute(),
@@ -109,7 +93,6 @@
     }
 
     protected void setupAll() throws MessagingException {
-        setupMockedMimeMessage();
         setupMockedMail(mockedMimeMessage);
         setupMatcher();
     }

Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java?rev=411558&r1=411557&r2=411558&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java
(original)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java
Sun Jun  4 07:05:01 2006
@@ -30,7 +30,6 @@
     }
 
     protected void setupMatcher() throws MessagingException {
-        setupMockedMimeMessage();
         matcher = createMatcher();
         MockMatcherConfig mci = new MockMatcherConfig("HasMailAttribute="
                 + getHasMailAttribute(), new MockMailContext());

Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java?rev=411558&r1=411557&r2=411558&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java
(original)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java
Sun Jun  4 07:05:01 2006
@@ -73,7 +73,6 @@
         String exception = "Malformed pattern: " + invalidRegex;
 
         setRegex(invalidRegex);
-        setupMockedMimeMessage();
         setupMockedMail(mockedMimeMessage);
 
         try {

Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java?rev=411558&r1=411557&r2=411558&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java
(original)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java
Sun Jun  4 07:05:01 2006
@@ -39,7 +39,6 @@
     // test if the mail attribute was not matched cause diffrent value
     public void testAttributeIsNotMatchedCauseValue() throws MessagingException {
         setMailAttributeName(MAIL_ATTRIBUTE_NAME);
-        setupMockedMimeMessage();
         setupMockedMail(mockedMimeMessage);
         setupMatcher();
 

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=411558&r1=411557&r2=411558&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 Sun
Jun  4 07:05:01 2006
@@ -81,7 +81,6 @@
     }
 
     protected Matcher createMatcher() {
-        // TODO Auto-generated method stub
         return new RecipientIs();
     }
 }

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/SMTPIsAuthNetworkTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/SMTPIsAuthNetworkTest.java?rev=411558&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/SMTPIsAuthNetworkTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/SMTPIsAuthNetworkTest.java
Sun Jun  4 07:05:01 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 java.util.Arrays;
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.ParseException;
+
+import junit.framework.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;
+
+public class SMTPIsAuthNetworkTest extends TestCase {
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private boolean isAuthorized = false;
+
+    private final String MAIL_ATTRIBUTE_NAME = "org.apache.james.SMTPIsAuthNetwork";
+
+    public SMTPIsAuthNetworkTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setIsAuthorized(boolean isAuthorized) {
+        this.isAuthorized = isAuthorized;
+    }
+
+    private void setupMockedMail() throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") }));
+        if (isAuthorized) {
+            mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME, "true");
+
+        }
+    }
+
+    private void setupMatcher() throws MessagingException {
+        matcher = new SMTPIsAuthNetwork();
+        MockMatcherConfig mci = new MockMatcherConfig("SMTPIsAuthNetwork",
+                new MockMailContext());
+        matcher.init(mci);
+    }
+
+    public void testIsAuthNetwork() throws MessagingException {
+        setIsAuthorized(true);
+        setupMockedMail();
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    public void testIsNotAuthNetwork() throws MessagingException {
+        setIsAuthorized(false);
+        setupMockedMail();
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+}



---------------------------------------------------------------------
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