james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [14/15] james-project git commit: JAMES-2406 String typing for SMTP port
Date Wed, 06 Jun 2018 07:01:08 GMT
JAMES-2406 String typing for SMTP port


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f9bcbf90
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f9bcbf90
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f9bcbf90

Branch: refs/heads/master
Commit: f9bcbf9070a02e6c90f6f6d88710192c585d09b7
Parents: a1c8bfc
Author: benwa <btellier@linagora.com>
Authored: Thu May 31 17:30:43 2018 +0700
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Wed Jun 6 09:00:10 2018 +0200

----------------------------------------------------------------------
 .../james/mpt/ant/MailProtocolTestTask.java     | 26 +++++++++++---------
 .../org/apache/james/mpt/ant/TestAddUser.java   |  4 +--
 .../apache/james/mpt/ant/TestRunScripts.java    |  2 +-
 .../java/org/apache/james/mpt/app/Main.java     |  3 ++-
 .../org/apache/james/mpt/app/RunScript.java     |  7 +++---
 .../james/mpt/host/ExternalHostSystem.java      |  3 ++-
 .../mpt/session/ExternalSessionFactory.java     |  5 ++--
 .../james/mpt/user/ScriptedUserAdder.java       | 11 +++++----
 .../org/apache/james/mpt/DiscardProtocol.java   |  7 +++---
 .../apache/james/mpt/TestDiscardProtocol.java   |  2 +-
 .../mpt/smtp/CassandraForwardSmtpTest.java      |  2 +-
 .../smtp/CassandraSmtpStarttlsCommandTest.java  |  2 +-
 .../apache/james/mpt/smtp/SmtpTestModule.java   | 15 +++--------
 .../smtp/host/CassandraJamesSmtpHostSystem.java |  3 ++-
 .../org/apache/james/mpt/maven/AddUser.java     | 11 ++++++---
 .../james/mpt/maven/MailProtocolTest.java       |  7 +++---
 16 files changed, 59 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
----------------------------------------------------------------------
diff --git a/mpt/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java b/mpt/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
index 04acf3c..6d3a08b 100644
--- a/mpt/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
+++ b/mpt/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
@@ -28,6 +28,7 @@ import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.Optional;
 
 import org.apache.james.mpt.Runner;
 import org.apache.james.mpt.api.ImapFeatures;
@@ -36,6 +37,7 @@ import org.apache.james.mpt.api.Monitor;
 import org.apache.james.mpt.host.ExternalHostSystem;
 import org.apache.james.mpt.protocol.ProtocolSessionBuilder;
 import org.apache.james.mpt.user.ScriptedUserAdder;
+import org.apache.james.util.Port;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
@@ -55,7 +57,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
     private boolean quiet = false;
     private File script;
     private Union scripts;
-    private int port = 0;
+    private Optional<Port> port = Optional.empty();
     private String host = "127.0.0.1";
     private boolean skip = false;
     private String shabang = null;
