james-server-dev mailing list archives

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

URL: http://svn.apache.org/r1455014
Log:
Merge AbstractSimpleScriptedTestProtocol (MPT-4)

Added:
    james/mpt/trunk/core/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java
      - copied, changed from r1455012, james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java
Removed:
    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/AbstractSimpleScriptedTestProtocol.java
    james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/ImapProtocolFramework.java

Modified: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java?rev=1455014&r1=1455013&r2=1455014&view=diff
==============================================================================
--- james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java
(original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/AbstractSimpleScriptedTestProtocol.java
Mon Mar 11 06:43:24 2013
@@ -22,44 +22,56 @@ package org.apache.james.mpt;
 import java.io.InputStream;
 import java.util.Locale;
 
+import org.apache.commons.io.IOUtils;
+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
- * into the constructor. Subclasses of this test can set up pre-
- * and post elements for extra elements not defined in the protocol
+ * into the constructor. Subclasses of this test can set up {@link #preElements}
+ * and {@link #postElements} for extra elements not defined in the protocol
  * session file.
  */
-public abstract class AbstractSimpleScriptedTestProtocol extends
-        AbstractProtocolTestFramework {
-    private ProtocolSessionBuilder builder = new ProtocolSessionBuilder();
+public abstract class AbstractSimpleScriptedTestProtocol extends AbstractProtocolTestFramework
{
+    private FileProtocolSessionBuilder builder = new FileProtocolSessionBuilder();
 
     private static final Locale BASE_DEFAULT_LOCALE = Locale.getDefault();
-    
+
+    private final String scriptDirectory;
+
     /**
-     * Constructs a scripted test.
-     * @param hostSystem not null
-     * @param userName user name
-     * @param password password for user
+     * 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 fileName
+     *            The name of the file to read protocol elements from.
+     * @throws Exception
      */
-    public AbstractSimpleScriptedTestProtocol(HostSystem hostSystem, String userName, String
password) {
+    public AbstractSimpleScriptedTestProtocol(HostSystem hostSystem, String userName, String
password,
+            String scriptDirectory) throws Exception {
         super(hostSystem, userName, password);
+        this.scriptDirectory = scriptDirectory;
     }
-    
-    protected void tearDown() throws Exception {
-        Locale.setDefault(BASE_DEFAULT_LOCALE);
+
+    @After
+    public void tearDown() throws Exception {
         super.tearDown();
+        Locale.setDefault(BASE_DEFAULT_LOCALE);
     }
 
     /**
      * Reads test elements from the protocol session file and adds them to the
-     * ProtocolSession. Then calls {@link #runSessions()}.
+     * {@link #testElements} ProtocolSession. Then calls {@link #runSessions}.
      * 
-     * @param locale test under this default locale, not null
+     * @param locale
+     *            execute the test using this locale
      */
     protected void scriptTest(String fileName, Locale locale) throws Exception {
         Locale.setDefault(locale);
-        addTestFile(fileName + ".test", runner.getTestElements());
+        addTestFile(fileName + ".test", testElements);
         runSessions();
     }
 
@@ -73,14 +85,21 @@ public abstract class AbstractSimpleScri
      * @param session
      *            The ProtocolSession to add elements to.
      */
-    protected void addTestFile(String fileName, ProtocolInteractor session)
-            throws Exception {
+    protected void addTestFile(String fileName, ProtocolSession session) throws Exception
{
+        fileName = scriptDirectory + fileName;
         // Need to find local resource.
         InputStream is = this.getClass().getResourceAsStream(fileName);
+
         if (is == null) {
             throw new Exception("Test Resource '" + fileName + "' not found.");
         }
 
-        builder.addProtocolLines(fileName, is, session);
+        try {
+            builder.addProtocolLinesFromStream(is, session, fileName);
+        }
+        finally {
+            IOUtils.closeQuietly(is);
+        }
     }
+
 }

Copied: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java
(from r1455012, 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/core/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java?p2=james/mpt/trunk/core/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java&p1=james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java&r1=1455012&r2=1455014&rev=1455014&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/base/FileProtocolSessionBuilder.java
(original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/FileProtocolSessionBuilder.java
Mon Mar 11 06:43:24 2013
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mpt.imapmailbox.base;
+package org.apache.james.mpt;
 
 import java.io.BufferedReader;
 import java.io.InputStream;
@@ -26,7 +26,6 @@ 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.

Modified: james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/ImapProtocolFramework.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/ImapProtocolFramework.java?rev=1455014&r1=1455013&r2=1455014&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/ImapProtocolFramework.java
(original)
+++ james/mpt/trunk/impl/imap-mailbox/src/test/java/org/apache/james/mpt/imapmailbox/ImapProtocolFramework.java
Mon Mar 11 06:43:24 2013
@@ -18,17 +18,16 @@
  ****************************************************************/
 package org.apache.james.mpt.imapmailbox;
 
+import org.apache.james.mpt.AbstractSimpleScriptedTestProtocol;
 import org.apache.james.mpt.HostSystem;
-import org.apache.james.mpt.imapmailbox.base.AbstractSimpleScriptedTestProtocol;
 
 /**
  * Specialise the protocol test framework for IMAP.
  */
-public abstract class ImapProtocolFramework extends
-        AbstractSimpleScriptedTestProtocol implements ImapTestConstants {
+public abstract class ImapProtocolFramework extends AbstractSimpleScriptedTestProtocol implements
ImapTestConstants {
 
     public ImapProtocolFramework(final HostSystem hostSystem) throws Exception {
         super(hostSystem, USER, PASSWORD, "/org/apache/james/imap/scripts/");
     }
 
-}
\ No newline at end of file
+}



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


Mime
View raw message