You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2008/11/26 23:06:21 UTC
svn commit: r720999 - in /james/protocol-tester/trunk/main/src:
main/java/org/apache/james/mpt/ test/java/org/apache/james/mpt/
Author: rdonkin
Date: Wed Nov 26 14:06:20 2008
New Revision: 720999
URL: http://svn.apache.org/viewvc?rev=720999&view=rev
Log:
Factored out Runner to allow scripts to be run from outside the test hierarchy. HostSystem is over-broad so factored out SessionFactory.
Added:
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java (with props)
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Session.java
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SessionFactory.java
Modified:
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java
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/HostSystem.java
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ProtocolSession.java
james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
Modified: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java?rev=720999&r1=720998&r2=720999&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/AbstractProtocolTestFramework.java Wed Nov 26 14:06:20 2008
@@ -32,15 +32,8 @@
* @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;
@@ -50,6 +43,7 @@
this.hostSystem = hostSystem;
this.userName = userName;
this.password = password;
+ runner = new Runner();
}
protected void setUp() throws Exception {
@@ -58,9 +52,7 @@
}
protected void continueAfterFailure() {
- preElements.setContinueAfterFailure(true);
- testElements.setContinueAfterFailure(true);
- postElements.setContinueAfterFailure(true);
+ runner.continueAfterFailure();
}
/**
@@ -75,38 +67,7 @@
* {@link MockImapServer#getImapSession()} works.
*/
protected void runSessions() throws Exception {
- class SessionContinuation implements HostSystem.Continuation {
-
- public ProtocolSession session;
-
- public void doContinue() {
- if (session != null) {
- session.doContinue();
- }
- }
-
- }
- SessionContinuation continuation = new SessionContinuation();
-
- HostSystem.Session[] sessions = new HostSystem.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();
- }
- }
+ runner.runSessions(hostSystem);
}
/**
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=720999&r1=720998&r2=720999&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 Wed Nov 26 14:06:20 2008
@@ -57,12 +57,11 @@
* Reads test elements from the protocol session file and adds them to the
* {@link #testElements} ProtocolSession. Then calls {@link #runSessions}.
*
- * @param locale
- * TODO
+ * @param locale test under this default locale, not null
*/
protected void scriptTest(String fileName, Locale locale) throws Exception {
Locale.setDefault(locale);
- addTestFile(fileName + ".test", testElements);
+ addTestFile(fileName + ".test", runner.getTestElements());
runSessions();
}
Modified: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java?rev=720999&r1=720998&r2=720999&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java Wed Nov 26 14:06:20 2008
@@ -23,7 +23,7 @@
* Host system under test.
* @see Session supports multiple connection to the host system
*/
-public interface HostSystem {
+public interface HostSystem extends SessionFactory {
/**
* Resets host system to initial state.
@@ -43,49 +43,6 @@
*/
public void addUser(String user, String password) throws Exception;
- /**
- * Creates a new session for functional testing.
- *
- * @return <code>Session</code>, not null
- * @throws Exception
- */
- public Session newSession(Continuation continuation) throws Exception;
-
- /**
- * A connection to the host.
- */
- public interface Session {
-
- /**
- * Reads a line from the session input,
- * blocking until a new line is available.
- * @return not null
- * @throws Exception
- */
- public String readLine() throws Exception;
-
- /**
- * Writes a line to the session output.
- * @param line not null
- * @throws Exception
- */
- public void writeLine(String line) throws Exception;
-
- /**
- * Opens the session.
- *
- * @throws Exception
- */
- public void start() throws Exception;
-
- /**
- * Closes the session.
- *
- * @throws Exception
- */
- public void stop() throws Exception;
- }
-
public interface Continuation {
public void doContinue();
}
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=720999&r1=720998&r2=720999&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 Wed Nov 26 14:06:20 2008
@@ -47,7 +47,7 @@
private Iterator elementsIterator;
- private HostSystem.Session[] sessions;
+ private Session[] sessions;
private ProtocolElement nextTest;
@@ -82,7 +82,7 @@
* @param in
* The server responses are read from here.
*/
- public void runSessions(HostSystem.Session[] sessions) throws Exception {
+ public void runSessions(Session[] sessions) throws Exception {
this.sessions = sessions;
elementsIterator = testElements.iterator();
while (elementsIterator.hasNext()) {
@@ -213,20 +213,20 @@
*
* @throws Exception
*/
- public void testProtocol(HostSystem.Session[] sessions,
+ public void testProtocol(Session[] sessions,
boolean continueAfterFailure) throws Exception {
if (sessionNumber < 0) {
for (int i = 0; i < sessions.length; i++) {
- HostSystem.Session session = sessions[i];
+ Session session = sessions[i];
writeMessage(session);
}
} else {
- HostSystem.Session session = sessions[sessionNumber];
+ Session session = sessions[sessionNumber];
writeMessage(session);
}
}
- private void writeMessage(HostSystem.Session session) throws Exception {
+ private void writeMessage(Session session) throws Exception {
session.writeLine(message);
}
@@ -295,20 +295,20 @@
* If the actual server response didn't match the regular
* expression expected.
*/
- public void testProtocol(HostSystem.Session[] sessions,
+ public void testProtocol(Session[] sessions,
boolean continueAfterFailure) throws Exception {
if (sessionNumber < 0) {
for (int i = 0; i < sessions.length; i++) {
- HostSystem.Session session = sessions[i];
+ Session session = sessions[i];
checkResponse(session, continueAfterFailure);
}
} else {
- HostSystem.Session session = sessions[sessionNumber];
+ Session session = sessions[sessionNumber];
checkResponse(session, continueAfterFailure);
}
}
- protected void checkResponse(HostSystem.Session session,
+ protected void checkResponse(Session session,
boolean continueAfterFailure) throws Exception {
String testLine = readLine(session);
if (!match(expectedLine, testLine)) {
@@ -344,7 +344,7 @@
*
* @return String of the line from the server
*/
- protected String readLine(HostSystem.Session session) throws Exception {
+ protected String readLine(Session session) throws Exception {
try {
return session.readLine();
} catch (IOException e) {
@@ -411,7 +411,7 @@
* If a line is encountered which doesn't match one of the
* expected lines.
*/
- protected void checkResponse(HostSystem.Session session,
+ protected void checkResponse(Session session,
boolean continueAfterFailure) throws Exception {
List testLines = new ArrayList(expectedLines);
while (testLines.size() > 0) {
@@ -456,9 +456,9 @@
this.sessionNumber = sessionNumber < 0 ? 0 : sessionNumber;
}
- public void testProtocol(HostSystem.Session[] sessions,
+ public void testProtocol(Session[] sessions,
boolean continueAfterFailure) throws Exception {
- HostSystem.Session session = sessions[sessionNumber];
+ Session session = sessions[sessionNumber];
continuationExpected = true;
continued = false;
String testLine = session.readLine();
@@ -497,7 +497,7 @@
* TODO
* @throws Exception
*/
- void testProtocol(HostSystem.Session[] sessions,
+ void testProtocol(Session[] sessions,
boolean continueAfterFailure) throws Exception;
boolean isClient();
Added: 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=720999&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java Wed Nov 26 14:06:20 2008
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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;
+
+/**
+ * Runs protocol scripts.
+ */
+public class Runner {
+
+ /** The Protocol session which is run before the testElements */
+ private final ProtocolSession preElements = new ProtocolSession();
+
+ /** The Protocol session which contains the tests elements */
+ private final ProtocolSession testElements = new ProtocolSession();
+
+ /** The Protocol session which is run after the testElements. */
+ private final ProtocolSession postElements = new ProtocolSession();
+
+ public void continueAfterFailure() {
+ preElements.setContinueAfterFailure(true);
+ testElements.setContinueAfterFailure(true);
+ postElements.setContinueAfterFailure(true);
+ }
+
+ /**
+ * Gets protocol session run after test.
+ * @return not null
+ */
+ public ProtocolSession getPostElements() {
+ return postElements;
+ }
+
+ /**
+ * Gets protocol session run before test.
+ * @return not null
+ */
+ public ProtocolSession getPreElements() {
+ return preElements;
+ }
+ /**
+ * Gets protocol session run on test.
+ * @return not null
+ */
+ public ProtocolSession getTestElements() {
+ return testElements;
+ }
+
+
+
+ /**
+ * Runs the pre,test and post protocol sessions against a local copy of the
+ * ImapServer. This does not require that James be running, and is useful
+ * for rapid development and debugging.
+ *
+ * Instead of sending requests to a socket connected to a running instance
+ * of James, this method uses the {@link MockImapServer} to simplify
+ * testing. One mock instance is required per protocol session/connection.
+ * These share the same underlying Mailboxes, because of the way
+ * {@link MockImapServer#getImapSession()} works.
+ */
+ public void runSessions(final SessionFactory factory) throws Exception {
+ class SessionContinuation implements HostSystem.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] = factory.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();
+ }
+ }
+ }
+
+}
Propchange: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Runner.java
------------------------------------------------------------------------------
svn:mergeinfo =
Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Session.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Session.java?rev=720999&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Session.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/Session.java Wed Nov 26 14:06:20 2008
@@ -0,0 +1,36 @@
+package org.apache.james.mpt;
+
+/**
+ * A connection to the host.
+ */
+public interface Session {
+
+ /**
+ * Reads a line from the session input,
+ * blocking until a new line is available.
+ * @return not null
+ * @throws Exception
+ */
+ public String readLine() throws Exception;
+
+ /**
+ * Writes a line to the session output.
+ * @param line not null
+ * @throws Exception
+ */
+ public void writeLine(String line) throws Exception;
+
+ /**
+ * Opens the session.
+ *
+ * @throws Exception
+ */
+ public void start() throws Exception;
+
+ /**
+ * Closes the session.
+ *
+ * @throws Exception
+ */
+ public void stop() throws Exception;
+}
\ No newline at end of file
Added: james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SessionFactory.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SessionFactory.java?rev=720999&view=auto
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SessionFactory.java (added)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/SessionFactory.java Wed Nov 26 14:06:20 2008
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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 org.apache.james.mpt.HostSystem.Continuation;
+
+/**
+ * Builds sessions for protocol testing.
+ */
+public interface SessionFactory {
+
+ /**
+ * Creates a new session for functional testing.
+ *
+ * @return <code>Session</code>, not null
+ * @throws Exception
+ */
+ public abstract Session newSession(Continuation continuation)
+ throws Exception;
+
+}
\ No newline at end of file
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=720999&r1=720998&r2=720999&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 Wed Nov 26 14:06:20 2008
@@ -64,7 +64,7 @@
}
public void testWrite() throws Exception {
- ExternalHostSystem.Session session = newSession(SHABANG);
+ Session session = newSession(SHABANG);
final String in = "Hello, World";
session.writeLine(in);
session.stop();
@@ -77,9 +77,9 @@
system.addUser(USER, PASSWORD);
}
- private ExternalHostSystem.Session newSession(final String shabang) throws Exception {
+ private Session newSession(final String shabang) throws Exception {
ExternalHostSystem system = buildSystem(shabang);
- ExternalHostSystem.Session session = system.newSession(continuation);
+ Session session = system.newSession(continuation);
return session;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org