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/27 22:30:36 UTC

svn commit: r721281 - in /james/protocol-tester/trunk/main/src: main/java/org/apache/james/mpt/ test/java/org/apache/james/mpt/

Author: rdonkin
Date: Thu Nov 27 13:30:36 2008
New Revision: 721281

URL: http://svn.apache.org/viewvc?rev=721281&view=rev
Log:
Created scriptable AddUser implementation. The plan is to use a script to connect to the remote manager which will add the required users.

Added:
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSession.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSessionFactory.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/InvalidServerResponseException.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSessionBuilder.java
      - copied, changed from r721269, james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java
    james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java
Removed:
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java
Modified:
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSession.java
    james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java
    james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
    james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java

Modified: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java?rev=721281&r1=721280&r2=721281&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java Thu Nov 27 13:30:36 2008
@@ -32,7 +32,7 @@
  */
 public abstract class AbstractSimpleScriptedTestProtocol extends
         AbstractProtocolTestFramework {
-    private FileProtocolSessionBuilder builder = new FileProtocolSessionBuilder();
+    private ProtocolSessionBuilder builder = new ProtocolSessionBuilder();
 
     private static final Locale BASE_DEFAULT_LOCALE = Locale.getDefault();
 

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=721281&r1=721280&r2=721281&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 Thu Nov 27 13:30:36 2008
@@ -19,24 +19,12 @@
 
 package org.apache.james.mpt;
 
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-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 class ExternalHostSystem extends ExternalSessionFactory implements HostSystem {
 
-    public static final String IMAP_SHABANG = "* OK IMAP4rev1 Server ready";
-
-    private final InetSocketAddress address;
-
-    private final Monitor monitor;
-
-    private final String shabang;
-    
     private final UserAdder userAdder;
 
     /**
@@ -52,10 +40,7 @@
      */
     public ExternalHostSystem(final String host, final int port,
             final Monitor monitor, final String shabang, final UserAdder userAdder) {
-        super();
-        this.address = new InetSocketAddress(host, port);
-        this.monitor = monitor;
-        this.shabang = shabang;
+        super(host, port, monitor, shabang);
         this.userAdder = userAdder;
     }
 
@@ -67,113 +52,4 @@
             userAdder.addUser(user, password);
         }
     }
