Author: rdonkin
Date: Wed Aug  1 02:24:36 2007
New Revision: 561736

URL: http://svn.apache.org/viewvc?view=rev&rev=561736
Log:
Tuned functional test framework.

Added:
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractAuthenticatedStateTestSuite.java
Modified:
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractProtocolTest.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestForAuthenticatedState.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestNonAuthenticatedState.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedInbox.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedState.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/HostSystem.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/SimpleScriptedTestProtocol.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Noop.test
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Welcome.test

Added: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractAuthenticatedStateTestSuite.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractAuthenticatedStateTestSuite.java?view=auto&rev=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractAuthenticatedStateTestSuite.java
 (added)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractAuthenticatedStateTestSuite.java
 Wed Aug  1 02:24:36 2007
@@ -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.test.functional.imap;
+
+
+abstract public class AbstractAuthenticatedStateTestSuite extends 
BaseTestForAuthenticatedState {
+
+    public AbstractAuthenticatedStateTestSuite(HostSystem system) throws 
Exception
+    {
+        super(system);
+    }
+
+    public void testNoop() throws Exception {
+        scriptTest("Noop");
+    }
+}

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractProtocolTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractProtocolTest.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractProtocolTest.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractProtocolTest.java
 Wed Aug  1 02:24:36 2007
@@ -19,9 +19,6 @@
 
 package org.apache.james.test.functional.imap;
 
-import java.io.BufferedReader;
-import java.io.PrintWriter;
-
 import junit.framework.TestCase;
 
 
@@ -54,9 +51,8 @@
 
     private final HostSystem hostSystem;
     
-    public AbstractProtocolTest( String name, HostSystem hostSystem )
+    public AbstractProtocolTest( HostSystem hostSystem )
     {
-        super(name);
         this.hostSystem = hostSystem;
     }
 
