james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1455012 - in /james/mpt/trunk: core/src/main/java/org/apache/james/mpt/ impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/
Date Mon, 11 Mar 2013 06:40:29 GMT
Author: eric
Date: Mon Mar 11 06:40:28 2013
New Revision: 1455012

URL: http://svn.apache.org/r1455012
Log:
Merge ProtocolSession (MPT-4)

Removed:
    james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/AbstractProtocolTestFramework.java
    james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/ProtocolSession.java
Modified:
    james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java
    james/mpt/trunk/core/src/main/java/org/apache/james/mpt/ProtocolSession.java
    james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/AbstractSimpleScriptedTestProtocol.java
    james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java

Modified: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java?rev=1455012&r1=1455011&r2=1455012&view=diff
==============================================================================
--- james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java
(original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java
Mon Mar 11 06:40:28 2013
@@ -22,20 +22,29 @@ package org.apache.james.mpt;
 import junit.framework.TestCase;
 
 /**
- * Abstract Protocol Test is the root of all of the scripted test
- * cases. It provides basic functionality for running a protocol session as a
- * JUnit test, and failing if exceptions are thrown. To create a test which
- * reads the entire protocol session from a single protocol definition file, use
- * the {@link AbstractSimpleScriptedTestProtocol}.
+ * Abstract Protocol Test is the root of all of the scripted test cases. It
+ * provides basic functionality for running a protocol session as a JUnit test,
+ * and failing if exceptions are thrown. To create a test which reads the entire
+ * protocol session from a single protocol definition file, use the
+ * {@link AbstractSimpleScriptedTestProtocol}.
  * 
  * @author Darrell DeBoer
  * @author Andrew C. Oliver
  */
 public abstract class AbstractProtocolTestFramework extends TestCase {
 
+    /** The Protocol session which is run before the testElements */
+    protected ProtocolSession preElements = new ProtocolSession();
+
+    /** The Protocol session which contains the tests elements */
+    protected ProtocolSession testElements = new ProtocolSession();
+
+    /** The Protocol session which is run after the testElements. */
+    protected ProtocolSession postElements = new ProtocolSession();
+
     protected final Runner runner;
     private final HostSystem hostSystem;
-    
+
     private final String userName;
     private final String password;
 
@@ -51,27 +60,56 @@ public abstract class AbstractProtocolTe
         setUpEnvironment();
     }
 
-    protected void continueAfterFailure() {
-        runner.continueAfterFailure();
-    }
-
     /**
-     * <p>Runs the pre,test and post protocol sessions against a local copy of the
+     * <p>
+     * Runs the pre,test and post protocol sessions against a local copy of the
      * Server. This is useful for rapid development and debugging.
      * </p>
      * Instead of sending requests to a socket connected to a running instance
-     * of James, this method uses the {@link HostSystem} to simplify
-     * testing. One mock instance is required per protocol session/connection.
+     * of James, this method uses the {@link HostSystem} to simplify testing.
+     * One mock instance is required per protocol session/connection.
      */
     protected void runSessions() throws Exception {
-        runner.runSessions(hostSystem);
+        class SessionContinuation implements Continuation {
+
+            public ProtocolSession session;
+
+            public void doContinue() {
+                if (session != null) {
+                    session.doContinue();
+                }
+            }
+
+        }
+        SessionContinuation continuation = new SessionContinuation();
+
+        Session[] sessions = new Session[testElements.getSessionCount()];
+
+        for (int i = 0; i < sessions.length; i++) {
+            sessions[i] = hostSystem.newSession(continuation);
+            sessions[i].start();
+        }
+        try {
+            continuation.session = preElements;
+            preElements.runSessions(sessions);
+            continuation.session = testElements;
+            testElements.runSessions(sessions);
+            continuation.session = postElements;
+            postElements.runSessions(sessions);
+        }
+        finally {
+            for (int i = 0; i < sessions.length; i++) {
+                sessions[i].stop();
+            }
+        }
     }
 
     /**
      * Initialises the host on first call.
      */
-    private void setUpEnvironment() throws Exception {
+    public void setUpEnvironment() throws Exception {
         hostSystem.reset();
         hostSystem.addUser(userName, password);
     }
+
 }

Modified: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/ProtocolSession.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/core/src/main/java/org/apache/james/mpt/ProtocolSession.java?rev=1455012&r1=1455011&r2=1455012&view=diff
==============================================================================
--- james/mpt/trunk/core/src/main/java/org/apache/james/mpt/ProtocolSession.java (original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/ProtocolSession.java Mon Mar 11
06:40:28 2013
@@ -25,7 +25,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Pattern;
 
-
 /**
  * A protocol session which can be run against a reader and writer, which checks
  * the server response against the expected values. TODO make ProtocolSession
@@ -33,8 +32,6 @@ import java.util.regex.Pattern;
  * sessions.
  * 
  * @author Darrell DeBoer <darrell@apache.org>
- * 
- * @version $Revision$
  */
 public class ProtocolSession implements ProtocolInteractor {
     private boolean continued = false;
@@ -45,7 +42,7 @@ public class ProtocolSession implements 
 
     protected List<ProtocolElement> testElements = new ArrayList<ProtocolElement>();
 
-    private Iterator elementsIterator;
+    private Iterator<ProtocolElement> elementsIterator;
 
     private Session[] sessions;
 
@@ -77,7 +74,10 @@ public class ProtocolSession implements 
      * in the array corresponds to the number of the session. If an exception
      * occurs, no more test elements are executed.
      * 
-     * @param sessions not null
+     * @param out
+     *            The client requests are written to here.
+     * @param in
+     *            The server responses are read from here.
      */
     public void runSessions(Session[] sessions) throws Exception {
         this.sessions = sessions;
@@ -109,38 +109,40 @@ public class ProtocolSession implements 
                 if (!elementsIterator.hasNext()) {
                     nextTest = null;
                 }
-            } else {
+            }
+            else {
                 throw new RuntimeException("Unexpected continuation");
             }
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#CL(java.lang.String)
+     * adds a new Client request line to the test elements
      */
     public void CL(String clientLine) {
         testElements.add(new ClientRequest(clientLine));
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#SL(java.lang.String, java.lang.String)
+     * adds a new Server Response line to the test elements, with the specified
+     * location.
      */
     public void SL(String serverLine, String location) {
         testElements.add(new ServerResponse(serverLine, location));
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#SUB(java.util.List, java.lang.String)
+     * adds a new Server Unordered Block to the test elements.
      */
     public void SUB(List<String> serverLines, String location) {
-        testElements
-                .add(new ServerUnorderedBlockResponse(serverLines, location));
+        testElements.add(new ServerUnorderedBlockResponse(serverLines, location));
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#CL(int, java.lang.String)
+     * adds a new Client request line to the test elements
      */
     public void CL(int sessionNumber, String clientLine) {
         this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
@@ -148,7 +150,7 @@ public class ProtocolSession implements 
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#CONT(int)
+     * Adds a continuation. To allow one thread to be used for testing.
      */
     public void CONT(int sessionNumber) throws Exception {
         this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
@@ -156,29 +158,26 @@ public class ProtocolSession implements 
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#SL(int, java.lang.String, java.lang.String,
java.lang.String)
+     * adds a new Server Response line to the test elements, with the specified
+     * location.
      */
-    public void SL(int sessionNumber, String serverLine, String location,
-            String lastClientMessage) {
+    public void SL(int sessionNumber, String serverLine, String location, String lastClientMessage)
{
         this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
-        testElements.add(new ServerResponse(sessionNumber, serverLine,
-                location, lastClientMessage));
+        testElements.add(new ServerResponse(sessionNumber, serverLine, location, lastClientMessage));
     }
 
     /**
-     * @see org.apache.james.mpt.ProtocolInteractor#SUB(int, java.util.List, java.lang.String,
java.lang.String)
+     * adds a new Server Unordered Block to the test elements.
      */
-    public void SUB(int sessionNumber, List<String> serverLines, String location,
-            String lastClientMessage) {
+    public void SUB(int sessionNumber, List<String> serverLines, String location, String
lastClientMessage) {
         this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
-        testElements.add(new ServerUnorderedBlockResponse(sessionNumber,
-                serverLines, location, lastClientMessage));
+        testElements.add(new ServerUnorderedBlockResponse(sessionNumber, serverLines, location,
lastClientMessage));
     }
 
     /**
      * A client request, which write the specified message to a Writer.
      */
-    private class ClientRequest implements ProtocolElement {
+    private static class ClientRequest implements ProtocolElement {
         private int sessionNumber;
 
         private String message;
@@ -202,20 +201,20 @@ public class ProtocolSession implements 
         }
 
         /**
-         * 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.
+         * 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(Session[] sessions,
-                boolean continueAfterFailure) throws Exception {
+        public void testProtocol(Session[] sessions, boolean continueAfterFailure) throws
Exception {
             if (sessionNumber < 0) {
                 for (int i = 0; i < sessions.length; i++) {
                     Session session = sessions[i];
                     writeMessage(session);
                 }
-            } else {
+            }
+            else {
                 Session session = sessions[sessionNumber];
                 writeMessage(session);
             }
@@ -228,27 +227,6 @@ public class ProtocolSession implements 
         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;
-        }
-        
-        
     }
 
     /**
@@ -289,8 +267,7 @@ public class ProtocolSession implements 
          * @param location
          *            A descriptive value to use in error messages.
          */
-        public ServerResponse(int sessionNumber, String expectedPattern,
-                String location, String lastClientMessage) {
+        public ServerResponse(int sessionNumber, String expectedPattern, String location,
String lastClientMessage) {
             this.sessionNumber = sessionNumber;
             this.expectedLine = expectedPattern;
             this.location = location;
@@ -311,29 +288,28 @@ public class ProtocolSession implements 
          *             If the actual server response didn't match the regular
          *             expression expected.
          */
-        public void testProtocol(Session[] sessions,
-                boolean continueAfterFailure) throws Exception {
+        public void testProtocol(Session[] sessions, boolean continueAfterFailure) throws
Exception {
             if (sessionNumber < 0) {
                 for (int i = 0; i < sessions.length; i++) {
                     Session session = sessions[i];
                     checkResponse(session, continueAfterFailure);
                 }
-            } else {
+            }
+            else {
                 Session session = sessions[sessionNumber];
                 checkResponse(session, continueAfterFailure);
             }
         }
 
-        protected void checkResponse(Session session,
-                boolean continueAfterFailure) throws Exception {
+        protected void checkResponse(Session session, boolean continueAfterFailure) throws
Exception {
             String testLine = readLine(session);
             if (!match(expectedLine, testLine)) {
-                String errMsg = "\nLocation: " + location + "\nLastClientMsg: "
-                        + lastClientMessage + "\nExpected: '" + expectedLine
-                        + "'\nActual   : '" + testLine + "'";
+                String errMsg = "\nLocation: " + location + "\nLastClientMsg: " + lastClientMessage
+ "\nExpected: '"
+                        + expectedLine + "'\nActual   : '" + testLine + "'";
                 if (continueAfterFailure) {
                     System.out.println(errMsg);
-                } else {
+                }
+                else {
                     throw new InvalidServerResponseException(errMsg);
                 }
             }
@@ -363,9 +339,9 @@ public class ProtocolSession implements 
         protected String readLine(Session session) throws Exception {
             try {
                 return session.readLine();
-            } catch (IOException e) {
-                String errMsg = "\nLocation: " + location + "\nExpected: "
-                        + expectedLine + "\nReason: Server Timeout.";
+            }
+            catch (IOException e) {
+                String errMsg = "\nLocation: " + location + "\nExpected: " + expectedLine
+ "\nReason: Server Timeout.";
                 throw new InvalidServerResponseException(errMsg);
             }
         }
@@ -373,29 +349,6 @@ public class ProtocolSession implements 
         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;
-        }
-        
-        
     }
 
     /**
@@ -432,10 +385,9 @@ public class ProtocolSession implements 
          * @param location
          *            A descriptive location string for error messages.
          */
-        public ServerUnorderedBlockResponse(int sessionNumber,
-                List<String> expectedLines, String location, String lastClientMessage)
{
-            super(sessionNumber, "<Unordered Block>", location,
-                    lastClientMessage);
+        public ServerUnorderedBlockResponse(int sessionNumber, List<String> expectedLines,
String location,
+                String lastClientMessage) {
+            super(sessionNumber, "<Unordered Block>", location, lastClientMessage);
             this.expectedLines = expectedLines;
         }
 
@@ -450,8 +402,7 @@ public class ProtocolSession implements 
          *             If a line is encountered which doesn't match one of the
          *             expected lines.
          */
-        protected void checkResponse(Session session,
-                boolean continueAfterFailure) throws Exception {
+        protected void checkResponse(Session session, boolean continueAfterFailure) throws
Exception {
             List<String> testLines = new ArrayList<String>(expectedLines);
             while (testLines.size() > 0) {
                 String actualLine = readLine(session);
@@ -467,10 +418,9 @@ public class ProtocolSession implements 
                 }
 
                 if (!foundMatch) {
-                    StringBuffer errMsg = new StringBuffer().append(
-                            "\nLocation: ").append(location).append(
-                            "\nExpected one of: ");
-                    Iterator iter = expectedLines.iterator();
+                    StringBuffer errMsg = new StringBuffer().append("\nLocation: ").append(location)
+                            .append("\nExpected one of: ");
+                    Iterator<String> iter = expectedLines.iterator();
                     while (iter.hasNext()) {
                         errMsg.append("\n    ");
                         errMsg.append(iter.next());
@@ -478,33 +428,13 @@ public class ProtocolSession implements 
                     errMsg.append("\nActual: ").append(actualLine);
                     if (continueAfterFailure) {
                         System.out.println(errMsg.toString());
-                    } else {
-                        throw new InvalidServerResponseException(errMsg
-                                .toString());
+                    }
+                    else {
+                        throw new InvalidServerResponseException(errMsg.toString());
                     }
                 }
             }
         }
-
-        /**
-         * 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 {
@@ -515,8 +445,7 @@ public class ProtocolSession implements 
             this.sessionNumber = sessionNumber < 0 ? 0 : sessionNumber;
         }
 
-        public void testProtocol(Session[] sessions,
-                boolean continueAfterFailure) throws Exception {
+        public void testProtocol(Session[] sessions, boolean continueAfterFailure) throws
Exception {
             Session session = sessions[sessionNumber];
             continuationExpected = true;
             continued = false;
@@ -525,7 +454,8 @@ public class ProtocolSession implements 
                 final String message = "Expected continuation";
                 if (continueAfterFailure) {
                     System.out.print(message);
-                } else {
+                }
+                else {
                     throw new InvalidServerResponseException(message);
                 }
             }
@@ -540,26 +470,6 @@ public class ProtocolSession implements 
         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;
-        }
-        
-        
     }
 
     /**
@@ -572,40 +482,42 @@ public class ProtocolSession implements 
         /**
          * Executes the ProtocolElement against the supplied session.
          * 
-         * @param continueAfterFailure true when the execution should continue,
-         * false otherwise
+         * @param continueAfterFailure
+         *            TODO
          * @throws Exception
          */
-        void testProtocol(Session[] sessions,
-                boolean continueAfterFailure) throws Exception;
+        void testProtocol(Session[] sessions, boolean continueAfterFailure) throws Exception;
 
         boolean isClient();
     }
 
     /**
-     * Constructs a <code>String</code> with all attributes
-     * in name = value format.
-     *
-     * @return a <code>String</code> representation 
-     * of this object.
+     * An exception which is thrown when the actual response from a server is
+     * different from that expected.
      */
-    public String toString()
-    {
+    @SuppressWarnings("serial")
+    public static class InvalidServerResponseException extends Exception {
+        public InvalidServerResponseException(String message) {
+            super(message);
+        }
+    }
+
+    /**
+     * 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  = "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
-            + " )";
-    
+
+        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;
     }
-    
-    
+
 }

Modified: james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/AbstractSimpleScriptedTestProtocol.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/AbstractSimpleScriptedTestProtocol.java?rev=1455012&r1=1455011&r2=1455012&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/AbstractSimpleScriptedTestProtocol.java
(original)
+++ james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/AbstractSimpleScriptedTestProtocol.java
Mon Mar 11 06:40:28 2013
@@ -23,10 +23,11 @@ import java.io.InputStream;
 import java.util.Locale;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mpt.AbstractProtocolTestFramework;
 import org.apache.james.mpt.HostSystem;
+import org.apache.james.mpt.ProtocolSession;
 import org.junit.After;
 
-
 /**
  * A Protocol test which reads the test protocol session from a file. The file
  * read is taken as "<test-name>.test", where <test-name> is the value passed
@@ -34,8 +35,7 @@ import org.junit.After;
  * and {@link #postElements} for extra elements not defined in the protocol
  * session file.
  */
-public abstract class AbstractSimpleScriptedTestProtocol extends
-        AbstractProtocolTestFramework {
+public abstract class AbstractSimpleScriptedTestProtocol extends AbstractProtocolTestFramework
{
     private FileProtocolSessionBuilder builder = new FileProtocolSessionBuilder();
 
     private static final Locale BASE_DEFAULT_LOCALE = Locale.getDefault();
@@ -46,12 +46,15 @@ public abstract class AbstractSimpleScri
      * Sets up a SimpleFileProtocolTest which reads the protocol session from a
      * file of name "<fileName>.test". This file should be available in the
      * classloader in the same location as this test class.
-     * @param scriptDirectory name of the directory containing the scripts to be run
+     * 
+     * @param scriptDirectory
+     *            name of the directory containing the scripts to be run
      * @param fileName
      *            The name of the file to read protocol elements from.
-     * @throws Exception 
+     * @throws Exception
      */
-    public AbstractSimpleScriptedTestProtocol(HostSystem hostSystem, String userName, String
password, String scriptDirectory) throws Exception {
+    public AbstractSimpleScriptedTestProtocol(HostSystem hostSystem, String userName, String
password,
+            String scriptDirectory) throws Exception {
         super(hostSystem, userName, password);
         this.scriptDirectory = scriptDirectory;
     }
@@ -96,7 +99,8 @@ public abstract class AbstractSimpleScri
 
         try {
             builder.addProtocolLinesFromStream(is, session, fileName);
-        } finally {
+        }
+        finally {
             IOUtils.closeQuietly(is);
         }
     }

Modified: james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java?rev=1455012&r1=1455011&r2=1455012&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java
(original)
+++ james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java
Mon Mar 11 06:40:28 2013
@@ -26,7 +26,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.io.IOUtils;
-
+import org.apache.james.mpt.ProtocolSession;
 
 /**
  * A builder which generates a ProtocolSession from a test file.
@@ -58,8 +58,7 @@ public class FileProtocolSessionBuilder 
      *            The name of the protocol session file.
      * @return The ProtocolSession
      */
-    public ProtocolSession buildProtocolSession(String fileName)
-            throws Exception {
+    public ProtocolSession buildProtocolSession(String fileName) throws Exception {
         ProtocolSession session = new ProtocolSession();
         addTestFile(fileName, session);
         return session;
@@ -74,8 +73,7 @@ public class FileProtocolSessionBuilder 
      * @param session
      *            The ProtocolSession to add the elements to.
      */
-    public void addTestFile(String fileName, ProtocolSession session)
-            throws Exception {
+    public void addTestFile(String fileName, ProtocolSession session) throws Exception {
         // Need to find local resource.
         InputStream is = this.getClass().getResourceAsStream(fileName);
         if (is == null) {
@@ -84,7 +82,8 @@ public class FileProtocolSessionBuilder 
 
         try {
             addProtocolLinesFromStream(is, session, fileName);
-        } finally {
+        }
+        finally {
             IOUtils.closeQuietly(is);
         }
     }
@@ -100,8 +99,7 @@ public class FileProtocolSessionBuilder 
      * @param fileName
      *            The name of the source file, for error messages.
      */
-    public void addProtocolLinesFromStream(InputStream is,
-            ProtocolSession session, String fileName) throws Exception {
+    public void addProtocolLinesFromStream(InputStream is, ProtocolSession session, String
fileName) throws Exception {
         int sessionNumber = -1;
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         try {
@@ -112,31 +110,33 @@ public class FileProtocolSessionBuilder 
                 String location = fileName + ":" + lineNumber;
                 if (SERVER_CONTINUATION_TAG.equals(next)) {
                     session.CONT(sessionNumber);
-                } else if (next.startsWith(CLIENT_TAG)) {
+                }
+                else if (next.startsWith(CLIENT_TAG)) {
                     String clientMsg = "";
                     if (next.length() > 3) {
                         clientMsg = next.substring(3);
                     }
                     session.CL(sessionNumber, clientMsg);
                     lastClientMsg = clientMsg;
-                } else if (next.startsWith(SERVER_TAG)) {
+                }
+                else if (next.startsWith(SERVER_TAG)) {
                     String serverMsg = "";
                     if (next.length() > 3) {
                         serverMsg = next.substring(3);
                     }
                     session.SL(sessionNumber, serverMsg, location, lastClientMsg);
-                } else if (next.startsWith(OPEN_UNORDERED_BLOCK_TAG)) {
+                }
+                else if (next.startsWith(OPEN_UNORDERED_BLOCK_TAG)) {
                     List<String> unorderedLines = new ArrayList<String>(5);
                     next = reader.readLine();
-    
+
                     if (next == null)
                         throw new Exception("Readline doesn't contain any data, but must
not be 'null' (linenumber="
                                 + lineNumber);
 
                     while (!next.startsWith(CLOSE_UNORDERED_BLOCK_TAG)) {
                         if (!next.startsWith(SERVER_TAG)) {
-                            throw new Exception(
-                                    "Only 'S: ' lines are permitted inside a 'SUB {' block.");
+                            throw new Exception("Only 'S: ' lines are permitted inside a
'SUB {' block.");
                         }
                         String serverMsg = next.substring(3);
                         unorderedLines.add(serverMsg);
@@ -144,23 +144,25 @@ public class FileProtocolSessionBuilder 
                         lineNumber++;
 
                         if (next == null)
-                            throw new Exception("Readline doesn't contain any data, but must
not be 'null' (linenumber="
-                                    + lineNumber);
+                            throw new Exception(
+                                    "Readline doesn't contain any data, but must not be 'null'
(linenumber="
+                                            + lineNumber);
 
                     }
-    
-                    session.SUB(sessionNumber, unorderedLines, location,
-                            lastClientMsg);
-                } else if (next.startsWith(COMMENT_TAG)
-                        || next.trim().length() == 0) {
+
+                    session.SUB(sessionNumber, unorderedLines, location, lastClientMsg);
+                }
+                else if (next.startsWith(COMMENT_TAG) || next.trim().length() == 0) {
                     // ignore these lines.
-                } else if (next.startsWith(SESSION_TAG)) {
+                }
+                else if (next.startsWith(SESSION_TAG)) {
                     String number = next.substring(SESSION_TAG.length()).trim();
                     if (number.length() == 0) {
                         throw new Exception("No session number specified");
                     }
                     sessionNumber = Integer.parseInt(number);
-                } else {
+                }
+                else {
                     String prefix = next;
                     if (next.length() > 3) {
                         prefix = next.substring(0, 3);
@@ -169,7 +171,8 @@ public class FileProtocolSessionBuilder 
                 }
                 lineNumber++;
             }
-        } finally {
+        }
+        finally {
             IOUtils.closeQuietly(reader);
         }
     }



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