-
-    public Session newSession(Continuation continuation) throws Exception {
-        final SocketChannel channel = SocketChannel.open(address);
-        channel.configureBlocking(false);
-        final SessionImpl result = new SessionImpl(channel, monitor, shabang);
-        return result;
-    }
-
-    public void reset() throws Exception {
-        monitor.note("Please reset system.");
-    }
-
-    private final static class SessionImpl implements Session {
-
-        private static final byte[] CRLF = { '\r', '\n' };
-
-        private final SocketChannel socket;
-
-        private final Monitor monitor;
-
-        private final ByteBuffer readBuffer;
-
-        private final Charset ascii;
-
-        private final ByteBuffer lineEndBuffer;
-
-        private boolean first = true;
-
-        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 && shabang != null) {
-                // fake shabang
-                monitor.note("<-" + buffer.toString());
-                result = shabang;
-                first = false;
-            } else {
-                result = buffer.toString();
-                monitor.note("<-" + result);
-            }
-            return result;
-        }
-
-        private void readlineInto(StringBuffer buffer) throws Exception {
-            while (socket.read(readBuffer) == 0)
-                ;
-            readBuffer.flip();
-            while (readOneMore(buffer))
-                ;
-            readBuffer.compact();
-        }
-
-        private boolean readOneMore(StringBuffer buffer) throws Exception {
-            final boolean result;
-            if (readBuffer.hasRemaining()) {
-                char next = (char) readBuffer.get();
-                if (next == '\n') {
-                    result = false;
-                } else if (next == '\r') {
-                    result = true;
-                } else {
-                    buffer.append(next);
-                    result = true;
-                }
-            } else {
-                readBuffer.clear();
-                readlineInto(buffer);
-                result = true;
-            }
-            return result;
-        }
-
-        public void start() throws Exception {
-            while (!socket.finishConnect()) {
-                monitor.note("connecting...");
-                Thread.sleep(10);
-            }
-        }
-
-        public void stop() throws Exception {
-            monitor.note("closing");
-            socket.close();
-        }
-
-        public void writeLine(String line) throws Exception {
-            monitor.note("-> " + line);
-            ByteBuffer writeBuffer = ascii.encode(line);
-            while (writeBuffer.hasRemaining()) {
-                socket.write(writeBuffer);
-            }
-            lineEndBuffer.rewind();
-            while (lineEndBuffer.hasRemaining()) {
-                socket.write(lineEndBuffer);
-            }
-        }
-    }
 }

Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSession.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSession.java?rev=721281&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSession.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSession.java Thu Nov 27 13:30:36 2008
@@ -0,0 +1,148 @@
+/****************************************************************
+ * 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;
+
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+final class ExternalSession implements Session {
+
+    private static final byte[] CRLF = { '\r', '\n' };
+
+    private final SocketChannel socket;
+
+    private final Monitor monitor;
+
+    private final ByteBuffer readBuffer;
+
+    private final Charset ascii;
+
+    private final ByteBuffer lineEndBuffer;
+
+    private boolean first = true;
+
+    private final String shabang;
+
+    public ExternalSession(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 && shabang != null) {
+            // fake shabang
+            monitor.note("<-" + buffer.toString());
+            result = shabang;
+            first = false;
+        } else {
+            result = buffer.toString();
+            monitor.note("<-" + result);
+        }
+        return result;
+    }
+
+    private void readlineInto(StringBuffer buffer) throws Exception {
+        while (socket.read(readBuffer) == 0)
+            ;
+        readBuffer.flip();
+        while (readOneMore(buffer))
+            ;
+        readBuffer.compact();
+    }
+
+    private boolean readOneMore(StringBuffer buffer) throws Exception {
+        final boolean result;
+        if (readBuffer.hasRemaining()) {
+            char next = (char) readBuffer.get();
+            if (next == '\n') {
+                result = false;
+            } else if (next == '\r') {
+                result = true;
+            } else {
+                buffer.append(next);
+                result = true;
+            }
+        } else {
+            readBuffer.clear();
+            readlineInto(buffer);
+            result = true;
+        }
+        return result;
+    }
+
+    public void start() throws Exception {
+        while (!socket.finishConnect()) {
+            monitor.note("connecting...");
+            Thread.sleep(10);
+        }
+    }
+
+    public void stop() throws Exception {
+        monitor.note("closing");
+        socket.close();
+    }
+
+    public void writeLine(String line) throws Exception {
+        monitor.note("-> " + line);
+        ByteBuffer writeBuffer = ascii.encode(line);
+        while (writeBuffer.hasRemaining()) {
+            socket.write(writeBuffer);
+        }
+        lineEndBuffer.rewind();
+        while (lineEndBuffer.hasRemaining()) {
+            socket.write(lineEndBuffer);
+        }
+    }
+
+    /**
+     * Constructs a <code>String</code> with all attributes
+     * in name = value format.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        final String TAB = " ";
+        
+        String result =  "External ( "
+            + "socket = " + this.socket + TAB
+            + "monitor = " + this.monitor + TAB
+            + "readBuffer = " + this.readBuffer + TAB
+            + "ascii = " + this.ascii + TAB
+            + "lineEndBuffer = " + this.lineEndBuffer + TAB
+            + "first = " + this.first + TAB
+            + "shabang = " + this.shabang + TAB
+            + " )";
+    
+        return result;
+    }
+    
+    
+}
\ No newline at end of file

Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSessionFactory.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSessionFactory.java?rev=721281&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSessionFactory.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalSessionFactory.java Thu Nov 27 13:30:36 2008
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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;
+
+import java.net.InetSocketAddress;
+import java.nio.channels.SocketChannel;
+
+import org.apache.james.mpt.HostSystem.Continuation;
+
+/**
+ * Session factory creates session which connection to a server port.
+ */
+public class ExternalSessionFactory implements SessionFactory {
+
+    public static final String IMAP_SHABANG = "* OK IMAP4rev1 Server ready";
+    protected final InetSocketAddress address;
+    protected final Monitor monitor;
+    protected final String shabang;
+
+    public ExternalSessionFactory(final String host, final int port, final Monitor monitor, final String shabang) {
+        super();
+        this.address = new InetSocketAddress(host, port);
+        this.monitor = monitor;
+        this.shabang = shabang;
+    }
+
+    public Session newSession(Continuation continuation) throws Exception {
+        final SocketChannel channel = SocketChannel.open(address);
+        channel.configureBlocking(false);
+        final ExternalSession result = new ExternalSession(channel, monitor, shabang);
+        return result;
+    }
+
+    public void reset() throws Exception {
+        monitor.note("Please reset system.");
+    }
+
+    /**
+     * Constructs a <code>String</code> with all attributes
+     * in name = value format.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        final String TAB = " ";
+
+        String retValue = "ExternalSessionFactory ( "
+            + "address = " + this.address + TAB
+            + "monitor = " + this.monitor + TAB
+            + "shabang = " + this.shabang + TAB
+            + " )";
+
+        return retValue;
+    }
+}
\ No newline at end of file

Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/InvalidServerResponseException.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/InvalidServerResponseException.java?rev=721281&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/InvalidServerResponseException.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/InvalidServerResponseException.java Thu Nov 27 13:30:36 2008
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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;
+
+/**
+ * An exception which is thrown when the actual response from a server is
+ * different from that expected.
+ */
+public class InvalidServerResponseException extends Exception {
+
+    private static final long serialVersionUID = 6489140960152710438L;
+
+    public InvalidServerResponseException(String message) {
+        super(message);
+    }
+}
\ No newline at end of file

Modified: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSession.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSession.java?rev=721281&r1=721280&r2=721281&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSession.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSession.java Thu Nov 27 13:30:36 2008
@@ -231,6 +231,27 @@
         public boolean isClient() {
             return true;
         }
+
+        /**
+         * Constructs a <code>String</code> with all attributes
+         * in name = value format.
+         *
+         * @return a <code>String</code> representation 
+         * of this object.
+         */
+        public String toString()
+        {
+            final String TAB = " ";
+            
+            String retValue = "ClientRequest ( "
+                + "sessionNumber = " + this.sessionNumber + TAB
+                + "message = " + this.message + TAB
+                + " )";
+        
+            return retValue;
+        }
+        
+        
     }
 
     /**
@@ -355,6 +376,29 @@
         public boolean isClient() {
             return false;
         }
+
+        /**
+         * Constructs a <code>String</code> with all attributes
+         * in name = value format.
+         *
+         * @return a <code>String</code> representation 
+         * of this object.
+         */
+        public String toString()
+        {
+            final String TAB = " ";
+            
+            String result = "ServerResponse ( "
+                + "lastClientMessage = " + this.lastClientMessage + TAB
+                + "sessionNumber = " + this.sessionNumber + TAB
+                + "expectedLine = " + this.expectedLine + TAB
+                + "location = " + this.location + TAB
+                + " )";
+        
+            return result;
+        }
+        
+        
     }
 
     /**
@@ -444,6 +488,26 @@
                 }
             }
         }
+
+        /**
+         * Constructs a <code>String</code> with all attributes
+         * in name = value format.
+         *
+         * @return a <code>String</code> representation 
+         * of this object.
+         */
+        public String toString()
+        {
+            final String TAB = " ";
+            
+            String result = "ServerUnorderedBlockResponse ( "
+                + "expectedLines = " + this.expectedLines + TAB
+                + " )";
+        
+            return result;
+        }
+        
+        
     }
 
     private class ContinuationElement implements ProtocolElement {
@@ -479,6 +543,26 @@
         public boolean isClient() {
             return false;
         }
+
+        /**
+         * Constructs a <code>String</code> with all attributes
+         * in name = value format.
+         *
+         * @return a <code>String</code> representation 
+         * of this object.
+         */
+        public String toString()
+        {
+            final String TAB = " ";
+            
+            String result = "ContinuationElement ( "
+                + "sessionNumber = " + this.sessionNumber + TAB
+                + " )";
+        
+            return result;
+        }
+        
+        
     }
 
     /**
@@ -502,12 +586,29 @@
     }
 
     /**
-     * An exception which is thrown when the actual response from a server is
-     * different from that expected.
+     * Constructs a <code>String</code> with all attributes
+     * in name = value format.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
      */
