james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r410812 - in /james/server/branches/v2.3/src/test/org/apache/james: test/mock/mailet/ transport/mailets/ transport/matchers/
Date Thu, 01 Jun 2006 09:31:18 GMT
Author: norman
Date: Thu Jun  1 02:31:17 2006
New Revision: 410812

URL: http://svn.apache.org/viewvc?rev=410812&view=rev
Log:
Merge all junit tests that work in 2.3 branch.

Added:
    james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMail.java
    james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMatcherConfig.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/mailets/SetMimeHeaderTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/AllTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/FetchedFromTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasHeaderTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java
    james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/RecipientIsTest.java

Added: james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMail.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMail.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMail.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMail.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,143 @@
+/***********************************************************************
+ * 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.test.mock.mailet;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+public class MockMail implements Mail {
+
+    private MimeMessage msg = null;
+
+    private Collection recipients = new ArrayList();
+
+    private String name = null;
+
+    private MailAddress sender = null;
+
+    private String state = null;
+
+    private String errorMessage;
+
+    private Date lastUpdated;
+
+    private HashMap attributes = new HashMap();
+
+    private static final long serialVersionUID = 1L;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String newName) {
+        this.name = newName;
+    }
+
+    public MimeMessage getMessage() throws MessagingException {
+        return msg;
+    }
+
+    public Collection getRecipients() {
+        return recipients;
+    }
+
+    public void setRecipients(Collection recipients) {
+        this.recipients = recipients;
+    }
+
+    public MailAddress getSender() {
+        return sender;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public String getRemoteHost() {
+        throw new UnsupportedOperationException("Unimplemented mock service");
+    }
+
+    public String getRemoteAddr() {
+        throw new UnsupportedOperationException("Unimplemented mock service");
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String msg) {
+        this.errorMessage = msg;
+    }
+
+    public void setMessage(MimeMessage message) {
+        this.msg = message;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public Serializable getAttribute(String name) {
+        return (Serializable) attributes.get(name);
+    }
+
+    public Iterator getAttributeNames() {
+        return attributes.keySet().iterator();
+    }
+
+    public boolean hasAttributes() {
+        return !attributes.isEmpty();
+    }
+
+    public Serializable removeAttribute(String name) {
+        return (Serializable) attributes.remove(name);
+
+    }
+
+    public void removeAllAttributes() {
+        attributes.clear();
+    }
+
+    public Serializable setAttribute(String name, Serializable object) {
+
+        return (Serializable) attributes.put(name, object);
+    }
+
+    public long getMessageSize() throws MessagingException {
+        throw new UnsupportedOperationException("Unimplemented mock service");
+    }
+
+    public Date getLastUpdated() {
+        return lastUpdated;
+    }
+
+    public void setLastUpdated(Date lastUpdated) {
+        this.lastUpdated = lastUpdated;
+    }
+
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMatcherConfig.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMatcherConfig.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMatcherConfig.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMatcherConfig.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,57 @@
+/***********************************************************************
+ * 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.test.mock.mailet;
+
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.MatcherConfig;
+
+/**
+ * MatcherConfig
+ */
+public class MockMatcherConfig implements MatcherConfig {
+
+    private String matcherName;
+
+    private MailetContext mc;
+
+    public MockMatcherConfig(String matcherName, MailetContext mc) {
+        super();
+        this.matcherName = matcherName;
+        this.mc = mc;
+    }
+
+    public String getCondition() {
+        if (matcherName.indexOf("=") >= 0) {
+            return matcherName.substring(getMatcherName().length() + 1);
+        } else {
+            return null;
+        }
+    }
+
+    public MailetContext getMailetContext() {
+        return mc;
+    }
+
+    public String getMatcherName() {
+        if (matcherName.indexOf("=") >= 0) {
+            return matcherName.split("=")[0];
+        } else {
+            return matcherName;
+        }
+    }
+
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/mailets/SetMimeHeaderTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/mailets/SetMimeHeaderTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/mailets/SetMimeHeaderTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/mailets/SetMimeHeaderTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,128 @@
+/***********************************************************************
+ * 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.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.MockMailetConfig;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Mailet;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class SetMimeHeaderTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private Mail mockedMail;
+
+    private Mailet mailet;
+
+    private final String HEADER_NAME = "JUNIT";
+
+    private final String HEADER_VALUE = "test-value";
+
+    private String headerName = "defaultHeaderName";
+
+    private String headerValue = "defaultHeaderValue";
+
+    public SetMimeHeaderTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
+
+    private void setHeaderValue(String headerValue) {
+        this.headerValue = headerValue;
+    }
+
+    private 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);
+        mockedMimeMessage.setHeader(headerName, headerValue);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"), new MailAddress("test2@james.apache.org") }));
+
+    }
+
+    private void setupMailet() throws MessagingException {
+        setupMockedMimeMessage();
+        mailet = new SetMimeHeader();
+        MockMailetConfig mci = new MockMailetConfig("Test",
+                new MockMailContext());
+        mci.setProperty("name", HEADER_NAME);
+        mci.setProperty("value", HEADER_VALUE);
+
+        mailet.init(mci);
+    }
+
+    // test if the Header was add
+    public void testHeaderIsPresent() throws MessagingException {
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMailet();
+
+        mailet.service(mockedMail);
+
+        assertEquals(HEADER_VALUE, mockedMail.getMessage().getHeader(
+                HEADER_NAME)[0]);
+
+    }
+
+    // test if the Header was replaced
+    public void testHeaderIsReplaced() throws MessagingException {
+        setHeaderName(HEADER_NAME);
+        setHeaderValue(headerValue);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMailet();
+
+        mailet.service(mockedMail);
+
+        assertEquals(HEADER_VALUE, mockedMail.getMessage().getHeader(
+                HEADER_NAME)[0]);
+
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/AllTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/AllTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/AllTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/AllTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,73 @@
+/***********************************************************************
+ * 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 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.ParseException;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class AllTest extends TestCase {
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    public AllTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    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") }));
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+        matcher = new All();
+        MockMatcherConfig mci = new MockMatcherConfig("All",
+                new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if all recipients was returned
+    public void testAllRecipientsReturned() throws MessagingException {
+        setupMockedMail();
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/FetchedFromTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/FetchedFromTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/FetchedFromTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/FetchedFromTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,142 @@
+/***********************************************************************
+ * 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 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.ParseException;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class FetchedFromTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String HEADER_NAME = "X-fetched-from";
+
+    private final String HEADER_VALUE = "james-user";
+
+    private String headerName = "defaultHeaderName";
+
+    private String headerValue = "defaultHeaderValue";
+
+    public FetchedFromTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
+
+    private void setHeaderValue(String headerValue) {
+        this.headerValue = headerValue;
+    }
+
+    private 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);
+        mockedMimeMessage.setHeader(headerName, headerValue);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") }));
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+        setupMockedMimeMessage();
+        matcher = new FetchedFrom();
+        MockMatcherConfig mci = new MockMatcherConfig("FetchedFrom="
+                + HEADER_VALUE, new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if the Header was matched
+    public void testHeaderIsMatched() throws MessagingException {
+        setHeaderName(HEADER_NAME);
+        setHeaderValue(HEADER_VALUE);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if the Header was not matched
+    public void testHeaderIsNotMatched() throws MessagingException {
+        setHeaderName(HEADER_NAME);
+        setHeaderValue(headerValue);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+        assertNull(matchedRecipients);
+    }
+
+    // test if the Header was removed after matched
+    public void testHeaderWasRemovedAfterMatched() throws MessagingException {
+        setHeaderName(HEADER_NAME);
+        setHeaderValue(HEADER_VALUE);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+        Collection matchedRecipients2 = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertNull(matchedRecipients2);
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasHeaderTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasHeaderTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasHeaderTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasHeaderTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,125 @@
+/***********************************************************************
+ * 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 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.ParseException;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class HasHeaderTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String HEADER_NAME = "JUNIT";
+
+    private final String HEADER_VALUE = "test-value";
+
+    private String headerName = "defaultHeaderName";
+
+    private String headerValue = "defaultHeaderValue";
+
+    public HasHeaderTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
+
+    private void setHeaderValue(String headerValue) {
+        this.headerValue = headerValue;
+    }
+
+    private 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);
+        mockedMimeMessage.setHeader(headerName, headerValue);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") }));
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+        setupMockedMimeMessage();
+        matcher = new HasHeader();
+        MockMatcherConfig mci = new MockMatcherConfig("HasHeader="
+                + HEADER_NAME, new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if the Header was matched
+    public void testHeaderIsMatched() throws MessagingException {
+        setHeaderName(HEADER_NAME);
+        setHeaderValue(HEADER_VALUE);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if the Header was not matched
+    public void testHeaderIsNotMatched() throws MessagingException {
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,128 @@
+/***********************************************************************
+ * 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 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.ParseException;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class HasMailAttributeTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String MAIL_ATTRIBUTE_NAME = "org.apache.james.test.junit";
+
+    private final String MAIL_ATTRIBUTE_VALUE = "true";
+
+    private String mailAttributeName = "org.apache.james";
+
+    private String mailAttributeValue = "false";
+
+    public HasMailAttributeTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setMailAttributeName(String mailAttributeName) {
+        this.mailAttributeName = mailAttributeName;
+    }
+
+    private void setMailAttributeValue(String mailAttributeValue) {
+        this.mailAttributeValue = mailAttributeValue;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") }));
+        mockedMail.setAttribute(mailAttributeName,
+                (Serializable) mailAttributeValue);
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+        setupMockedMimeMessage();
+        matcher = new HasMailAttribute();
+        MockMatcherConfig mci = new MockMatcherConfig("HasMailAttribute="
+                + MAIL_ATTRIBUTE_NAME, new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if the mail attribute was matched
+    public void testAttributeIsMatched() throws MessagingException {
+        setMailAttributeName(MAIL_ATTRIBUTE_NAME);
+        setMailAttributeValue(MAIL_ATTRIBUTE_VALUE);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if the mail attribute was not matched
+    public void testAttributeIsNotMatched() throws MessagingException {
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,160 @@
+/***********************************************************************
+ * 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 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.ParseException;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class HasMailAttributeWithValueRegexTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String MAIL_ATTRIBUTE_NAME = "org.apache.james.test.junit";
+
+    private final String MAIL_ATTRIBUTE_VALUE = "true";
+
+    private String mailAttributeName = "org.apache.james";
+
+    private String mailAttributeValue = "false";
+
+    private String regex = ".*";
+
+    public HasMailAttributeWithValueRegexTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setMailAttributeName(String mailAttributeName) {
+        this.mailAttributeName = mailAttributeName;
+    }
+
+    private void setMailAttributeValue(String mailAttributeValue) {
+        this.mailAttributeValue = mailAttributeValue;
+    }
+
+    private void setRegex(String regex) {
+        this.regex = regex;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") }));
+        mockedMail.setAttribute(mailAttributeName,
+                (Serializable) mailAttributeValue);
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+        setupMockedMimeMessage();
+        matcher = new HasMailAttributeWithValueRegex();
+        MockMatcherConfig mci = new MockMatcherConfig("HasMailAttribute="
+                + MAIL_ATTRIBUTE_NAME + ", " + regex, new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if the mail attribute was matched
+    public void testAttributeIsMatched() throws MessagingException {
+        setMailAttributeName(MAIL_ATTRIBUTE_NAME);
+        setMailAttributeValue(MAIL_ATTRIBUTE_VALUE);
+        setRegex(".*");
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if the mail attribute was not matched
+    public void testHeaderIsNotMatched() throws MessagingException {
+        setRegex("\\d");
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+
+    // test if an exception was thrown cause the regex was invalid
+    public void testHeaderIsNotMatchedCauseValue() throws MessagingException {
+
+        String invalidRegex = "(!(";
+        String regexException = null;
+        String exception = "Malformed pattern: " + invalidRegex;
+
+        setRegex(invalidRegex);
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+
+        try {
+            setupMatcher();
+        } catch (MessagingException m) {
+            regexException = m.getMessage();
+        }
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+        assertEquals(regexException, exception);
+
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,140 @@
+/***********************************************************************
+ * 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 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.ParseException;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class HasMailAttributeWithValueTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String MAIL_ATTRIBUTE_NAME = "org.apache.james.test.junit";
+
+    private final String MAIL_ATTRIBUTE_VALUE = "true";
+
+    private String mailAttributeName = "org.apache.james";
+
+    private String mailAttributeValue = "false";
+
+    public HasMailAttributeWithValueTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setMailAttributeName(String mailAttributeName) {
+        this.mailAttributeName = mailAttributeName;
+    }
+
+    private void setMailAttributeValue(String mailAttributeValue) {
+        this.mailAttributeValue = mailAttributeValue;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) throws ParseException {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"), new MailAddress("test2@james.apache.org") }));
+        mockedMail.setAttribute(mailAttributeName,
+                (Serializable) mailAttributeValue);
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+        setupMockedMimeMessage();
+        matcher = new HasMailAttributeWithValue();
+        MockMatcherConfig mci = new MockMatcherConfig("HasMailAttribute="
+                + MAIL_ATTRIBUTE_NAME + ", " + MAIL_ATTRIBUTE_VALUE,
+                new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if the mail attribute was matched
+    public void testHeaderIsMatched() throws MessagingException {
+        setMailAttributeName(MAIL_ATTRIBUTE_NAME);
+        setMailAttributeValue(MAIL_ATTRIBUTE_VALUE);
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if the mail attribute was not matched
+    public void testHeaderIsNotMatched() throws MessagingException {
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+
+    // test if the mail attribute was not matched cause diffrent value
+    public void testHeaderIsNotMatchedCauseValue() throws MessagingException {
+        setMailAttributeName(MAIL_ATTRIBUTE_NAME);
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsLocalTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,260 @@
+/***********************************************************************
+ * 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 org.apache.james.test.mock.javaxmail.MockMimeMessage;
+import org.apache.james.test.mock.mailet.MockMail;
+import org.apache.james.test.mock.mailet.MockMatcherConfig;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetContext;
+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;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+public class HostIsLocalTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String[] LOCALSERVER = new String[] { "james.apache.org" };
+
+    private MailAddress[] recipients;
+
+    public HostIsLocalTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setRecipients(MailAddress[] recipients) {
+        this.recipients = recipients;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(recipients));
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+
+        MailetContext mockMailContext = new MailetContext() {
+
+            Collection localServer = new ArrayList(Arrays.asList(LOCALSERVER));
+
+            public void bounce(Mail mail, String message)
+                    throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+
+            }
+
+            public void bounce(Mail mail, String message, MailAddress bouncer)
+                    throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+
+            }
+
+            public Collection getMailServers(String host) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public MailAddress getPostmaster() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Object getAttribute(String name) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Iterator getAttributeNames() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public int getMajorVersion() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public int getMinorVersion() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public String getServerInfo() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public boolean isLocalServer(String serverName) {
+                return localServer.contains(serverName);
+            }
+
+            public boolean isLocalUser(String userAccount) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public boolean isLocalEmail(MailAddress mailAddress) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void log(String message) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void log(String message, Throwable t) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void removeAttribute(String name) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void sendMail(MimeMessage msg) throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void sendMail(MailAddress sender, Collection recipients,
+                    MimeMessage msg) throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void sendMail(MailAddress sender, Collection recipients,
+                    MimeMessage msg, String state) throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void sendMail(Mail mail) throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void setAttribute(String name, Object object) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void storeMail(MailAddress sender, MailAddress recipient,
+                    MimeMessage msg) throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Iterator getSMTPHostAddresses(String domainName) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+        };
+
+        setupMockedMimeMessage();
+        matcher = new HostIsLocal();
+        MockMatcherConfig mci = new MockMatcherConfig("HostIsLocal",
+                mockMailContext);
+        matcher.init(mci);
+    }
+
+    // test if all recipients get returned as matched
+    public void testHostIsMatchedAllRecipients() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if one recipients get returned as matched
+    public void testHostIsMatchedOneRecipient() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james2.apache.org"),
+                new MailAddress("test2@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), 1);
+    }
+
+    // test if no recipient get returned cause it not match
+    public void testHostIsNotMatch() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james2.apache.org"),
+                new MailAddress("test2@james2.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertEquals(matchedRecipients.size(), 0);
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/HostIsTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,134 @@
+/***********************************************************************
+ * 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 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;
+
+public class HostIsTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String HOST_NAME = "james.apache.org";
+
+    private MailAddress[] recipients;
+
+    public HostIsTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setRecipients(MailAddress[] recipients) {
+        this.recipients = recipients;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) {
+        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());
+        matcher.init(mci);
+    }
+
+    // test if all recipients get returned as matched
+    public void testHostIsMatchedAllRecipients() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if one recipients get returned as matched
+    public void testHostIsMatchedOneRecipient() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james2.apache.org"),
+                new MailAddress("test2@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), 1);
+    }
+
+    // test if no recipient get returned cause it not match
+    public void testHostIsNotMatch() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james2.apache.org"),
+                new MailAddress("test2@james2.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertEquals(matchedRecipients.size(), 0);
+    }
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/IsSingleRecipientTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,115 @@
+/***********************************************************************
+ * 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 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;
+
+public class IsSingleRecipientTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private MailAddress[] recipients;
+
+    public IsSingleRecipientTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setRecipients(MailAddress[] recipients) {
+        this.recipients = recipients;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) {
+        mockedMail = new MockMail();
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(recipients));
+
+    }
+
+    private void setupMatcher() throws MessagingException {
+
+        matcher = new IsSingleRecipient();
+        MockMatcherConfig mci = new MockMatcherConfig("IsSingleRecipient",
+                new MockMailContext());
+        matcher.init(mci);
+    }
+
+    // test if matched
+    public void testHostIsMatchedAllRecipients() throws MessagingException {
+        setRecipients(new MailAddress[] { new MailAddress(
+                "test@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+    }
+
+    // test if not matched
+    public void testHostIsMatchedOneRecipient() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james2.apache.org"),
+                new MailAddress("test2@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+
+}

Added: james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/RecipientIsTest.java
URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/RecipientIsTest.java?rev=410812&view=auto
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/RecipientIsTest.java (added)
+++ james/server/branches/v2.3/src/test/org/apache/james/transport/matchers/RecipientIsTest.java Thu Jun  1 02:31:17 2006
@@ -0,0 +1,133 @@
+/***********************************************************************
+ * 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 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;
+
+public class RecipientIsTest extends TestCase {
+
+    private MimeMessage mockedMimeMessage;
+
+    private MockMail mockedMail;
+
+    private Matcher matcher;
+
+    private final String RECIPIENT_NAME = "test@james.apache.org";
+
+    private MailAddress[] recipients;
+
+    public RecipientIsTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setRecipients(MailAddress[] recipients) {
+        this.recipients = recipients;
+    }
+
+    private 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);
+        mockedMimeMessage.setSubject("testmail");
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+
+    }
+
+    private void setupMockedMail(MimeMessage m) {
+        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());
+        matcher.init(mci);
+    }
+
+    // test if the recipients get returned as matched
+    public void testHostIsMatchedAllRecipients() throws MessagingException {
+        setRecipients(new MailAddress[] { new MailAddress(
+                "test@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if one recipients get returned as matched
+    public void testHostIsMatchedOneRecipient() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), 1);
+    }
+
+    // test if no recipient get returned cause it not match
+    public void testHostIsNotMatch() throws MessagingException {
+        setRecipients(new MailAddress[] {
+                new MailAddress("test@james2.apache.org"),
+                new MailAddress("test2@james2.apache.org") });
+
+        setupMockedMimeMessage();
+        setupMockedMail(mockedMimeMessage);
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertEquals(matchedRecipients.size(), 0);
+    }
+}



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