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 rd...@apache.org on 2008/11/26 00:13:47 UTC

svn commit: r720645 - in /james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt: ExternalHostSystem.java Monitor.java SystemLoggingMonitor.java

Author: rdonkin
Date: Tue Nov 25 15:13:46 2008
New Revision: 720645

URL: http://svn.apache.org/viewvc?rev=720645&view=rev
Log:
Factor out IMAP specifics

Added:
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Monitor.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SystemLoggingMonitor.java
Modified:
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java

Modified: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java?rev=720645&r1=720644&r2=720645&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java Tue Nov 25 15:13:46 2008
@@ -24,23 +24,35 @@
 import java.nio.channels.SocketChannel;
 import java.nio.charset.Charset;
 
+/**
+ * Connects to a host system serving on an open port.
+ */
 public class ExternalHostSystem implements HostSystem {
 
-    public static final HostSystem createLocalImap() {
-        final ExternalHostSystem result = new ExternalHostSystem("localhost",
-                143, new SystemLoggingMonitor());
-        return result;
-    }
+    public static final String IMAP_SHABANG = "* OK IMAP4rev1 Server ready";
 
     private final InetSocketAddress address;
 
     private final Monitor monitor;
 
+    private final String shabang;
+
+    /**
+     * Constructs a host system suitable for connection to an open port.
+     * @param host host name that will be connected to, not null
+     * @param port port on host that will be connected to, not null
+     * @param monitor monitors the conduct of the connection
+     * @param shabang protocol shabang will be sent to the script test in the place of the
+     * first line received from the server. Many protocols pass server specific information
+     * in the first line. When not null, this line will be replaced.
+     * Or null when the first line should be passed without replacement
+     */
     public ExternalHostSystem(final String host, final int port,
-            final Monitor monitor) {
+            final Monitor monitor, final String shabang) {
         super();
         this.address = new InetSocketAddress(host, port);
         this.monitor = monitor;
+        this.shabang = shabang;
     }
 
     public boolean addUser(String user, String password) throws Exception {
@@ -52,7 +64,7 @@
     public Session newSession(Continuation continuation) throws Exception {
         final SocketChannel channel = SocketChannel.open(address);
         channel.configureBlocking(false);
-        final SessionImpl result = new SessionImpl(channel, monitor);
+        final SessionImpl result = new SessionImpl(channel, monitor, shabang);
         return result;
     }
 
@@ -60,18 +72,6 @@
         monitor.note("Please reset system.");
     }
 
-    public interface Monitor {
-        void note(String message);
-    }
-
-    public static final class SystemLoggingMonitor implements Monitor {
-
-        public void note(String message) {
-            System.out.println(message);
-        }
-
-    }
-
     private final static class SessionImpl implements Session {
 
         private static final byte[] CRLF = { '\r', '\n' };
@@ -88,23 +88,26 @@
 
         private boolean first = true;
 
-        public SessionImpl(final SocketChannel socket, final Monitor monitor) {
+        private final String shabang;
+
+        public SessionImpl(final SocketChannel socket, final Monitor monitor, String shabang) {
             super();
             this.socket = socket;
             this.monitor = monitor;
             readBuffer = ByteBuffer.allocateDirect(2048);
             ascii = Charset.forName("US-ASCII");
             lineEndBuffer = ByteBuffer.wrap(CRLF);
+            this.shabang = shabang;
         }
 
         public String readLine() throws Exception {
             StringBuffer buffer = new StringBuffer();
             readlineInto(buffer);
             final String result;
-            if (first) {
+            if (first && shabang != null) {
                 // fake shabang
                 monitor.note("<-" + buffer.toString());
-                result = "* OK IMAP4rev1 Server ready";
+                result = shabang;
                 first = false;
             } else {
                 result = buffer.toString();

Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Monitor.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Monitor.java?rev=720645&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Monitor.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Monitor.java Tue Nov 25 15:13:46 2008
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mpt;
+
+/**
+ * Monitors the conduct of a process.
+ * Allows the caller to control the output of the logged information.
+ */
+public interface Monitor {
+    void note(String message);
+}
\ No newline at end of file

Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SystemLoggingMonitor.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SystemLoggingMonitor.java?rev=720645&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SystemLoggingMonitor.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SystemLoggingMonitor.java Tue Nov 25 15:13:46 2008
@@ -0,0 +1,31 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mpt;
+
+/**
+ * Feeds monitored information to {@link System#out}.
+ */
+public final class SystemLoggingMonitor implements Monitor {
+
+    public void note(String message) {
+        System.out.println(message);
+    }
+
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org