Author: bago
Date: Sun Sep 17 06:19:15 2006
New Revision: 447065
URL: http://svn.apache.org/viewvc?view=rev&rev=447065
Log:
Moved dependencies on global mailet context variables from
UsersRepositoryAliasingForwarding to DeliveryMailet wrapper (related to
JAMES-414)
Added few more tests for local mailet attributes vs global James parameter and
for ignoreCase.
Modified:
james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java
Modified:
james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java?view=diff&rev=447065&r1=447064&r2=447065
==============================================================================
---
james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
(original)
+++
james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
Sun Sep 17 06:19:15 2006
@@ -22,6 +22,7 @@
package org.apache.james.transport.mailets;
import org.apache.commons.collections.iterators.IteratorChain;
+import org.apache.james.Constants;
import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailetConfig;
@@ -83,8 +84,41 @@
*/
public void init() throws MessagingException {
super.init();
+
aliasingMailet = new UsersRepositoryAliasingForwarding();
- aliasingMailet.init(getMailetConfig());
+ MailetConfig mua = new MailetConfig() {
+
+ public String getInitParameter(String name) {
+ if ("enableAliases".equals(name)) {
+ String res =
getMailetConfig().getInitParameter("enableAliases");
+ return res != null ? res :
getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_ALIASES).toString();
+ } else if ("enableForwarding".equals(name)) {
+ String res =
getMailetConfig().getInitParameter("enableForwarding");
+ return res != null ? res :
getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_FORWARDING).toString();
+ } else if ("ignoreCase".equals(name)) {
+ String res =
getMailetConfig().getInitParameter("ignoreCase");
+ return res != null ? res :
getMailetContext().getAttribute(Constants.DEFAULT_IGNORE_USERNAME_CASE).toString();
+ } else return null;
+ }
+
+ public Iterator getInitParameterNames() {
+ Collection h = new ArrayList();
+ h.add("enableAliases");
+ h.add("enableForwarding");
+ h.add("ignoreCase");
+ return h.iterator();
+ }
+
+ public MailetContext getMailetContext() {
+ return getMailetConfig().getMailetContext();
+ }
+
+ public String getMailetName() {
+ return getMailetConfig().getMailetName();
+ }
+
+ };
+ aliasingMailet.init(mua);
deliveryMailet = new ToMultiRepository();
MailetConfig m = new MailetConfig() {
Modified:
james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java?view=diff&rev=447065&r1=447064&r2=447065
==============================================================================
---
james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
(original)
+++
james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
Sun Sep 17 06:19:15 2006
@@ -247,15 +247,9 @@
.getAttribute(Constants.AVALON_COMPONENT_MANAGER);
try {
- enableAliases = new Boolean(getInitParameter("enableAliases",
-
getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_ALIASES).toString()
- )).booleanValue();
- enableForwarding = new Boolean(getInitParameter("enableForwarding",
-
getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_FORWARDING).toString()
- )).booleanValue();
- ignoreCase = new Boolean(getInitParameter("ignoreCase",
-
getMailetContext().getAttribute(Constants.DEFAULT_IGNORE_USERNAME_CASE).toString()
- )).booleanValue();
+ enableAliases = new
Boolean(getInitParameter("enableAliases","false")).booleanValue();
+ enableForwarding = new
Boolean(getInitParameter("enableForwarding","false")).booleanValue();
+ ignoreCase = new
Boolean(getInitParameter("ignoreCase","false")).booleanValue();
String userRep = getInitParameter("usersRepository");
if (userRep == null || userRep.length() == 0) {
Modified:
james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java?view=diff&rev=447065&r1=447064&r2=447065
==============================================================================
---
james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
(original)
+++
james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
Sun Sep 17 06:19:15 2006
@@ -48,6 +48,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import junit.framework.TestCase;
@@ -63,7 +64,7 @@
public void testUnknownUser() throws MessagingException {
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -77,7 +78,7 @@
public void testSimpleDelivery() throws MessagingException {
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -88,10 +89,38 @@
assertDeliveryWorked(mail, expectedMails);
}
+ public void testSimpleDeliveryCaseSensitiveNoMatch() throws
MessagingException {
+ //mockMailetConfig.setProperty(key, value)
+ Mailet m = getMailet(null);
+
+ Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
+ m.service(mail);
+
+ HashMap expectedMails = new HashMap();
+ expectedMails.put("errors", new String[] {"[EMAIL PROTECTED]"});
+
+ assertDeliveryWorked(mail, expectedMails);
+ }
+
+ public void testSimpleDeliveryCaseSensitiveMatch() throws
MessagingException {
+ //mockMailetConfig.setProperty(key, value)
+ Properties properties = new Properties();
+ properties.setProperty("ignoreCase", "true");
+ Mailet m = getMailet(properties);
+
+ Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
+ m.service(mail);
+
+ HashMap expectedMails = new HashMap();
+ expectedMails.put("localuser", new String[] {"[EMAIL PROTECTED]"});
+
+ assertDeliveryWorked(mail, expectedMails);
+ }
+
public void testSimpleAliasDelivery() throws MessagingException {
mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES,
Boolean.TRUE);
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -104,7 +133,7 @@
public void testSimpleAliasWithDisabledAlias() throws MessagingException {
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -118,7 +147,7 @@
public void testForwardingWithForwardingDisabled() throws
MessagingException {
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -133,7 +162,7 @@
public void testForwarding() throws MessagingException {
mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING,
Boolean.TRUE);
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -148,7 +177,7 @@
mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING,
Boolean.TRUE);
mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES,
Boolean.TRUE);
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -159,11 +188,27 @@
assertDeliveryWorked(mail, expectedMails);
}
+ public void testAliasingForwardingWithLocallyOverriddenForwarding() throws
MessagingException {
+ mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING,
Boolean.TRUE);
+ mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES,
Boolean.TRUE);
+ Properties properties = new Properties();
+ properties.setProperty("enableForwarding", "false");
+ Mailet m = getMailet(properties);
+
+ Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
+ m.service(mail);
+
+ HashMap expectedMails = new HashMap();
+ expectedMails.put("localuser", new String[] {"[EMAIL PROTECTED]"});
+
+ assertDeliveryWorked(mail, expectedMails);
+ }
+
public void testForwardingToLocal() throws MessagingException {
mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING,
Boolean.TRUE);
mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES,
Boolean.TRUE);
//mockMailetConfig.setProperty(key, value)
- Mailet m = getMailet();
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"[EMAIL PROTECTED]"});
m.service(mail);
@@ -322,8 +367,8 @@
return mail;
}
- public Mailet getMailet() throws MessagingException {
- MockMailetConfig mockMailetConfig = new
MockMailetConfig("TestedLocalDelivery", mockMailetContext);
+ public Mailet getMailet(Properties p) throws MessagingException {
+ MockMailetConfig mockMailetConfig = new
MockMailetConfig("TestedLocalDelivery", mockMailetContext, p);
Mailet m = new LocalDelivery();
m.init(mockMailetConfig);
return m;
Modified:
james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java?view=diff&rev=447065&r1=447064&r2=447065
==============================================================================
---
james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java
(original)
+++
james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java
Sun Sep 17 06:19:15 2006
@@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
public class MockUsersRepository implements UsersRepository {
@@ -107,11 +108,11 @@
}
public User getUserByNameCaseInsensitive(String name) {
- return null; // trivial implementation
+ return (User) m_users.get(name.toLowerCase(Locale.US));
}
public String getRealName(String name) {
- return m_users.get(name) != null ? ((User)
m_users.get(name)).getUserName() : null;
+ return m_users.get(name.toLowerCase(Locale.US)) != null ? ((User)
m_users.get(name.toLowerCase(Locale.US))).getUserName() : null;
}
public boolean updateUser(User user) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]