-    public class InvalidServerResponseException extends Exception {
-        public InvalidServerResponseException(String message) {
-            super(message);
-        }
+    public String toString()
+    {
+        final String TAB = " ";
+        
+        String result  = "ProtocolSession ( "
+            + "continued = " + this.continued + TAB
+            + "continuationExpected = " + this.continuationExpected + TAB
+            + "maxSessionNumber = " + this.maxSessionNumber + TAB
+            + "testElements = " + this.testElements + TAB
+            + "elementsIterator = " + this.elementsIterator + TAB
+            + "sessions = " + this.sessions + TAB
+            + "nextTest = " + this.nextTest + TAB
+            + "continueAfterFailure = " + this.continueAfterFailure + TAB
+            + " )";
+    
+        return result;
     }
+    
+    
 }

Copied: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSessionBuilder.java (from r721269, james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java)
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSessionBuilder.java?p2=james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSessionBuilder.java&p1=james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java&r1=721269&r2=721281&rev=721281&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSessionBuilder.java Thu Nov 27 13:30:36 2008
@@ -29,13 +29,13 @@
 
 
 /**
- * A builder which generates a ProtocolSession from a test file.
+ * A builder which generates scripts from textual input.
  * 
  * @author Darrell DeBoer <da...@apache.org>
  * 
  * @version $Revision$
  */
