You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by er...@apache.org on 2013/02/08 12:40:43 UTC
svn commit: r1443949 - in /james/server/trunk/protocols/protocols-smtp/src:
main/java/org/apache/james/smtpserver/
main/java/org/apache/james/smtpserver/fastfail/
test/java/org/apache/james/smtpserver/
Author: eric
Date: Fri Feb 8 11:40:42 2013
New Revision: 1443949
URL: http://svn.apache.org/r1443949
Log:
Fix SMTP failing unit tests due to @Inject usage instead of @Resource (JAMES-1477)
Modified:
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesMailCmdHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesRcptCmdHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ResolvableEhloHeloHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ReverseEqualsEhloHeloHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java
james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java Fri Feb 8 11:40:42 2013
@@ -19,6 +19,7 @@
package org.apache.james.smtpserver;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.api.DomainListException;
@@ -29,7 +30,7 @@ public class AuthRequiredToRelayRcptHook
private DomainList domains;
@Inject
- public void setDomainList(DomainList domains) {
+ public void setDomainList(@Named("domainlist") DomainList domains) {
this.domains = domains;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesMailCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesMailCmdHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesMailCmdHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesMailCmdHandler.java Fri Feb 8 11:40:42 2013
@@ -19,6 +19,7 @@
package org.apache.james.smtpserver;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.api.DomainListException;
@@ -29,7 +30,7 @@ public class JamesMailCmdHandler extends
private DomainList domainList;
@Inject
- public final void setDomainList(DomainList domainList) {
+ public final void setDomainList(@Named("domainlist") DomainList domainList) {
this.domainList = domainList;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesRcptCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesRcptCmdHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesRcptCmdHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/JamesRcptCmdHandler.java Fri Feb 8 11:40:42 2013
@@ -20,6 +20,7 @@
package org.apache.james.smtpserver;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.api.DomainListException;
@@ -30,7 +31,7 @@ public class JamesRcptCmdHandler extends
private DomainList domainList;
@Inject
- public final void setDomainList(DomainList domainList) {
+ public final void setDomainList(@Named("domainlist") DomainList domainList) {
this.domainList = domainList;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java Fri Feb 8 11:40:42 2013
@@ -19,6 +19,7 @@
package org.apache.james.smtpserver;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.api.DomainListException;
@@ -39,12 +40,12 @@ public class SenderAuthIdentifyVerificat
private UsersRepository users;
@Inject
- public final void setUsersRepository(UsersRepository users) {
+ public final void setUsersRepository(@Named("usersrepository") UsersRepository users) {
this.users = users;
}
@Inject
- public void setDomainList(DomainList domains) {
+ public void setDomainList(@Named("domainlist") DomainList domains) {
this.domains = domains;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java Fri Feb 8 11:40:42 2013
@@ -19,6 +19,7 @@
package org.apache.james.smtpserver;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.protocols.smtp.SMTPSession;
import org.apache.james.protocols.smtp.hook.AuthHook;
@@ -50,7 +51,7 @@ public class UsersRepositoryAuthHook imp
* the users to set
*/
@Inject
- public final void setUsers(UsersRepository users) {
+ public final void setUsersRepository(@Named("usersrepository") UsersRepository users) {
this.users = users;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java Fri Feb 8 11:40:42 2013
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
import java.net.UnknownHostException;
@@ -25,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
@@ -37,7 +37,7 @@ public class DNSRBLHandler extends org.a
private DNSService dns;
@Inject
- public void setDNSService(DNSService dns) {
+ public void setDNSService(@Named("dnsservice") DNSService dns) {
this.dns = dns;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java Fri Feb 8 11:40:42 2013
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
import java.io.File;
@@ -34,6 +33,7 @@ import java.util.List;
import java.util.Map;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.sql.DataSource;
import org.apache.commons.configuration.Configuration;
@@ -170,7 +170,7 @@ public class JDBCGreylistHandler extends
}
@Inject
- public final void setDNSService(DNSService dnsService) {
+ public final void setDNSService(@Named("dnsservice") DNSService dnsService) {
this.dnsService = dnsService;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ResolvableEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ResolvableEhloHeloHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ResolvableEhloHeloHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ResolvableEhloHeloHandler.java Fri Feb 8 11:40:42 2013
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
import java.net.UnknownHostException;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.dnsservice.api.DNSService;
@@ -30,7 +30,7 @@ public class ResolvableEhloHeloHandler e
private DNSService dns;
@Inject
- public void setDNSService(DNSService dns) {
+ public void setDNSService(@Named("dnsservice") DNSService dns) {
this.dns = dns;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ReverseEqualsEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ReverseEqualsEhloHeloHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ReverseEqualsEhloHeloHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ReverseEqualsEhloHeloHandler.java Fri Feb 8 11:40:42 2013
@@ -21,6 +21,7 @@ package org.apache.james.smtpserver.fast
import java.net.UnknownHostException;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.dnsservice.api.DNSService;
@@ -29,7 +30,7 @@ public class ReverseEqualsEhloHeloHandle
private DNSService dns;
@Inject
- public void setDNSService(DNSService dns) {
+ public void setDNSService(@Named("dnsservice") DNSService dns) {
this.dns = dns;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java Fri Feb 8 11:40:42 2013
@@ -16,9 +16,10 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
+import javax.inject.Named;
+
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.jspf.core.DNSService;
@@ -95,7 +96,7 @@ public class SPFHandler implements James
* @param dnsService
* The DNSService
*/
- public void setDNSService(DNSService dnsService) {
+ public void setDNSService(@Named("dnsservice") DNSService dnsService) {
spf = new SPF(dnsService, new SPFLogger());
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java Fri Feb 8 11:40:42 2013
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
import java.io.IOException;
@@ -27,6 +26,7 @@ import java.util.HashSet;
import java.util.Iterator;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
@@ -88,7 +88,7 @@ public class URIRBLHandler implements Ja
* the dnsService to set
*/
@Inject
- public final void setDNSService(DNSService dnsService) {
+ public final void setDNSService(@Named("dnsservice") DNSService dnsService) {
this.dnsService = dnsService;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java Fri Feb 8 11:40:42 2013
@@ -21,6 +21,7 @@ package org.apache.james.smtpserver.fast
import java.util.Collection;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
@@ -65,7 +66,7 @@ public class ValidRcptHandler extends Ab
* the users to set
*/
@Inject
- public final void setUsers(UsersRepository users) {
+ public final void setUsersRepository(@Named("usersrepository") UsersRepository users) {
this.users = users;
}
@@ -81,7 +82,7 @@ public class ValidRcptHandler extends Ab
}
@Inject
- public void setDomainList(DomainList domains) {
+ public void setDomainList(@Named("domainlist") DomainList domains) {
this.domains = domains;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java Fri Feb 8 11:40:42 2013
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
import java.net.UnknownHostException;
@@ -25,6 +24,7 @@ import java.util.Collection;
import java.util.Iterator;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
@@ -90,7 +90,7 @@ public class ValidRcptMX implements Init
* @param dnsService the dnsService to set
*/
@Inject
- public final void setDNSService(DNSService dnsService) {
+ public final void setDNSService(@Named("dnsservice") DNSService dnsService) {
this.dnsService = dnsService;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java Fri Feb 8 11:40:42 2013
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.fastfail;
import java.util.Collection;
import javax.inject.Inject;
+import javax.inject.Named;
import org.apache.james.dnsservice.api.DNSService;
import org.apache.james.protocols.smtp.SMTPSession;
@@ -31,7 +31,7 @@ public class ValidSenderDomainHandler ex
private DNSService dnsService;
@Inject
- public void setDNSService(DNSService dnsService) {
+ public void setDNSService(@Named("dnsservice") DNSService dnsService) {
this.dnsService = dnsService;
}
Modified: james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java Fri Feb 8 11:40:42 2013
@@ -18,13 +18,31 @@
****************************************************************/
package org.apache.james.smtpserver;
-import java.io.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Writer;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
+
import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPReply;
import org.apache.james.dnsservice.api.DNSService;
@@ -44,7 +62,6 @@ import org.apache.mailet.HostAddress;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.junit.After;
-import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@@ -136,11 +153,12 @@ public class SMTPServerTest {
return InetAddress.getLocalHost();
}
}
- protected final int m_smtpListenerPort;
- // private SMTPServer m_smtpServer;
- protected SMTPTestConfiguration m_testConfiguration;
- protected MockUsersRepository m_usersRepository = new MockUsersRepository();
- protected AlterableDNSServer m_dnsServer;
+
+ protected final int smtpListenerPort;
+
+ protected SMTPTestConfiguration smtpConfiguration;
+ protected MockUsersRepository usersRepository = new MockUsersRepository();
+ protected AlterableDNSServer dnsServer;
protected MockMailRepositoryStore store;
protected MockFileSystem fileSystem;
protected DNSService dnsService;
@@ -148,8 +166,10 @@ public class SMTPServerTest {
protected MockMailQueueFactory queueFactory;
protected MockMailQueue queue;
+ private SMTPServer smtpServer;
+
public SMTPServerTest() {
- m_smtpListenerPort = PortUtil.getNonPrivilegedPort();
+ smtpListenerPort = PortUtil.getNonPrivilegedPort();
}
@Before
@@ -157,243 +177,231 @@ public class SMTPServerTest {
setUpFakeLoader();
// slf4j can't set programmatically any log level. It's just a facade
// log.setLevel(SimpleLog.LOG_LEVEL_ALL);
- m_testConfiguration = new SMTPTestConfiguration(m_smtpListenerPort);
-
+ smtpConfiguration = new SMTPTestConfiguration(smtpListenerPort);
setUpSMTPServer();
}
- private SMTPServer m_smtpServer;
-
- protected void initSMTPServer(SMTPTestConfiguration testConfiguration) throws Exception {
- m_smtpServer.configure(testConfiguration);
- m_smtpServer.init();
-
- }
protected SMTPServer createSMTPServer() {
return new SMTPServer();
}
protected void setUpSMTPServer() throws Exception {
+
Logger log = LoggerFactory.getLogger("SMTP");
// slf4j can't set programmatically any log level. It's just a facade
// log.setLevel(SimpleLog.LOG_LEVEL_ALL);
- m_smtpServer = createSMTPServer();
- m_smtpServer.setDnsService(m_dnsServer);
- m_smtpServer.setFileSystem(fileSystem);
-
- m_smtpServer.setProtocolHandlerLoader(chain);
-
- m_smtpServer.setLog(log);
- }
-
- @Test
- public void testMaxLineLength() throws Exception {
- finishSetUp(m_testConfiguration);
-
- SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < AbstractChannelPipelineFactory.MAX_LINE_LENGTH; i++) {
- sb.append("A");
- }
- smtpProtocol.sendCommand("EHLO " + sb.toString());
- System.out.println(smtpProtocol.getReplyString());
- assertEquals("Line length exceed", 500, smtpProtocol.getReplyCode());
-
- smtpProtocol.sendCommand("EHLO test");
- assertEquals("Line length ok", 250, smtpProtocol.getReplyCode());
-
- smtpProtocol.quit();
- smtpProtocol.disconnect();
- }
-
- @Test
- public void testConnectionLimit() throws Exception {
- m_testConfiguration.setConnectionLimit(2);
- finishSetUp(m_testConfiguration);
-
- SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
- SMTPClient smtpProtocol2 = new SMTPClient();
- smtpProtocol2.connect("127.0.0.1", m_smtpListenerPort);
-
- SMTPClient smtpProtocol3 = new SMTPClient();
-
- try {
- smtpProtocol3.connect("127.0.0.1", m_smtpListenerPort);
- Thread.sleep(3000);
- fail("Shold disconnect connection 3");
- } catch (Exception e) {
- }
-
- smtpProtocol.quit();
- smtpProtocol.disconnect();
- smtpProtocol2.quit();
- smtpProtocol2.disconnect();
-
- smtpProtocol3.connect("127.0.0.1", m_smtpListenerPort);
- Thread.sleep(3000);
+ smtpServer = createSMTPServer();
+ smtpServer.setDnsService(dnsServer);
+ smtpServer.setFileSystem(fileSystem);
+ smtpServer.setProtocolHandlerLoader(chain);
+ smtpServer.setLog(log);
}
- protected void finishSetUp(SMTPTestConfiguration testConfiguration) throws Exception {
+ protected void init(SMTPTestConfiguration testConfiguration) throws Exception {
testConfiguration.init();
-
initSMTPServer(testConfiguration);
-
- // m_mailServer.setMaxMessageSizeBytes(m_testConfiguration.getMaxMessageSize()
- // * 1024);
+ // m_mailServer.setMaxMessageSizeBytes(m_testConfiguration.getMaxMessageSize() * 1024);
}
- @After
- public void tearDown() throws Exception {
- queue.clear();
- m_smtpServer.destroy();
- }
-
- public void verifyLastMail(String sender, String recipient, MimeMessage msg) throws IOException, MessagingException {
- Mail mailData = queue.getLastMail();
- assertNotNull("mail received by mail server", mailData);
-
- if (sender == null && recipient == null && msg == null) {
- fail("no verification can be done with all arguments null");
- }
-
- if (sender != null) {
- assertEquals("sender verfication", sender, mailData.getSender().toString());
- }
- if (recipient != null) {
- assertTrue("recipient verfication", mailData.getRecipients().contains(new MailAddress(recipient)));
- }
- if (msg != null) {
- ByteArrayOutputStream bo1 = new ByteArrayOutputStream();
- msg.writeTo(bo1);
- ByteArrayOutputStream bo2 = new ByteArrayOutputStream();
- mailData.getMessage().writeTo(bo2);
- assertEquals(bo1.toString(), bo2.toString());
- assertEquals("message verification", msg, mailData.getMessage());
- }
+ protected void initSMTPServer(SMTPTestConfiguration testConfiguration) throws Exception {
+ smtpServer.configure(testConfiguration);
+ smtpServer.init();
}
protected void setUpFakeLoader() throws Exception {
- chain = new MockProtocolHandlerLoader();
-
- chain.put("usersrepository", m_usersRepository);
-
- m_dnsServer = new AlterableDNSServer();
- chain.put("dnsservice", m_dnsServer);
+ chain = new MockProtocolHandlerLoader();
+
+ chain.put("usersrepository", usersRepository);
+
+ dnsServer = new AlterableDNSServer();
+ chain.put("dnsservice", dnsServer);
+
store = new MockMailRepositoryStore();
chain.put("mailStore", store);
fileSystem = new MockFileSystem();
-
+
chain.put("fileSystem", fileSystem);
chain.put("org.apache.james.smtpserver.protocol.DNSService", dnsService);
+
chain.put("recipientrewritetable", new RecipientRewriteTable() {
-
+
@Override
public void addRegexMapping(String user, String domain, String regex) throws RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
}
-
+
@Override
public void removeRegexMapping(String user, String domain, String regex) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public void addAddressMapping(String user, String domain, String address) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public void removeAddressMapping(String user, String domain, String address) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public void addErrorMapping(String user, String domain, String error) throws RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public void removeErrorMapping(String user, String domain, String error) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public Collection<String> getUserDomainMappings(String user, String domain) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
}
-
+
@Override
public void addMapping(String user, String domain, String mapping) throws RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public void removeMapping(String user, String domain, String mapping) throws RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public Map<String, Collection<String>> getAllMappings() throws RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
}
-
+
@Override
public void addAliasDomainMapping(String aliasDomain, String realDomain) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public void removeAliasDomainMapping(String aliasDomain, String realDomain) throws
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
-
}
-
+
@Override
public Collection<String> getMappings(String user, String domain) throws ErrorMappingException,
RecipientRewriteTableException {
throw new UnsupportedOperationException("Not implemented");
}
});
-
+
chain.put("org.apache.james.smtpserver.protocol.DNSService", dnsService);
queueFactory = new MockMailQueueFactory();
queue = (MockMailQueue) queueFactory.getQueue(MockMailQueueFactory.SPOOL);
chain.put("mailqueuefactory", queueFactory);
chain.put("domainlist", new SimpleDomainList() {
-
+
@Override
public boolean containsDomain(String serverName) {
return "localhost".equals(serverName);
}
});
+
+ }
+
+ @Test
+ public void testMaxLineLength() throws Exception {
+ init(smtpConfiguration);
+
+ SMTPClient smtpProtocol = new SMTPClient();
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < AbstractChannelPipelineFactory.MAX_LINE_LENGTH; i++) {
+ sb.append("A");
+ }
+ smtpProtocol.sendCommand("EHLO " + sb.toString());
+ System.out.println(smtpProtocol.getReplyString());
+ assertEquals("Line length exceed", 500, smtpProtocol.getReplyCode());
+
+ smtpProtocol.sendCommand("EHLO test");
+ assertEquals("Line length ok", 250, smtpProtocol.getReplyCode());
+
+ smtpProtocol.quit();
+ smtpProtocol.disconnect();
+ }
+
+ @Test
+ public void testConnectionLimit() throws Exception {
+ smtpConfiguration.setConnectionLimit(2);
+ init(smtpConfiguration);
+
+ SMTPClient smtpProtocol = new SMTPClient();
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
+ SMTPClient smtpProtocol2 = new SMTPClient();
+ smtpProtocol2.connect("127.0.0.1", smtpListenerPort);
+
+ SMTPClient smtpProtocol3 = new SMTPClient();
+
+ try {
+ smtpProtocol3.connect("127.0.0.1", smtpListenerPort);
+ Thread.sleep(3000);
+ fail("Shold disconnect connection 3");
+ } catch (Exception e) {
+ }
+
+ smtpProtocol.quit();
+ smtpProtocol.disconnect();
+ smtpProtocol2.quit();
+ smtpProtocol2.disconnect();
+
+ smtpProtocol3.connect("127.0.0.1", smtpListenerPort);
+ Thread.sleep(3000);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ queue.clear();
+ smtpServer.destroy();
+ }
+
+ public void verifyLastMail(String sender, String recipient, MimeMessage msg) throws IOException, MessagingException {
+ Mail mailData = queue.getLastMail();
+ assertNotNull("mail received by mail server", mailData);
+
+ if (sender == null && recipient == null && msg == null) {
+ fail("no verification can be done with all arguments null");
+ }
+
+ if (sender != null) {
+ assertEquals("sender verfication", sender, mailData.getSender().toString());
+ }
+ if (recipient != null) {
+ assertTrue("recipient verfication", mailData.getRecipients().contains(new MailAddress(recipient)));
+ }
+ if (msg != null) {
+ ByteArrayOutputStream bo1 = new ByteArrayOutputStream();
+ msg.writeTo(bo1);
+ ByteArrayOutputStream bo2 = new ByteArrayOutputStream();
+ mailData.getMessage().writeTo(bo2);
+ assertEquals(bo1.toString(), bo2.toString());
+ assertEquals("message verification", msg, mailData.getMessage());
+ }
}
@Test
public void testSimpleMailSendWithEHLO() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
// no message there, yet
assertNull("no mail received by mail server", queue.getLastMail());
@@ -424,11 +432,11 @@ public class SMTPServerTest {
@Test
public void testStartTLSInEHLO() throws Exception {
- m_testConfiguration.setStartTLS();
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setStartTLS();
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
// no message there, yet
assertNull("no mail received by mail server", queue.getLastMail());
@@ -490,10 +498,10 @@ public class SMTPServerTest {
*/
@Test
public void testSimpleMailSendWithHELO() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
// no message there, yet
assertNull("no mail received by mail server", queue.getLastMail());
@@ -515,12 +523,12 @@ public class SMTPServerTest {
@Test
public void testTwoSimultaneousMails() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
SMTPClient smtpProtocol2 = new SMTPClient();
- smtpProtocol2.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol2.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
assertTrue("second connection taken", smtpProtocol2.isConnected());
@@ -556,10 +564,10 @@ public class SMTPServerTest {
@Test
public void testTwoMailsInSequence() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -590,16 +598,16 @@ public class SMTPServerTest {
@Test
public void testHeloResolv() throws Exception {
- m_testConfiguration.setHeloResolv();
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1");
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setHeloResolv();
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1");
+ init(smtpConfiguration);
doTestHeloEhloResolv("helo");
}
private void doTestHeloEhloResolv(String heloCommand) throws IOException {
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol.isConnected());
@@ -633,10 +641,10 @@ public class SMTPServerTest {
@Test
public void testHeloResolvDefault() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
smtpProtocol1.helo("abgsfe3rsf.de");
// helo should not be checked. so this should give a 250 code
@@ -647,19 +655,19 @@ public class SMTPServerTest {
@Test
public void testReverseEqualsHelo() throws Exception {
- m_testConfiguration.setReverseEqualsHelo();
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1");
+ smtpConfiguration.setReverseEqualsHelo();
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1");
// temporary alter the loopback resolution
try {
- m_dnsServer.setLocalhostByName(InetAddress.getByName("james.apache.org"));
+ dnsServer.setLocalhostByName(InetAddress.getByName("james.apache.org"));
} catch (UnknownHostException e) {
fail("james.apache.org currently cannot be resolved (check your DNS/internet connection/proxy settings to make test pass)");
}
try {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -688,18 +696,18 @@ public class SMTPServerTest {
smtpProtocol1.quit();
} finally {
- m_dnsServer.setLocalhostByName(null);
+ dnsServer.setLocalhostByName(null);
}
}
@Test
public void testSenderDomainResolv() throws Exception {
- m_testConfiguration.setSenderDomainResolv();
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setSenderDomainResolv();
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1/32");
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -721,10 +729,10 @@ public class SMTPServerTest {
@Test
public void testSenderDomainResolvDefault() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
smtpProtocol1.helo(InetAddress.getLocalHost().toString());
@@ -737,11 +745,11 @@ public class SMTPServerTest {
@Test
public void testSenderDomainResolvRelayClientDefault() throws Exception {
- m_testConfiguration.setSenderDomainResolv();
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setSenderDomainResolv();
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -761,12 +769,12 @@ public class SMTPServerTest {
@Test
public void testSenderDomainResolvRelayClient() throws Exception {
- m_testConfiguration.setSenderDomainResolv();
- m_testConfiguration.setCheckAuthNetworks(true);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setSenderDomainResolv();
+ smtpConfiguration.setCheckAuthNetworks(true);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -789,11 +797,11 @@ public class SMTPServerTest {
@Test
public void testMaxRcpt() throws Exception {
- m_testConfiguration.setMaxRcpt(1);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setMaxRcpt(1);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -829,10 +837,10 @@ public class SMTPServerTest {
@Test
public void testMaxRcptDefault() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
smtpProtocol1.helo(InetAddress.getLocalHost().toString());
@@ -850,19 +858,19 @@ public class SMTPServerTest {
@Test
public void testEhloResolv() throws Exception {
- m_testConfiguration.setEhloResolv();
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1");
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setEhloResolv();
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1");
+ init(smtpConfiguration);
doTestHeloEhloResolv("ehlo");
}
@Test
public void testEhloResolvDefault() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
smtpProtocol1.sendCommand("ehlo", "abgsfe3rsf.de");
// ehlo should not be checked. so this should give a 250 code
@@ -873,30 +881,30 @@ public class SMTPServerTest {
@Test
public void testEhloResolvIgnoreClientDisabled() throws Exception {
- m_testConfiguration.setEhloResolv();
- m_testConfiguration.setCheckAuthNetworks(true);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setEhloResolv();
+ smtpConfiguration.setCheckAuthNetworks(true);
+ init(smtpConfiguration);
doTestHeloEhloResolv("ehlo");
}
@Test
public void testReverseEqualsEhlo() throws Exception {
- m_testConfiguration.setReverseEqualsEhlo();
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1");
+ smtpConfiguration.setReverseEqualsEhlo();
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1");
// temporary alter the loopback resolution
InetAddress jamesDomain = null;
try {
- jamesDomain = m_dnsServer.getByName("james.apache.org");
+ jamesDomain = dnsServer.getByName("james.apache.org");
} catch (UnknownHostException e) {
fail("james.apache.org currently cannot be resolved (check your DNS/internet connection/proxy settings to make test pass)");
}
- m_dnsServer.setLocalhostByName(jamesDomain);
+ dnsServer.setLocalhostByName(jamesDomain);
try {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -925,16 +933,16 @@ public class SMTPServerTest {
smtpProtocol1.quit();
} finally {
- m_dnsServer.setLocalhostByName(null);
+ dnsServer.setLocalhostByName(null);
}
}
@Test
public void testHeloEnforcement() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -954,11 +962,11 @@ public class SMTPServerTest {
@Test
public void testHeloEnforcementDisabled() throws Exception {
- m_testConfiguration.setHeloEhloEnforcement(false);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setHeloEhloEnforcement(false);
+ init(smtpConfiguration);
SMTPClient smtpProtocol1 = new SMTPClient();
- smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.connect("127.0.0.1", smtpListenerPort);
assertTrue("first connection taken", smtpProtocol1.isConnected());
@@ -974,12 +982,12 @@ public class SMTPServerTest {
@Test
public void testAuthCancel() throws Exception {
- m_testConfiguration.setAuthorizedAddresses("127.0.0.1/8");
- m_testConfiguration.setAuthorizingAnnounce();
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAuthorizedAddresses("127.0.0.1/8");
+ smtpConfiguration.setAuthorizingAnnounce();
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
@@ -998,12 +1006,12 @@ public class SMTPServerTest {
// Test for JAMES-939
@Test
public void testAuth() throws Exception {
- m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
- m_testConfiguration.setAuthorizingAnnounce();
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8");
+ smtpConfiguration.setAuthorizingAnnounce();
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
String[] capabilityRes = smtpProtocol.getReplyStrings();
@@ -1029,14 +1037,14 @@ public class SMTPServerTest {
smtpProtocol.addRecipient("mail@sample.com");
assertEquals("expected 530 error", 530, smtpProtocol.getReplyCode());
- assertFalse("user not existing", m_usersRepository.contains(noexistUserName));
+ assertFalse("user not existing", usersRepository.contains(noexistUserName));
smtpProtocol.sendCommand("AUTH PLAIN");
smtpProtocol.sendCommand(Base64.encodeAsString("\0" + noexistUserName + "\0pwd\0"));
// smtpProtocol.sendCommand(noexistUserName+"pwd".toCharArray());
assertEquals("expected error", 535, smtpProtocol.getReplyCode());
- m_usersRepository.addUser(userName, "pwd");
+ usersRepository.addUser(userName, "pwd");
smtpProtocol.sendCommand("AUTH PLAIN");
smtpProtocol.sendCommand(Base64.encodeAsString("\0" + userName + "\0wrongpwd\0"));
@@ -1060,17 +1068,17 @@ public class SMTPServerTest {
@Test
public void testAuthWithEmptySender() throws Exception {
- m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
- m_testConfiguration.setAuthorizingAnnounce();
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8");
+ smtpConfiguration.setAuthorizingAnnounce();
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
String userName = "test_user_smtp";
- m_usersRepository.addUser(userName, "pwd");
+ usersRepository.addUser(userName, "pwd");
smtpProtocol.setSender("");
@@ -1086,10 +1094,10 @@ public class SMTPServerTest {
@Test
public void testNoRecepientSpecified() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
@@ -1108,10 +1116,10 @@ public class SMTPServerTest {
@Test
public void testMultipleMailsAndRset() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
@@ -1129,11 +1137,11 @@ public class SMTPServerTest {
@Test
public void testRelayingDenied() throws Exception {
- m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8");
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
@@ -1145,11 +1153,11 @@ public class SMTPServerTest {
@Test
public void testHandleAnnouncedMessageSizeLimitExceeded() throws Exception {
- m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
@@ -1161,11 +1169,11 @@ public class SMTPServerTest {
}
public void testHandleMessageSizeLimitExceeded() throws Exception {
- m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
@@ -1197,11 +1205,11 @@ public class SMTPServerTest {
@Test
public void testHandleMessageSizeLimitRespected() throws Exception {
- m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
@@ -1232,15 +1240,15 @@ public class SMTPServerTest {
@Test
public void testDNSRBLNotRejectAuthUser() throws Exception {
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
- m_testConfiguration.setAuthorizingAnnounce();
- m_testConfiguration.useRBL(true);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1/32");
+ smtpConfiguration.setAuthorizingAnnounce();
+ smtpConfiguration.useRBL(true);
+ init(smtpConfiguration);
- m_dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1"));
+ dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1"));
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
String[] capabilityRes = smtpProtocol.getReplyStrings();
@@ -1259,7 +1267,7 @@ public class SMTPServerTest {
smtpProtocol.setSender(sender);
- m_usersRepository.addUser(userName, "pwd");
+ usersRepository.addUser(userName, "pwd");
smtpProtocol.sendCommand("AUTH PLAIN");
smtpProtocol.sendCommand(Base64.encodeAsString("\0" + userName + "\0pwd\0"));
@@ -1278,14 +1286,14 @@ public class SMTPServerTest {
@Test
public void testDNSRBLRejectWorks() throws Exception {
- m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
- m_testConfiguration.useRBL(true);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAuthorizedAddresses("192.168.0.1/32");
+ smtpConfiguration.useRBL(true);
+ init(smtpConfiguration);
- m_dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1"));
+ dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1"));
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
@@ -1306,10 +1314,10 @@ public class SMTPServerTest {
@Test
public void testAddressBracketsEnforcementDisabled() throws Exception {
- m_testConfiguration.setAddressBracketsEnforcement(false);
- finishSetUp(m_testConfiguration);
+ smtpConfiguration.setAddressBracketsEnforcement(false);
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
@@ -1321,7 +1329,7 @@ public class SMTPServerTest {
smtpProtocol.quit();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
@@ -1336,9 +1344,9 @@ public class SMTPServerTest {
@Test
public void testAddressBracketsEnforcementEnabled() throws Exception {
- finishSetUp(m_testConfiguration);
+ init(smtpConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
- smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol.connect("127.0.0.1", smtpListenerPort);
smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
@@ -1359,8 +1367,8 @@ public class SMTPServerTest {
@Test
public void testPipelining() throws Exception {
StringBuilder buf = new StringBuilder();
- finishSetUp(m_testConfiguration);
- Socket client = new Socket("127.0.0.1", m_smtpListenerPort);
+ init(smtpConfiguration);
+ Socket client = new Socket("127.0.0.1", smtpListenerPort);
buf.append("HELO TEST");
buf.append("\r\n");
@@ -1403,9 +1411,9 @@ public class SMTPServerTest {
@Test
public void testRejectAllRCPTPipelining() throws Exception {
StringBuilder buf = new StringBuilder();
- m_testConfiguration.setAuthorizedAddresses("");
- finishSetUp(m_testConfiguration);
- Socket client = new Socket("127.0.0.1", m_smtpListenerPort);
+ smtpConfiguration.setAuthorizedAddresses("");
+ init(smtpConfiguration);
+ Socket client = new Socket("127.0.0.1", smtpListenerPort);
buf.append("HELO TEST");
buf.append("\r\n");
@@ -1449,9 +1457,9 @@ public class SMTPServerTest {
@Test
public void testRejectOneRCPTPipelining() throws Exception {
StringBuilder buf = new StringBuilder();
- m_testConfiguration.setAuthorizedAddresses("");
- finishSetUp(m_testConfiguration);
- Socket client = new Socket("127.0.0.1", m_smtpListenerPort);
+ smtpConfiguration.setAuthorizedAddresses("");
+ init(smtpConfiguration);
+ Socket client = new Socket("127.0.0.1", smtpListenerPort);
buf.append("HELO TEST");
buf.append("\r\n");
Modified: james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java?rev=1443949&r1=1443948&r2=1443949&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java (original)
+++ james/server/trunk/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java Fri Feb 8 11:40:42 2013
@@ -51,10 +51,12 @@ public class ValidRcptHandlerTest {
@Before
public void setUp() throws Exception {
+
users = new MockUsersRepository();
users.addUser(VALID_USER, "xxx");
+
handler = new ValidRcptHandler();
- handler.setUsers(users);
+ handler.setUsersRepository(users);
handler.setRecipientRewriteTable(setUpRecipientRewriteTable());
handler.setDomainList(new SimpleDomainList() {
@@ -298,4 +300,5 @@ public class ValidRcptHandlerTest {
assertNull("Valid Error mapping", session.getAttachment("VALID_USER", State.Transaction));
assertEquals("Error mapping", rCode, HookReturnCode.DENY);
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org