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/30 12:04:07 UTC
svn commit: r721793 - in /james/protocol-tester/trunk:
antlib/src/main/java/org/apache/james/mpt/ant/ antlib/src/site/xdoc/
antlib/src/test/resources/ main/src/main/java/org/apache/james/mpt/
Author: rdonkin
Date: Sun Nov 30 03:04:07 2008
New Revision: 721793
URL: http://svn.apache.org/viewvc?rev=721793&view=rev
Log:
Tidy up build.xml and support AddUser script as body text.
Modified:
james/protocol-tester/trunk/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
james/protocol-tester/trunk/antlib/src/site/xdoc/index.xml
james/protocol-tester/trunk/antlib/src/test/resources/build.xml
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java
Modified: james/protocol-tester/trunk/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java?rev=721793&r1=721792&r2=721793&view=diff
==============================================================================
--- james/protocol-tester/trunk/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java (original)
+++ james/protocol-tester/trunk/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java Sun Nov 30 03:04:07 2008
@@ -20,11 +20,17 @@
package org.apache.james.mpt.ant;
import java.io.File;
+import java.io.FileReader;
+import java.io.Reader;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import org.apache.james.mpt.Monitor;
+import org.apache.james.mpt.ScriptedUserAdder;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.Union;
@@ -33,7 +39,7 @@
* Task executes MPT scripts against a server
* running on a given port and host.
*/
-public class MailProtocolTestTask extends Task {
+public class MailProtocolTestTask extends Task implements Monitor {
private File script;
private Union scripts;
@@ -153,13 +159,15 @@
}
/**
- *
+ * Adds a user.
*/
- public static class AddUser {
+ public class AddUser {
+
private int port;
private String user;
private String passwd;
private File script;
+ private String scriptText;
/**
* Gets the port against which the user addition
@@ -211,6 +219,14 @@
public void setUser(String user) {
this.user = user;
}
+
+ /**
+ * Sets user addition script.
+ * @param scriptText not null
+ */
+ public void addText(String scriptText) {
+ this.scriptText = getProject().replaceProperties(scriptText);
+ }
/**
* Gets the file containing the user creation script.
@@ -232,19 +248,46 @@
* Validates mandatory fields have been filled.
*/
void validate() throws BuildException {
- if (script == null) {
- throw new BuildException("'script' attribute must be set on AddUser to the file containing the user creations script.");
+ if (script == null && scriptText == null) {
+ throw new BuildException("Either the 'script' attribute must be set, or the body must contain the text of the script");
+ }
+
+ if (script != null && scriptText != null) {
+ throw new BuildException("Choose either script text or script attribute but not both.");
}
+
if (user == null) {
throw new BuildException("'user' attribute must be set on AddUser to the name of the user to be created.");
}
+
if (passwd == null) {
throw new BuildException("'passwd' attribute must be set on AddUser to the password to be set for the user created");
}
+
if (port <= 0) {
throw new BuildException("'port' attribute must be set on AddUser to the port against which the script should run.");
}
-
}
+
+ void execute() throws BuildException {
+ validate();
+ try {
+ final File scriptFile = getScript();
+ final Reader reader;
+ if (scriptFile == null) {
+ reader = new StringReader(scriptText);
+ } else {
+ reader = new FileReader(scriptFile);
+ }
+ ScriptedUserAdder adder = new ScriptedUserAdder(getHost(), getPort(), MailProtocolTestTask.this);
+ adder.addUser(getUser(), getPasswd(), reader);
+ } catch (Exception e) {
+ throw new BuildException("User addition failed", e);
+ }
+ }
+ }
+
+ public void note(String message) {
+ log(message, Project.MSG_DEBUG);
}
}
Modified: james/protocol-tester/trunk/antlib/src/site/xdoc/index.xml
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/antlib/src/site/xdoc/index.xml?rev=721793&r1=721792&r2=721793&view=diff
==============================================================================
--- james/protocol-tester/trunk/antlib/src/site/xdoc/index.xml (original)
+++ james/protocol-tester/trunk/antlib/src/site/xdoc/index.xml Sun Nov 30 03:04:07 2008
@@ -121,9 +121,14 @@
<tr>
<td>script</td>
<td>File containing the user creation script</td>
- <td>Yes</td>
+ <td>Either this attribute must be set, or the user addition script </td>
</tr>
</table>
+<p>
+User addition scripts are typically short. As an alternative to the script attribute
+(which specifies the file containing the script), the script text can be added directly
+as text to the body of this element.
+</p>
</subsection>
<subsection name='Example'>
<p>TODO:</p>
Modified: james/protocol-tester/trunk/antlib/src/test/resources/build.xml
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/antlib/src/test/resources/build.xml?rev=721793&r1=721792&r2=721793&view=diff
==============================================================================
--- james/protocol-tester/trunk/antlib/src/test/resources/build.xml (original)
+++ james/protocol-tester/trunk/antlib/src/test/resources/build.xml Sun Nov 30 03:04:07 2008
@@ -17,94 +17,108 @@
specific language governing permissions and limitations
under the License.
-->
-<project
- name="tests" default="all"
- xmlns:au="antlib:org.apache.ant.antunit"
- xmlns:mpt="antlib:org.apache.james.mpt.ant">
-
- <taskdef uri="antlib:org.apache.ant.antunit"
- resource="org/apache/ant/antunit/antlib.xml"
- classpath="${test.classpath}" />
-
- <taskdef uri="antlib:org.apache.james.mpt.ant"
- resource="org/apache/james/mpt/ant/antlib.xml"
- classpath="${jar.name}" />
-
- <target name='testMustNotAllowScriptsAndScript'>
- <au:expectfailure>
- <mpt:mpt skip='true' port='10000' script='pom.xml'>
- <fileset dir='${basedir}'/>
- </mpt:mpt>
- </au:expectfailure>
- </target>
-
- <target name='testMustSetScriptsOrScript'>
- <au:expectfailure>
- <mpt:mpt skip='true' port='10000'/>
- </au:expectfailure>
- <mpt:mpt port='10000' skip='true'>
- <fileset dir='${basedir}'/>
- </mpt:mpt>
- <mpt:mpt port='10000' skip='true' script='pom.xml'/>
- </target>
-
- <target name='testMustSetPort'>
- <au:expectfailure>
- <mpt:mpt skip='true'>
- <fileset dir='${basedir}'/>
- </mpt:mpt>
- </au:expectfailure>
- <mpt:mpt port='10000' skip='true'>
- <fileset dir='${basedir}'/>
- </mpt:mpt>
- </target>
-
- <target name='testMaySetHost'>
- <mpt:mpt port='10000' skip='true' host='example.org'>
- <fileset dir='${basedir}'/>
- </mpt:mpt>
- <mpt:mpt port='10000' skip='true' host='10.0.0.66'>
- <fileset dir='${basedir}'/>
- </mpt:mpt>
- </target>
-
- <target name='testShouldAllowAddUserToBeSet'>
- <mpt:mpt port='10000' skip='true' host='example.org'>
- <fileset dir='${basedir}'/>
- <addUser port='10001' user='user' passwd='passwd' script='pom.xml'/>
- </mpt:mpt>
- </target>
-
-
- <target name='testAddUserMustSetPortNamePasswordScript'>
- <au:expectfailure>
- <mpt:mpt port='10000' skip='true' host='example.org'>
- <fileset dir='${basedir}'/>
- <addUser user='user' passwd='passwd' script='pom.xml'/>
- </mpt:mpt>
- </au:expectfailure>
- <au:expectfailure>
- <mpt:mpt port='10000' skip='true' host='example.org'>
- <fileset dir='${basedir}'/>
- <addUser port='10001' passwd='passwd' script='pom.xml'/>
- </mpt:mpt>
- </au:expectfailure>
- <au:expectfailure>
- <mpt:mpt port='10000' skip='true' host='example.org'>
- <fileset dir='${basedir}'/>
- <addUser port='10001' user='user' script='pom.xml'/>
- </mpt:mpt>
- </au:expectfailure>
- <au:expectfailure>
- <mpt:mpt port='10000' skip='true' host='example.org'>
- <fileset dir='${basedir}'/>
- <addUser port='10001' user='user' passwd='passwd'/>
- </mpt:mpt>
- </au:expectfailure>
- </target>
-
- <target name='testMptAttributes' depends='testMustSetPort, testMaySetHost,testMustSetScriptsOrScript, testMustNotAllowScriptsAndScript'/>
- <target name='testAddUser' depends='testShouldAllowAddUserToBeSet, testAddUserMustSetPortNamePasswordScript'/>
-
- <target name='all' depends='testMptAttributes, testAddUser'/>
+<project name="tests" default="all" xmlns:au="antlib:org.apache.ant.antunit" xmlns:mpt="antlib:org.apache.james.mpt.ant">
+
+ <taskdef uri="antlib:org.apache.ant.antunit" resource="org/apache/ant/antunit/antlib.xml" classpath="${test.classpath}" />
+
+ <taskdef uri="antlib:org.apache.james.mpt.ant" resource="org/apache/james/mpt/ant/antlib.xml">
+ <classpath>
+ <pathelement location="${jar.name}" />
+ <pathelement path='${test.classpath}' />
+ </classpath>
+ </taskdef>
+
+ <target name='testMustNotAllowScriptsAndScript'>
+ <au:expectfailure>
+ <mpt:mpt skip='true' port='10000' script='pom.xml'>
+ <fileset dir='${basedir}' />
+ </mpt:mpt>
+ </au:expectfailure>
+ </target>
+
+ <target name='testMustSetScriptsOrScript'>
+ <au:expectfailure>
+ <mpt:mpt skip='true' port='10000' />
+ </au:expectfailure>
+ <mpt:mpt port='10000' skip='true'>
+ <fileset dir='${basedir}' />
+ </mpt:mpt>
+ <mpt:mpt port='10000' skip='true' script='pom.xml' />
+ </target>
+
+ <target name='testMustSetPort'>
+ <au:expectfailure>
+ <mpt:mpt skip='true'>
+ <fileset dir='${basedir}' />
+ </mpt:mpt>
+ </au:expectfailure>
+ <mpt:mpt port='10000' skip='true'>
+ <fileset dir='${basedir}' />
+ </mpt:mpt>
+ </target>
+
+ <target name='testMaySetHost'>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}' />
+ </mpt:mpt>
+ <mpt:mpt port='10000' skip='true' host='10.0.0.66'>
+ <fileset dir='${basedir}' />
+ </mpt:mpt>
+ </target>
+
+ <target name='testShouldAllowAddUserToBeSet'>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}' />
+ <addUser port='10001' user='user' passwd='passwd' script='pom.xml' />
+ </mpt:mpt>
+ </target>
+
+
+ <target name='testAddUserMustSetPortNamePasswordScript'>
+ <au:expectfailure>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}' />
+ <addUser user='user' passwd='passwd' script='pom.xml' />
+ </mpt:mpt>
+ </au:expectfailure>
+ <au:expectfailure>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}' />
+ <addUser port='10001' passwd='passwd' script='pom.xml' />
+ </mpt:mpt>
+ </au:expectfailure>
+ <au:expectfailure>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}' />
+ <addUser port='10001' user='user' script='pom.xml' />
+ </mpt:mpt>
+ </au:expectfailure>
+ <au:expectfailure>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}' />
+ <addUser port='10001' user='user' passwd='passwd' />
+ </mpt:mpt>
+ </au:expectfailure>
+ </target>
+
+ <target name='testAddUserMayIncludeScriptText'>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}'/>
+ <addUser port='10000' user='user' passwd='passwd'>C: Foo Bar</addUser>
+ </mpt:mpt>
+ </target>
+
+ <target name='testAddUserBothScriptTextAndScriptAttributeMayNotBeSet'>
+ <au:expectfailure>
+ <mpt:mpt port='10000' skip='true' host='example.org'>
+ <fileset dir='${basedir}'/>
+ <addUser port='10000' user='user' passwd='passwd' script='pom.xml'>C: Foo Bar</addUser>
+ </mpt:mpt>
+ </au:expectfailure>
+ </target>
+
+ <target name='testMptAttributes' depends='testMustSetPort, testMaySetHost,testMustSetScriptsOrScript, testMustNotAllowScriptsAndScript'/>
+ <target name='testAddUser' depends='testShouldAllowAddUserToBeSet, testAddUserMustSetPortNamePasswordScript, testAddUserMayIncludeScriptText, testAddUserBothScriptTextAndScriptAttributeMayNotBeSet'/>
+
+ <target name='all' depends='testMptAttributes, testAddUser'/>
</project>
Modified: 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=721793&r1=721792&r2=721793&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java (original)
+++ james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ScriptedUserAdder.java Sun Nov 30 03:04:07 2008
@@ -19,6 +19,7 @@
package org.apache.james.mpt;
+import java.io.Reader;
import java.io.StringReader;
/**
@@ -37,10 +38,31 @@
private final String script;
private final Monitor monitor;
+ /**
+ * Constructs an adder without a script.
+ * Note that {@link #addUser(String, String)} will not be available
+ * @param host connect to this host
+ * @param port connect to this port
+ */
+ public ScriptedUserAdder(final String host, final int port)
+ {
+ this(host, port, (String) null);
+ }
+
public ScriptedUserAdder(final String host, final int port, final String script) {
this(host, port, script, new NullMonitor());
}
+ /**
+ * Note that {@link #addUser(String, String)} will not be available
+ * @param host connect to this host
+ * @param port connect to this port
+ * @param monitor not null
+ */
+ public ScriptedUserAdder(final String host, final int port, final Monitor monitor) {
+ this(host, port, null, monitor);
+ }
+
public ScriptedUserAdder(final String host, final int port, final String script, final Monitor monitor) {
this.host = host;
this.port = port;
@@ -48,13 +70,31 @@
this.monitor = monitor;
}
+ /**
+ * Adds a user using the script read from the given input.
+ * @param user user name, not null
+ * @param password password to set, not null
+ * @throws Exception upon failure
+ * @throws NullPointerException when script has not been set
+ */
public void addUser(final String user, final String password) throws Exception {
+ final StringReader reader = new StringReader(script);
+ addUser(user, password, reader);
+ }
+
+ /**
+ * Adds a user using the script read from the given input.
+ * @param user user name, not null
+ * @param password password to set, not null
+ * @param reader reader for script, not null
+ * @throws Exception upon failure
+ */
+ public void addUser(final String user, final String password, final Reader reader) 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);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org