@@ -139,7 +141,9 @@ public class MailProtocolTestTask extends Task implements Monitor {
      * @return port number
      */
     public int getPort() {
-        return port;
+        return port
+            .map(Port::getValue)
+            .orElseThrow(() -> new RuntimeException("Port must be set"));
     }
 
     /**
@@ -147,7 +151,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
      * @param port port number
      */
     public void setPort(int port) {
-        this.port = port;
+        this.port = Optional.of(new Port(port));
     }
 
     /**
@@ -189,8 +193,8 @@ public class MailProtocolTestTask extends Task implements Monitor {
 
     @Override
     public void execute() throws BuildException {
-        if (port <= 0) {
-            throw new BuildException("Port must be set to a positive integer");
+        if (! port.isPresent()) {
+            throw new BuildException("Port must be set");
         }
         
         if (scripts == null && script == null) {
@@ -232,7 +236,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
             userAdder.execute();
         }
         
-        final ExternalHostSystem host = new ExternalHostSystem(SUPPORTED_FEATURES, getHost(),
getPort(), this, getShabang(), null);
+        final ExternalHostSystem host = new ExternalHostSystem(SUPPORTED_FEATURES, getHost(),
port.get(), this, getShabang(), null);
         final ProtocolSessionBuilder builder = new ProtocolSessionBuilder();
         
         if (scripts == null) {
@@ -277,7 +281,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
      */
     public class AddUser {
         
-        private int port;
+        private Port port;
         private String user;
         private String passwd;
         private File script;
@@ -289,7 +293,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
          * @return port number
          */
         public int getPort() {
-            return port;
+            return port.getValue();
         }
 
         /**
@@ -298,7 +302,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
          * @param port port number
          */
         public void setPort(int port) {
-            this.port = port;
+            this.port = new Port(port);
         }
 
         /**
@@ -370,7 +374,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
                 throw new BuildException("Choose either script text or script attribute but
not both.");
             }
             
-            if (port <= 0) {
+            if (port == null) {
                 throw new BuildException("'port' attribute must be set on AddUser to the
port against which the script should run.");
             }
         }
@@ -389,7 +393,7 @@ public class MailProtocolTestTask extends Task implements Monitor {
                 } else {
                     reader = new FileReader(scriptFile);
                 }
-                final ScriptedUserAdder adder = new ScriptedUserAdder(getHost(), getPort(),
MailProtocolTestTask.this);
+                final ScriptedUserAdder adder = new ScriptedUserAdder(getHost(), port, MailProtocolTestTask.this);
                 adder.addUser(getUser(), getPasswd(), reader);
             } catch (Exception e) {
                 log(e.getMessage(), Project.MSG_ERR);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java
----------------------------------------------------------------------
diff --git a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java
index 7eba9e99..aabc2e1 100644
--- a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java
+++ b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java
@@ -42,7 +42,7 @@ public class TestAddUser extends TestCase {
         
         subject = new MailProtocolTestTask();
         subject.setHost("127.0.0.1");
-        subject.setPort(fakeServer.getPort());
+        subject.setPort(fakeServer.getPort().getValue());
         subject.add(new Union());
         subject.setProject(new Project());
     }
@@ -55,7 +55,7 @@ public class TestAddUser extends TestCase {
 
     public void testShouldExecuteScriptAgainstPort() throws Exception {
         MailProtocolTestTask.AddUser user = subject.createAddUser();
-        user.setPort(fakeServer.getPort());
+        user.setPort(fakeServer.getPort().getValue());
         user.setPasswd("PASSWORD");
         user.setUser("USER");
         final String script = "This script adds a user";

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java
----------------------------------------------------------------------
diff --git a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java
index 5c5e92d..9472f1d 100644
--- a/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java
+++ b/mpt/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java
@@ -56,7 +56,7 @@ public class TestRunScripts extends TestCase {
         
         subject = new MailProtocolTestTask();
         subject.setHost("127.0.0.1");
-        subject.setPort(fakeServer.getPort());
+        subject.setPort(fakeServer.getPort().getValue());
         subject.setProject(new Project());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/app/src/main/java/org/apache/james/mpt/app/Main.java
----------------------------------------------------------------------
diff --git a/mpt/app/src/main/java/org/apache/james/mpt/app/Main.java b/mpt/app/src/main/java/org/apache/james/mpt/app/Main.java
index 63d243c..4e3f3ea 100644
--- a/mpt/app/src/main/java/org/apache/james/mpt/app/Main.java
+++ b/mpt/app/src/main/java/org/apache/james/mpt/app/Main.java
@@ -28,6 +28,7 @@ import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.james.util.Port;
 
 /**
  * <p>Runs MPT application.</p>
@@ -73,7 +74,7 @@ public class Main {
         File file = new File(cmd.getOptionValue(FILE_OPTION));
         if (file.exists()) {
             try {
-                int port = Integer.parseInt(cmd.getOptionValue(PORT_OPTION));    
+                Port port = new Port(Integer.parseInt(cmd.getOptionValue(PORT_OPTION)));
   
                 String host = cmd.getOptionValue(HOST_OPTION, "localhost");
                 String shabang = cmd.getOptionValue(SHABANG_OPTION, null);
                 RunScript runner = new RunScript(file, port, host, shabang, verbose);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/app/src/main/java/org/apache/james/mpt/app/RunScript.java
----------------------------------------------------------------------
diff --git a/mpt/app/src/main/java/org/apache/james/mpt/app/RunScript.java b/mpt/app/src/main/java/org/apache/james/mpt/app/RunScript.java
index 707718c..9621ccb 100644
--- a/mpt/app/src/main/java/org/apache/james/mpt/app/RunScript.java
+++ b/mpt/app/src/main/java/org/apache/james/mpt/app/RunScript.java
@@ -28,6 +28,7 @@ import org.apache.james.mpt.api.ImapFeatures.Feature;
 import org.apache.james.mpt.host.ExternalHostSystem;
 import org.apache.james.mpt.monitor.SystemLoggingMonitor;
 import org.apache.james.mpt.protocol.ProtocolSessionBuilder;
+import org.apache.james.util.Port;
 
 /**
  * Runs a single script.
@@ -37,12 +38,12 @@ class RunScript {
     private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT);
     
     private final File file;
-    private final int port;
+    private final Port port;
     private final String host;
     private final String shabang;
     private final SystemLoggingMonitor monitor;
     
-    public RunScript(File file, int port, String host, String shabang, boolean verbose) {
+    public RunScript(File file, Port port, String host, String shabang, boolean verbose)
{
         super();
         this.file = file;
         this.port = port;
@@ -55,7 +56,7 @@ class RunScript {
      * Runs the script.
      */
     public void run() throws Exception {
-       System.out.println("Running " + file + " against " + host + ":"  + port + "...");
+       System.out.println("Running " + file + " against " + host + ":"  + port.getValue()
+ "...");
        
        final ExternalHostSystem host = new ExternalHostSystem(SUPPORTED_FEATURES, this.host,
port, monitor, shabang, null);
        final ProtocolSessionBuilder builder = new ProtocolSessionBuilder();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java b/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
index ffbbafe..53a1972 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/host/ExternalHostSystem.java
@@ -30,6 +30,7 @@ import org.apache.james.mpt.api.ImapHostSystem;
 import org.apache.james.mpt.api.Monitor;
 import org.apache.james.mpt.api.UserAdder;
 import org.apache.james.mpt.session.ExternalSessionFactory;
+import org.apache.james.util.Port;
 
 /**
  * <p>
@@ -67,7 +68,7 @@ public class ExternalHostSystem extends ExternalSessionFactory implements
ImapHo
      * @param userAdder
      *            null when test system has appropriate users already set
      */
-    public ExternalHostSystem(ImapFeatures features, String host, int port, 
+    public ExternalHostSystem(ImapFeatures features, String host, Port port,
             Monitor monitor, String shabang, UserAdder userAdder) {
         super(host, port, monitor, shabang);
         this.features = features;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSessionFactory.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSessionFactory.java
b/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSessionFactory.java
index f1fbaf0..0abcdfb 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSessionFactory.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSessionFactory.java
@@ -26,6 +26,7 @@ import org.apache.james.mpt.api.Continuation;
 import org.apache.james.mpt.api.Monitor;
 import org.apache.james.mpt.api.Session;
 import org.apache.james.mpt.api.SessionFactory;
+import org.apache.james.util.Port;
 
 /**
  * Session factory creates session which connection to a server port.
@@ -41,8 +42,8 @@ public class ExternalSessionFactory implements SessionFactory {
         this(null, monitor, shabang);
     }
     
-    public ExternalSessionFactory(String host, int port, Monitor monitor, String shabang)
{
-        this(new InetSocketAddress(host, port), monitor, shabang);
+    public ExternalSessionFactory(String host, Port port, Monitor monitor, String shabang)
{
+        this(new InetSocketAddress(host, port.getValue()), monitor, shabang);
     }
 
     public ExternalSessionFactory(InetSocketAddress address, Monitor monitor, String shabang)
{

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/core/src/main/java/org/apache/james/mpt/user/ScriptedUserAdder.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/user/ScriptedUserAdder.java b/mpt/core/src/main/java/org/apache/james/mpt/user/ScriptedUserAdder.java
index 5f6eeca..51c0485 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/user/ScriptedUserAdder.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/user/ScriptedUserAdder.java
@@ -28,6 +28,7 @@ import org.apache.james.mpt.api.UserAdder;
 import org.apache.james.mpt.monitor.NullMonitor;
 import org.apache.james.mpt.protocol.ProtocolSessionBuilder;
 import org.apache.james.mpt.session.ExternalSessionFactory;
+import org.apache.james.util.Port;
 
 /**
  * Adds a user by executing a script at a port.
@@ -41,7 +42,7 @@ public class ScriptedUserAdder implements UserAdder {
     private static final String USER_VARIABLE_NAME = "user";
     
     private final String host;
-    private final int port;
+    private final Port port;
     private final String script;
     private final Monitor monitor;
     
@@ -51,11 +52,11 @@ public class ScriptedUserAdder implements UserAdder {
      * @param host connect to this host
      * @param port connect to this port
      */
-    public ScriptedUserAdder(String host, int port) {
+    public ScriptedUserAdder(String host, Port port) {
         this(host, port, (String) null);
     }
     
-    public ScriptedUserAdder(String host, int port, String script) {
+    public ScriptedUserAdder(String host, Port port, String script) {
         this(host, port, script, new NullMonitor());
     }
     
@@ -65,11 +66,11 @@ public class ScriptedUserAdder implements UserAdder {
      * @param port connect to this port
      * @param monitor not null
      */
-    public ScriptedUserAdder(String host, int port, Monitor monitor) {
+    public ScriptedUserAdder(String host, Port port, Monitor monitor) {
         this(host, port, null, monitor);
     }
     
-    public ScriptedUserAdder(String host, int port, String script, Monitor monitor) {
+    public ScriptedUserAdder(String host, Port port, String script, Monitor monitor) {
         this.host = host;
         this.port = port;
         this.script = script;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java b/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
index 53dfd5d..d27bacc 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
@@ -32,6 +32,7 @@ import java.util.Queue;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.james.util.Port;
 
 /**
  * Simple <a href='http://tools.ietf.org/html/rfc863'>RFC 863</a> implementation.
@@ -47,7 +48,7 @@ public class DiscardProtocol {
     private static final Log LOG = LogFactory.getLog(DiscardProtocol.class);
     
     /** Serve on this port */
-    private int port;
+    private Port port;
     
     /** 
      * Queues requests for recordings.
@@ -80,7 +81,7 @@ public class DiscardProtocol {
             if (socket == null) {
                 socket = ServerSocketChannel.open();
                 socket.socket().bind(new InetSocketAddress(0));
-                port = socket.socket().getLocalPort();
+                port = new Port(socket.socket().getLocalPort());
                 // only going to record a single conversation
                 socket.configureBlocking(false);
                 
@@ -93,7 +94,7 @@ public class DiscardProtocol {
         }
     }
     
-    public int getPort() {
+    public Port getPort() {
         return port;
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java b/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java
index 787a426..bc30917 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/TestDiscardProtocol.java
@@ -63,7 +63,7 @@ public class TestDiscardProtocol extends TestCase {
         super.setUp();
         protocol = new DiscardProtocol();
         protocol.start();
-        socket = SocketFactory.getDefault().createSocket("127.0.0.1", protocol.getPort());
+        socket = SocketFactory.getDefault().createSocket("127.0.0.1", protocol.getPort().getValue());
         record = protocol.recordNext();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
index 6f82b82..abc50df 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
@@ -37,7 +37,7 @@ public class CassandraForwardSmtpTest extends ForwardSmtpTest {
     @Before
     public void setUp() throws Exception {
         Injector injector = Guice.createInjector(
-                new SmtpTestModule(SmtpTestModule.Port.SMTP, cassandraServer.getHost()));
+                new SmtpTestModule(SmtpTestModule.SMTP_PORT, cassandraServer.getHost()));
         system = injector.getInstance(SmtpHostSystem.class);
         system.beforeTest();
         super.setUp();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
index e76ff05..18f052c 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
@@ -37,7 +37,7 @@ public class CassandraSmtpStarttlsCommandTest extends SmtpStarttlsCommandTest
{
     @Before
     public void setUp() throws Exception {
         Injector injector = Guice.createInjector(
-                new SmtpTestModule(SmtpTestModule.Port.SMTP_START_TTLS, cassandraServer.getHost()));
+                new SmtpTestModule(SmtpTestModule.SMTP_START_TLS_PORT, cassandraServer.getHost()));
         system = injector.getInstance(SmtpHostSystem.class);
         system.beforeTest();
         super.setUp();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/SmtpTestModule.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/SmtpTestModule.java
b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/SmtpTestModule.java
index eea9106..fa87b4b 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/SmtpTestModule.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/SmtpTestModule.java
@@ -20,21 +20,14 @@ package org.apache.james.mpt.smtp;
 
 import org.apache.james.mpt.smtp.host.CassandraJamesSmtpHostSystem;
 import org.apache.james.util.Host;
+import org.apache.james.util.Port;
 
 import com.google.inject.AbstractModule;
 
 public class SmtpTestModule extends AbstractModule {
 
-    enum Port {
-        SMTP(1025),
-        SMTP_START_TTLS(1587);
-        
-        private int port;
-
-        Port(int port) {
-            this.port = port;
-        }
-    }
+    public static Port SMTP_PORT = new Port(1025);
+    public static Port SMTP_START_TLS_PORT = new Port(1587);
 
     private final Port smtpPort;
     private final Host cassandraHost;
@@ -46,7 +39,7 @@ public class SmtpTestModule extends AbstractModule {
     
     @Override
     protected void configure() {
-        bind(SmtpHostSystem.class).toInstance(new CassandraJamesSmtpHostSystem(smtpPort.port,
cassandraHost));
+        bind(SmtpHostSystem.class).toInstance(new CassandraJamesSmtpHostSystem(smtpPort,
cassandraHost));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
index 86dcd33..3d2d65b 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
@@ -37,6 +37,7 @@ import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
 import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
 import org.apache.james.server.core.configuration.Configuration;
 import org.apache.james.util.Host;
+import org.apache.james.util.Port;
 import org.apache.james.utils.DataProbeImpl;
 import org.junit.rules.TemporaryFolder;
 
@@ -58,7 +59,7 @@ public class CassandraJamesSmtpHostSystem extends ExternalSessionFactory
impleme
     private final Host cassandraHost;
 
 
-    public CassandraJamesSmtpHostSystem(int smtpPort, Host cassandraHost) {
+    public CassandraJamesSmtpHostSystem(Port smtpPort, Host cassandraHost) {
         super("localhost", smtpPort, new SystemLoggingMonitor(), "220 mydomain.tld smtp");
         this.cassandraHost = cassandraHost;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/AddUser.java
----------------------------------------------------------------------
diff --git a/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/AddUser.java b/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/AddUser.java
index 1bfa1de..e8c2e2c 100644
--- a/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/AddUser.java
+++ b/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/AddUser.java
@@ -20,6 +20,9 @@
 package org.apache.james.mpt.maven;
 
 import java.io.File;
+import java.util.Optional;
+
+import org.apache.james.util.Port;
 
 
 /**
@@ -27,7 +30,7 @@ import java.io.File;
  */
 public class AddUser {
     
-    private int port;
+    private Optional<Port> port = Optional.empty();
     private String user;
     private String passwd;
     private String scriptText;
@@ -52,7 +55,7 @@ public class AddUser {
      * script should be executed.
      * @return port number
      */
-    public int getPort() {
+    public Optional<Port> getPort() {
         return port;
     }
 
@@ -61,8 +64,8 @@ public class AddUser {
      * script should be executed.
      * @param port port number
      */
-    public void setPort(int port) {
-        this.port = port;
+    public void setPort(Port port) {
+        this.port = Optional.of(port);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/f9bcbf90/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/MailProtocolTest.java
----------------------------------------------------------------------
diff --git a/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/MailProtocolTest.java
b/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/MailProtocolTest.java
index a9a6eb5..1b575f9 100644
--- a/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/MailProtocolTest.java
+++ b/mpt/mavenplugin/src/main/java/org/apache/james/mpt/maven/MailProtocolTest.java
@@ -34,6 +34,7 @@ import org.apache.james.mpt.api.Monitor;
 import org.apache.james.mpt.host.ExternalHostSystem;
 import org.apache.james.mpt.protocol.ProtocolSessionBuilder;
 import org.apache.james.mpt.user.ScriptedUserAdder;
+import org.apache.james.util.Port;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
@@ -104,7 +105,7 @@ public class MailProtocolTest implements Monitor {
                 } else {
                     reader = new FileReader(addUser.getScriptFile());
                 }
-                final ScriptedUserAdder adder = new ScriptedUserAdder(addUser.getHost(),
addUser.getPort(), this);
+                final ScriptedUserAdder adder = new ScriptedUserAdder(addUser.getHost(),
addUser.getPort().orElseThrow(() -> new RuntimeException("Port should be set")), this);
                 adder.addUser(addUser.getUser(), addUser.getPasswd(), reader);
             } catch (Exception e) {
                 //getLog().error("Unable to add user", e);
@@ -116,7 +117,7 @@ public class MailProtocolTest implements Monitor {
         try {
             inputStream = new FileInputStream(scriptFile);
 
-            final ExternalHostSystem hostSystem = new ExternalHostSystem(SUPPORTED_FEATURES,
host, port, this, shabang, null);
+            final ExternalHostSystem hostSystem = new ExternalHostSystem(SUPPORTED_FEATURES,
host, new Port(port), this, shabang, null);
             final ProtocolSessionBuilder builder = new ProtocolSessionBuilder();
 
             builder.addProtocolLines(scriptFile.getName(), inputStream, runner.getTestElements());
@@ -150,7 +151,7 @@ public class MailProtocolTest implements Monitor {
                 throw new MojoFailureException("AddUser must contain the text of the script
or a scriptFile");
             }
 
-            if (addUser.getPort() <= 0) {
+            if (! addUser.getPort().isPresent()) {
                 throw new MojoFailureException("'port' attribute must be set on AddUser to
the port against which the script should run.");
             }
 


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