@@ -79,53 +75,19 @@
      */
     protected void runSessions() throws Exception
     {
-        HostSystem.Session[] socket = new 
HostSystem.Session[testElements.getSessionCount()];
-        PrintWriter[] out = new PrintWriter[socket.length];
-        BufferedReader[] in = new BufferedReader[socket.length];
-
-        for (int i = 0; i < socket.length; i++) {
-            socket[i] = hostSystem.newSession();
-            out[i] = new PrintWriter(socket[i].getWriter());
-            in[i] = new BufferedReader(socket[i].getReader());
-            socket[i].start();
-        }
-        try
-        {
-            Exception failure = null;
-            try {
-                preElements.runLiveSession( out, in );
-                testElements.runLiveSession( out, in );
-            } catch (ProtocolSession.InvalidServerResponseException e) {
-                failure = e;
-                // Try our best to do cleanup.
-                for (int i = 0; i < in.length; i++) {
-                    BufferedReader reader = in[i];
-                    while (reader.ready()) {
-                        reader.read();
-                    }
-                }
-            } finally {
-                try {
-                    postElements.runLiveSession(out, in);
-                } catch (ProtocolSession.InvalidServerResponseException e) {
-                    // Don't overwrite real error with error on cleanup.
-                    if (failure == null) {
-                        failure = e;
-                    }
-                }
-            }
-
-            if (failure != null) {
-                fail(failure.getMessage());
-            }
+        HostSystem.Session[] sessions = new 
HostSystem.Session[testElements.getSessionCount()];
 
+        for (int i = 0; i < sessions.length; i++) {
+            sessions[i] = hostSystem.newSession();
+            sessions[i].start();
         }
-        finally
-        {
-            for (int i = 0; i < socket.length; i++) {
-                out[i].close();
-                in[i].close();
-                socket[i].stop();
+        try {
+            preElements.runSessions( sessions );
+            testElements.runSessions( sessions );
+            postElements.runSessions(sessions);
+        } finally {
+            for (int i = 0; i < sessions.length; i++) {
+                sessions[i].stop();
             }
         }
     }

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestForAuthenticatedState.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestForAuthenticatedState.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestForAuthenticatedState.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestForAuthenticatedState.java
 Wed Aug  1 02:24:36 2007
@@ -46,7 +46,7 @@
  * <li>Compound:<ul>
  * <li>AppendExpunge</li>
  * <li>SelectAppend</li>
- * <li>StringArgs</li>;
+ * <li>StringArgs</li>
  * </ul></li>
  * </ul>
  * </p>
@@ -54,9 +54,9 @@
 public class BaseTestForAuthenticatedState
         extends SimpleScriptedTestProtocol implements ImapTestConstants
 {
-    public BaseTestForAuthenticatedState( String name, HostSystem hostSystem)
+    public BaseTestForAuthenticatedState( HostSystem hostSystem)
     {
-        super( name, hostSystem );
+        super( hostSystem );
     }
 
     /**
@@ -73,6 +73,6 @@
     protected void addLogin( String username, String password )
     {
         preElements.CL( "a001 LOGIN " + username + " " + password );
-        preElements.SL( "a001 OK LOGIN completed", 
"AbstractTestForAuthenticatedState.java:53" );
+        preElements.SL( "a001 OK LOGIN completed.", 
"AbstractTestForAuthenticatedState.java:53" );
     }
 }

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestNonAuthenticatedState.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestNonAuthenticatedState.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestNonAuthenticatedState.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestNonAuthenticatedState.java
 Wed Aug  1 02:24:36 2007
@@ -39,9 +39,9 @@
 public class BaseTestNonAuthenticatedState
         extends SimpleScriptedTestProtocol
 {
-    public BaseTestNonAuthenticatedState( String name, HostSystem system )
+    public BaseTestNonAuthenticatedState( HostSystem system )
     {
-        super( name, system );
+        super( system );
     }
 
     /**

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedInbox.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedInbox.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedInbox.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedInbox.java
 Wed Aug  1 02:24:36 2007
@@ -52,9 +52,9 @@
 public class BaseTestSelectedInbox
         extends BaseTestForAuthenticatedState
 {
-    public BaseTestSelectedInbox( String name, HostSystem system )
+    public BaseTestSelectedInbox( HostSystem system )
     {
-        super( name, system );
+        super( system );
     }
 
     /**

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedState.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedState.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedState.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/BaseTestSelectedState.java
 Wed Aug  1 02:24:36 2007
@@ -42,9 +42,9 @@
 public class BaseTestSelectedState
         extends BaseTestForAuthenticatedState
 {
-    public BaseTestSelectedState( String name, HostSystem system )
+    public BaseTestSelectedState( HostSystem system )
     {
-        super( name, system );
+        super( system );
     }
 
     /**

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/HostSystem.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/HostSystem.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/HostSystem.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/HostSystem.java
 Wed Aug  1 02:24:36 2007
@@ -41,7 +41,7 @@
      * @param password user password
      * @throws Exception
      */
-    public void addUser(String user, String password) throws Exception;
+    public boolean addUser(String user, String password) throws Exception;
     
     /**
      * Creates a new session for functional testing.
@@ -52,8 +52,8 @@
     
     public interface Session
     {
-        public Reader getReader() throws Exception;
-        public Writer getWriter() throws Exception;
+        public String readLine() throws Exception;
+        public void writeLine(String line) throws Exception;
         public void start() throws Exception;
         public void stop() throws Exception;
     }

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java
 Wed Aug  1 02:24:36 2007
@@ -20,9 +20,7 @@
 
 package org.apache.james.test.functional.imap;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -60,12 +58,12 @@
      * @param out The client requests are written to here.
      * @param in The server responses are read from here.
      */
-    public void runLiveSession(PrintWriter[] out, BufferedReader[] in) throws 
InvalidServerResponseException {
+    public void runSessions(HostSystem.Session[] sessions) throws Exception {
         for ( Iterator iter = testElements.iterator(); iter.hasNext(); ) {
             Object obj = iter.next();
             if ( obj instanceof ProtocolElement ) {
                 ProtocolElement test = ( ProtocolElement ) obj;
-                test.testProtocol( out, in );
+                test.testProtocol( sessions );
             }
         }
     }
@@ -151,26 +149,24 @@
          * Writes the request message to the PrintWriters. If the 
sessionNumber == -1,
          * the request is written to *all* supplied writers, otherwise, only 
the
          * writer for this session is writted to.
+         * @throws Exception 
          */
-        public void testProtocol( PrintWriter[] out, BufferedReader[] in )
+        public void testProtocol( HostSystem.Session[] sessions ) throws 
Exception
         {
             if (sessionNumber < 0) {
-                for (int i = 0; i < out.length; i++) {
-                    PrintWriter printWriter = out[i];
-                    writeMessage(printWriter);
+                for (int i = 0; i < sessions.length; i++) {
+                    HostSystem.Session session = sessions[i];
+                    writeMessage(session);
                 }
             }
             else {
-                PrintWriter writer = out[sessionNumber];
-                writeMessage(writer);
+                HostSystem.Session session = sessions[sessionNumber];
+                writeMessage(session);
             }
         }
 
-        private void writeMessage(PrintWriter writer) {
-            writer.write(message);
-            writer.write('\r');
-            writer.write('\n');
-            writer.flush();
+        private void writeMessage(HostSystem.Session session) throws Exception 
{
+            session.writeLine(message);
         }
     }
 
@@ -219,23 +215,23 @@
          * @throws InvalidServerResponseException If the actual server 
response didn't
          *          match the regular expression expected.
          */
-        public void testProtocol( PrintWriter[] out, BufferedReader[] in )
-                throws InvalidServerResponseException
+        public void testProtocol( HostSystem.Session[] sessions)
+                throws Exception
         {
             if (sessionNumber < 0) {
-                for (int i = 0; i < in.length; i++) {
-                    BufferedReader reader = in[i];
-                    checkResponse(reader);
+                for (int i = 0; i < sessions.length; i++) {
+                    HostSystem.Session session = sessions[i];
+                    checkResponse(session);
                 }
             }
             else {
-                BufferedReader reader = in[sessionNumber];
-                checkResponse(reader);
+                HostSystem.Session session = sessions[sessionNumber];
+                checkResponse(session);
             }
         }
 
-        protected void checkResponse(BufferedReader reader) throws 
InvalidServerResponseException {
-            String testLine = readLine(reader);
+        protected void checkResponse(HostSystem.Session session) throws 
Exception {
+            String testLine = readLine(session);
             if ( ! match( expectedLine, testLine ) ) {
                 String errMsg = "\nLocation: " + location +
                         "\nExcpected: " + expectedLine +
@@ -260,14 +256,13 @@
         /**
          * Grabs a line from the server and throws an error message if it
          * doesn't work out
-         * @param in BufferedReader for getting the server response
          * @return String of the line from the server
          */
-        protected String readLine( BufferedReader in )
-                throws InvalidServerResponseException
+        protected String readLine( HostSystem.Session session )
+                throws Exception
         {
             try {
-                return in.readLine();
+                return session.readLine();
             } catch (IOException e) {
                 String errMsg = "\nLocation: " + location +
                                 "\nExpected: " + expectedLine +
@@ -319,10 +314,10 @@
          * @throws InvalidServerResponseException If a line is encountered 
which doesn't
          *              match one of the expected lines.
          */
-        protected void checkResponse(BufferedReader reader) throws 
InvalidServerResponseException {
+        protected void checkResponse(HostSystem.Session session) throws 
Exception {
             List testLines = new ArrayList(expectedLines);
             while (testLines.size() > 0) {
-                String actualLine = readLine(reader);
+                String actualLine = readLine(session);
 
                 boolean foundMatch = false;
                 for (int i = 0; i < testLines.size(); i++) {
@@ -361,14 +356,10 @@
     private interface ProtocolElement
     {
         /**
-         * Executes the ProtocolElement against the supplied read and writer.
-         * @param out Client requests are written to here.
-         * @param in Server responses are read from here.
-         * @throws InvalidServerResponseException If the actual server response
-         *              doesn't match the one expected.
+         * Executes the ProtocolElement against the supplied session.
+         * @throws Exception 
          */
-        void testProtocol( PrintWriter[] out, BufferedReader[] in )
-                throws InvalidServerResponseException;
+        void testProtocol( HostSystem.Session[] sessions) throws Exception;
     }
 
     /**

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/SimpleScriptedTestProtocol.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/SimpleScriptedTestProtocol.java?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/SimpleScriptedTestProtocol.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/SimpleScriptedTestProtocol.java
 Wed Aug  1 02:24:36 2007
@@ -41,20 +41,18 @@
      * in the same location as this test class.
      * @param fileName The name of the file to read protocol elements from.
      */
-    public SimpleScriptedTestProtocol( String fileName, HostSystem hostSystem  
)
+    public SimpleScriptedTestProtocol( HostSystem hostSystem  )
     {
-        super( fileName, hostSystem );
+        super( hostSystem );
     }
 
     /**
      * Reads test elements from the protocol session file and adds them to the
      * [EMAIL PROTECTED] #testElements} ProtocolSession. Then calls [EMAIL 
PROTECTED] #runSessions}.
      */
-    protected void runTest() throws Throwable
+    protected void scriptTest(String fileName) throws Exception
     {
-        String fileName = getName() + ".test";
-        addTestFile( fileName, testElements );
-
+        addTestFile( fileName + ".test", testElements );
         runSessions();
     }
 
@@ -67,6 +65,7 @@
      */ 
     protected void addTestFile( String fileName, ProtocolSession session) 
throws Exception
     {
+        fileName = "/org/apache/james/test/functional/imap/scripts/" + 
fileName;
         // Need to find local resource.
         InputStream is = this.getClass().getResourceAsStream( fileName );
         if ( is == null ) {

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Noop.test
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Noop.test?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Noop.test
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Noop.test
 Wed Aug  1 02:24:36 2007
@@ -18,4 +18,4 @@
 ################################################################
 # TODO make sure we get unsolicited responses on NOOP
 C: a01 NOOP
-S: a01 OK NOOP completed
\ No newline at end of file
+S: a01 OK NOOP completed.
\ No newline at end of file

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Welcome.test
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Welcome.test?view=diff&rev=561736&r1=561735&r2=561736
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Welcome.test
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/Welcome.test
 Wed Aug  1 02:24:36 2007
@@ -16,4 +16,4 @@
 # specific language governing permissions and limitations      #
 # under the License.                                           #
 ################################################################
-S: \* OK IMAP4rev1 Server .* ready
+S: \* OK IMAP4rev1 Server ready
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to