-public class FileProtocolSessionBuilder {
+public class ProtocolSessionBuilder {
     
     public static final String SERVER_CONTINUATION_TAG = "S: \\+";
 
@@ -53,7 +53,7 @@
 
     private final Properties variables;
     
-    public FileProtocolSessionBuilder() {
+    public ProtocolSessionBuilder() {
         variables = new Properties();
     }
     
@@ -83,6 +83,21 @@
         addTestFile(fileName, session);
         return session;
     }
+    
+    /**
+     * Builds a ProtocolSession by reading lines from the reader.
+     * 
+     * @param fileName
+     *            The name of the protocol session file.
+     * @return The ProtocolSession
+     */
+    public ProtocolInteractor buildProtocolSession(final String scriptName, final Reader reader)
+            throws Exception {
+        ProtocolInteractor session = new ProtocolSession();
+        addProtocolLines(scriptName, reader, session);
+        return session;
+    }
+
 
     /**
      * Adds all protocol elements from a test file to the ProtocolSession

Modified: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java?rev=721281&r1=721280&r2=721281&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java Thu Nov 27 13:30:36 2008
@@ -110,4 +110,25 @@
         }
     }
 
+    /**
+     * Constructs a <code>String</code> with all attributes
+     * in name = value format.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        final String TAB = " ";
+        
+        String result  = "Runner ( "
+            + "preElements = " + this.preElements + TAB
+            + "testElements = " + this.testElements + TAB
+            + "postElements = " + this.postElements + TAB
+            + " )";
+    
+        return result;
+    }
+
+    
 }

Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java?rev=721281&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java Thu Nov 27 13:30:36 2008
@@ -0,0 +1,86 @@
+/****************************************************************
+ * 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;
+
+import java.io.StringReader;
+
+/**
+ * Adds a user by executing a script at a port.
+ * The user name and password supplied will be substituted 
+ * for the variables <code>${user}</code> and <code>${password}</code>.
+ */
+public class ScriptedUserAdder implements UserAdder {
+
+    private static final String SCRIPT_NAME = "Add User Script";
+    private static final String PASSWORD_VARIABLE_NAME = "password";
+    private static final String USER_VARIABLE_NAME = "user";
+    
+    private final String host;
+    private final int port;
+    private final String script;
+    private final Monitor monitor;
+    
+    public ScriptedUserAdder(final String host, final int port, final String script) {
+        this(host, port, script, new NullMonitor());
+    }
+    
+    public ScriptedUserAdder(final String host, final int port, final String script, final Monitor monitor) {
+        this.host = host;
+        this.port = port;
+        this.script = script;
+        this.monitor = monitor;
+    }
+    
+    public void addUser(final String user, final String password) throws Exception {
+        final ProtocolSessionBuilder builder = new ProtocolSessionBuilder();
+        builder.setVariable(USER_VARIABLE_NAME, user);
+        builder.setVariable(PASSWORD_VARIABLE_NAME, password);
+        
+        final Runner runner = new Runner();
+        final StringReader reader = new StringReader(script);
+        builder.addProtocolLines(SCRIPT_NAME, reader, runner.getTestElements());
+        final ExternalSessionFactory factory = new ExternalSessionFactory(host, port, monitor, null);
+        runner.runSessions(factory);
+    }
+
+    /**
+     * Constructs a <code>String</code> with all attributes
+     * in name = value format.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        final String TAB = " ";
+        
+        String result = "ScriptedUserAdder ( "
+            + super.toString() + TAB
+            + "host = " + this.host + TAB
+            + "port = " + this.port + TAB
+            + "script = " + this.script + TAB
+            + "monitor = " + this.monitor + TAB
+            + " )";
+    
+        return result;
+    }
+    
+    
+}

Modified: james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java?rev=721281&r1=721280&r2=721281&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java (original)
+++ james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java Thu Nov 27 13:30:36 2008
@@ -76,7 +76,7 @@
     }
 
     private Session newSession(final String shabang) throws Exception {
-        ExternalHostSystem system = buildSystem(shabang);
+        ExternalSessionFactory system = buildSystem(shabang);
         Session session = system.newSession(continuation);
         return session;
     }

Modified: james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java?rev=721281&r1=721280&r2=721281&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java (original)
+++ james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestFileProtocolSessionBuilder.java Thu Nov 27 13:30:36 2008
@@ -30,7 +30,7 @@
     private static final String SCRIPT_WITH_FOO_REPLACED_BY_WHATEVER = "HELLO ${not} whatever WORLD ${bar}";
     private static final String SCRIPT_WITH_VARIABLES_INLINED = "HELLO not foo WORLD bar";
     
-    FileProtocolSessionBuilder builder;
+    ProtocolSessionBuilder builder;
     ProtocolInteractor session;
 
     private Mock mockSession;
@@ -38,7 +38,7 @@
     //@Override
     protected void setUp() throws Exception {
         super.setUp();
-        builder = new FileProtocolSessionBuilder();
+        builder = new ProtocolSessionBuilder();
         mockSession = mock(ProtocolInteractor.class);
         session = (ProtocolInteractor) mockSession.proxy();
     }
@@ -49,7 +49,7 @@
     }
 
     private void addLines() throws Exception {
-        builder.addProtocolLines("A Script", new StringReader(FileProtocolSessionBuilder.CLIENT_TAG + " " + SCRIPT_WITH_VARIABLES), session);
+        builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + SCRIPT_WITH_VARIABLES), session);
     }
     
     public void testShouldPreserveContentsWhenNoVariablesSet() throws Exception {
@@ -74,13 +74,13 @@
     public void testShouldReplaceVariableAtBeginningAndEnd() throws Exception {
         mockSession.expects(once()).method("CL").with(eq(-1), eq("whatever Some Other Scriptwhateverwhatever"));
         builder.setVariable("foo", "whatever");
-        builder.addProtocolLines("A Script", new StringReader(FileProtocolSessionBuilder.CLIENT_TAG + " " + "${foo} Some Other Script${foo}${foo}"), session);
+        builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + "${foo} Some Other Script${foo}${foo}"), session);
     }
     
     public void testShouldIgnoreNotQuiteVariables() throws Exception {
         final String NEARLY = "{foo}${}${foo Some Other Script${foo}";
         mockSession.expects(once()).method("CL").with(eq(-1), eq(NEARLY));
         builder.setVariable("foo", "whatever");
-        builder.addProtocolLines("A Script", new StringReader(FileProtocolSessionBuilder.CLIENT_TAG + " " + NEARLY), session);
+        builder.addProtocolLines("A Script", new StringReader(ProtocolSessionBuilder.CLIENT_TAG + " " + NEARLY), session);
     }
 }

Added: james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java?rev=721281&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java (added)
+++ james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestScriptedUserAdder.java Thu Nov 27 13:30:36 2008
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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;
+
+import junit.framework.TestCase;
+
+public class TestScriptedUserAdder extends TestCase {
+    
+    private static final int PORT = 10001;
+    
+    private DiscardProtocol protocol;
+    
+    private DiscardProtocol.Record record;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        protocol = new DiscardProtocol(PORT);
+        protocol.start();
+        record = protocol.recordNext();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        protocol.stop();
+    }
+
+    public void testShouldExecuteScriptAgainstPort() throws Exception {
+        ScriptedUserAdder adder = new ScriptedUserAdder("localhost", PORT, "C: USER='${user}' password='${password}'");
+        adder.addUser("A User", "Some Password");
+        assertEquals("USER='A User' password='Some Password'\r\n", record.complete());
+    }
+}



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