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 15:56:43 UTC
svn commit: r721825 - in /james/protocol-tester/trunk/antlib/src:
main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
test/java/org/apache/james/mpt/ant/TestAddUser.java
test/java/org/apache/james/mpt/ant/TestRunScripts.java
Author: rdonkin
Date: Sun Nov 30 06:56:43 2008
New Revision: 721825
URL: http://svn.apache.org/viewvc?rev=721825&view=rev
Log:
Implement script execution
Added:
james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java
Modified:
james/protocol-tester/trunk/antlib/src/main/java/org/apache/james/mpt/ant/MailProtocolTestTask.java
james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.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=721825&r1=721824&r2=721825&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 06:56:43 2008
@@ -21,18 +21,25 @@
import java.io.File;
import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
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.ExternalHostSystem;
import org.apache.james.mpt.Monitor;
+import org.apache.james.mpt.ProtocolSessionBuilder;
+import org.apache.james.mpt.Runner;
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.Resource;
import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.Union;
/**
@@ -46,6 +53,7 @@
private int port = 0;
private String host = "127.0.0.1";
private boolean skip = false;
+ private String shabang = "";
private Collection users = new ArrayList();
/**
@@ -115,6 +123,11 @@
this.script = script;
}
+ //TODO:
+ public String getShabang() {
+ return shabang;
+ }
+
//@Override
public void execute() throws BuildException {
if (port <= 0) {
@@ -153,6 +166,38 @@
final AddUser userAdder = (AddUser) it.next();
userAdder.execute();
}
+
+ final ExternalHostSystem host = new ExternalHostSystem(getHost(), getPort(), this, getShabang(), null);
+ final ProtocolSessionBuilder builder = new ProtocolSessionBuilder();
+
+ if (scripts == null) {
+ scripts = new Union();
+ scripts.add(new FileResource(script));
+ }
+
+ for (final Iterator it=scripts.iterator();it.hasNext();) {
+ final Resource resource = (Resource) it.next();
+ try {
+ final Runner runner = new Runner();
+
+ try {
+
+ final InputStream inputStream = resource.getInputStream();
+ final String name = resource.getName();
+ builder.addProtocolLines(name == null ? "[Unknown]" : name, inputStream, runner.getTestElements());
+ runner.runSessions(host);
+
+ } catch (UnsupportedOperationException e) {
+ log("Resource cannot be read: " + resource.getName(), Project.MSG_WARN);
+ }
+ } catch (IOException e) {
+ throw new BuildException("Cannot load script " + resource.getName(), e);
+ } catch (Exception e) {
+ throw new BuildException("[FAILURE] in script " + resource.getName(), e);
+ }
+
+ }
+
}
public AddUser createAddUser() {
Modified: james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java?rev=721825&r1=721824&r2=721825&view=diff
==============================================================================
--- james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java (original)
+++ james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestAddUser.java Sun Nov 30 06:56:43 2008
@@ -23,6 +23,7 @@
import org.apache.james.mpt.DiscardProtocol;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.resources.Union;
import junit.framework.TestCase;
@@ -45,7 +46,7 @@
subject = new MailProtocolTestTask();
subject.setHost("127.0.0.1");
subject.setPort(PORT+1);
- subject.setScript(new File("pom.xml"));
+ subject.add(new Union());
subject.setProject(new Project());
}
Added: james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java
URL: http://svn.apache.org/viewvc/james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java?rev=721825&view=auto
==============================================================================
--- james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java (added)
+++ james/protocol-tester/trunk/antlib/src/test/java/org/apache/james/mpt/ant/TestRunScripts.java Sun Nov 30 06:56:43 2008
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.ant;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.james.mpt.DiscardProtocol;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.types.resources.StringResource;
+import org.apache.tools.ant.types.resources.Union;
+
+public class TestRunScripts extends TestCase {
+
+ private static final String SCRIPT = "A script";
+
+ private static final int PORT = 10001;
+
+ Union stubResourceCollection;
+ Resource stubResource;
+
+ DiscardProtocol fakeServer;
+ DiscardProtocol.Record record;
+
+ MailProtocolTestTask subject;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ fakeServer = new DiscardProtocol(PORT);
+ fakeServer.start();
+ record = fakeServer.recordNext();
+
+ stubResourceCollection = new Union();
+ stubResource = new StringResource("C: " + SCRIPT);
+ stubResourceCollection.add(stubResource);
+
+ subject = new MailProtocolTestTask();
+ subject.setHost("127.0.0.1");
+ subject.setPort(PORT);
+ subject.setProject(new Project());
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fakeServer.stop();
+ }
+
+ public void testIgnoreUnsupportedResource() throws Exception {
+ final Resource unsupportedResource = new StringResource() {
+ public InputStream getInputStream() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ stubResourceCollection.add(unsupportedResource);
+ subject.add(stubResourceCollection);
+ subject.execute();
+ assertEquals(SCRIPT +"\r\n", record.complete());
+ }
+
+ public void testRunOneScriptFromCollection() throws Exception {
+ subject.add(stubResourceCollection);
+ subject.execute();
+ assertEquals(SCRIPT +"\r\n", record.complete());
+ }
+
+ public void testRunOneScriptFromAttribute() throws Exception {
+ final File file = File.createTempFile("Test", "mpt");
+ file.deleteOnExit();
+ final FileWriter writer = new FileWriter(file);
+ writer.write("C: " + SCRIPT);
+ writer.close();
+ subject.setScript(file);
+ subject.execute();
+ assertEquals(SCRIPT +"\r\n", record.complete());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org