[jboss-cvs] JBossAS SVN: r104566 - in branches/JBPAPP_5_1/testsuite: imports and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 7 12:27:23 EDT 2010


Author: rachmatowicz at jboss.com
Date: 2010-05-07 12:27:21 -0400 (Fri, 07 May 2010)
New Revision: 104566

Added:
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/README.txt
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AbstractShellScriptExecutor.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AsyncShellScriptExecutor.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/LogFileAssertionChecker.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ProbeTestCase.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/RunTestCase.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ScriptsTestBase.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ShutdownTestCase.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/TwiddleTestCase.java
Modified:
   branches/JBPAPP_5_1/testsuite/build.xml
   branches/JBPAPP_5_1/testsuite/imports/server-config.xml
Log:
Automation of AS command-line scripts (JBQA-3309)

Modified: branches/JBPAPP_5_1/testsuite/build.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/build.xml	2010-05-07 16:24:13 UTC (rev 104565)
+++ branches/JBPAPP_5_1/testsuite/build.xml	2010-05-07 16:27:21 UTC (rev 104566)
@@ -3567,11 +3567,120 @@
     </junit>
     
     <server:stop  name="classloader-leak"/>
+  </target>
+
+  <!-- script tests -->
+  <target name="tests-scripts">
+    <mkdir dir="${build.reports}"/>
+    <mkdir dir="${build.testlog}"/>
     
+    <create-config baseconf="all" newconf="scripts">
+      <patternset>
+	<include name="conf/**"/>
+	<include name="deploy/**"/>
+	<include name="deployers/**"/>
+	<include name="deploy-hasingleton/**"/>
+	<include name="farm/**"/>
+	<include name="lib/**"/>
+      </patternset>
+    </create-config>
+    <server:start name="scripts"/>
+    
+    <!-- script tests which require a started server -->
+    <junit dir="${module.output}" printsummary="${junit.printsummary}" haltonerror="${junit.haltonerror}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}"
+	   timeout="${junit.timeout}" jvm="${junit.jvm}">
+      
+      <jvmarg value="${junit.jvm.options}"/>
+      <!-- Used for JGroups -->
+      <jvmarg value="-Dbind.address=${node0}"/>
+      <sysproperty key="jboss.dist" value="${jboss.dist}"/>
+      <sysproperty key="jbosstest.server.config" value="scripts"/>
+      <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>
+      <sysproperty key="build.testlog" value="${build.testlog}"/>
+      <sysproperty key="log4j.configuration" value="file:${build.resources}/log4j.xml"/>
+      <sysproperty key="java.naming.provider.url" value="${node0.jndi.url}"/>
+      <sysproperty key="jbosstest.server.host" value="${node0}"/>
+      <sysproperty key="jbosstest.server.host.url" value="${node0.url}"/>
+      <sysproperty key="java.net.preferIPv4Stack" value="${java.net.preferIPv4Stack}" />
+      <sysproperty key="java.net.preferIPv6Addresses" value="${java.net.preferIPv6Addresses}" />
+      <!-- Pass along any jbosstest.* system properties -->
+      <syspropertyset>
+	<propertyref prefix="jbosstest."/>
+      </syspropertyset>
+      <classpath>
+	<pathelement location="${build.classes}"/>
+	<pathelement location="${build.resources}"/>
+	<path refid="tests.classpath"/>
+      </classpath>
+      
+      <!--sysproperty key="jboss-junit-configuration" value="classloader-leak"/-->
+      <formatter classname="org.jboss.ant.taskdefs.XMLJUnitMultipleResultFormatter" usefile="${junit.formatter.usefile}" extension="-scripts.xml"/>
+      
+      <batchtest todir="${build.reports}" haltonerror="${junit.batchtest.haltonerror}" haltonfailure="${junit.batchtest.haltonfailure}" fork="${junit.batchtest.fork}">
+	
+	<fileset dir="${build.classes}">
+          <include name="**/test/scripts/test/TwiddleTestCase.class"/>
+          <include name="**/test/scripts/test/ProbeTestCase.class"/>
+	</fileset>
+      </batchtest>
+    </junit>
+    <server:stop  name="scripts"/>
+   </target>
+	
+ <target name="tests-scripts-noserver">
+    <mkdir dir="${build.reports}"/>
+    <mkdir dir="${build.testlog}"/>
+    
+    <create-config baseconf="default" newconf="scripts-noserver">
+      <patternset>
+	<include name="conf/**"/>
+	<include name="deploy/**"/>
+	<include name="deployers/**"/>
+	<include name="lib/**"/>
+      </patternset>
+    </create-config>
+    
+    <!-- script tests which start their own servers -->
+    <junit dir="${module.output}" printsummary="${junit.printsummary}" haltonerror="${junit.haltonerror}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}"
+	   timeout="${junit.timeout}" jvm="${junit.jvm}">
+      
+      <jvmarg value="${junit.jvm.options}"/>
+      <!-- Used for JGroups -->
+      <jvmarg value="-Dbind.address=${node0}"/>
+      <sysproperty key="jboss.dist" value="${jboss.dist}"/>
+      <sysproperty key="jbosstest.server.config" value="scripts-noserver"/>
+      <sysproperty key="jbosstest.deploy.dir" file="${build.lib}"/>
+      <sysproperty key="build.testlog" value="${build.testlog}"/>
+      <sysproperty key="log4j.configuration" value="file:${build.resources}/log4j.xml"/>
+      <sysproperty key="java.naming.provider.url" value="${node0.jndi.url}"/>
+      <sysproperty key="jbosstest.server.host" value="${node0}"/>
+      <sysproperty key="jbosstest.server.host.url" value="${node0.url}"/>
+      <sysproperty key="java.net.preferIPv4Stack" value="${java.net.preferIPv4Stack}" />
+      <sysproperty key="java.net.preferIPv6Addresses" value="${java.net.preferIPv6Addresses}" />
+      <!-- Pass along any jbosstest.* system properties -->
+      <syspropertyset>
+		<propertyref prefix="jbosstest."/>
+      </syspropertyset>
+      <classpath>
+		<pathelement location="${build.classes}"/>
+		<pathelement location="${build.resources}"/>
+		<path refid="tests.classpath"/>
+      </classpath>
+      
+      <!--sysproperty key="jboss-junit-configuration" value="classloader-leak"/-->
+      <formatter classname="org.jboss.ant.taskdefs.XMLJUnitMultipleResultFormatter" usefile="${junit.formatter.usefile}" extension="-scripts-noserver.xml"/>
+      
+      <batchtest todir="${build.reports}" haltonerror="${junit.batchtest.haltonerror}" haltonfailure="${junit.batchtest.haltonfailure}" fork="${junit.batchtest.fork}">
+	
+	  <fileset dir="${build.classes}">
+         <include name="**/test/scripts/test/RunTestCase.class"/>
+         <include name="**/test/scripts/test/ShutdownTestCase.class"/>
+	  </fileset>
+      </batchtest>
+    </junit>
   </target>
 
-
-   <!--
+	<!--
       | Run all database related tests
     -->
    <target name="tests-db" depends="run-db-tests, tests-report-html"/>

Modified: branches/JBPAPP_5_1/testsuite/imports/server-config.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/imports/server-config.xml	2010-05-07 16:24:13 UTC (rev 104565)
+++ branches/JBPAPP_5_1/testsuite/imports/server-config.xml	2010-05-07 16:27:21 UTC (rev 104566)
@@ -1145,7 +1145,17 @@
          <sysproperty key="jgroups.udp.ip_ttl" value="${jbosstest.udp.ip_ttl}" />
          <sysproperty key="xb.builder.useUnorderedSequence" value="true" />
       </server>
-
+    <server name="scripts" host="${node0}">
+       <jvmarg value="-Xms128m" />
+       <jvmarg value="-Xmx512m" />
+       <jvmarg value="-XX:MaxPermSize=512m" />
+       <jvmarg value="-XX:+HeapDumpOnOutOfMemoryError" />
+       <jvmarg value="-XX:-UseGCOverheadLimit" />
+       <sysproperty key="java.endorsed.dirs" value="${jboss.dist}/lib/endorsed" />
+       <sysproperty key="java.net.preferIPv4Stack" value="true" />
+       <sysproperty key="jgroups.udp.ip_ttl" value="${jbosstest.udp.ip_ttl}" />
+       <sysproperty key="xb.builder.useUnorderedSequence" value="true" />
+    </server>
    </server:config>
 
     <!-- A macro for printing sleep before going into sleep

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/README.txt
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/README.txt	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/README.txt	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,32 @@
+Test cases for command-line scripts
+-----------------------------------
+
+1. This directory ('scripts') contains automated tests for the command-line
+scripts found in JBOSS_DIST/bin directory, including run.sh, shutdown.sh,
+twiddle.sh and probe.sh. The tests also cover the case of the Windows-based
+counterparts.
+
+2. There are two test targets used to test these scripts:
+
+tests-scripts:
+- starts a JBoss instance called 'scripts' which is based on 'all'
+- executes TwiddleTestCase and ProbeTestCase against the instance
+- stops the JBoss instance
+- the server is started and stopped using JBoss Test
+
+tests-scripts-noserver:
+- makes use of a JBoss instance 'scripts-noserver' which is based on 'default'
+- executes RunTestCase and ShutdownTestCase
+- run.sh is used to start the servers
+- JMX shutdown or shutdown.sh is used to stop the servers, depending on
+the test case in question
+
+3. The commands and servers are executed using a small framework based
+on the classes AbstractShellScriptExecutor, ShellScriptExecutor and
+AsyncShellScriptExecutor. There is also a class for checking assertions
+on server log files called LogFileAssertionChecker.
+
+4. Due to the fact that tests-scripts-noserver involves starting and stopping
+a potentially number of servers, these tests will exceed the normal junit.timeout
+setting (3 minutes) and this needs to be extended. Also, it is wise to run this
+target at the end of the test suite or separately.   
\ No newline at end of file

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AbstractShellScriptExecutor.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AbstractShellScriptExecutor.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AbstractShellScriptExecutor.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.scripts.support;
+
+import java.io.BufferedReader ;
+import java.io.PrintWriter ;
+import java.io.StringWriter ;
+import java.io.IOException ;
+
+import junit.framework.Assert ;
+
+/**
+ * Base class to test command-line scripts.
+ * 
+ * @author Richard Achmatowicz
+ * @version $Revision: 1.0
+ */
+public abstract class AbstractShellScriptExecutor {
+
+	Process process = null ;
+	StringWriter outWriter = null ;
+	StringWriter errWriter = null ;
+	PrintWriter outlog = null ;
+	PrintWriter errorlog = null ;
+
+	public String getOutput() {
+		if (outWriter == null)
+			return null ;
+		return outWriter.toString() ;
+	}
+	public String getError() {
+		if (errWriter == null)
+			return null ;
+		return errWriter.toString() ;
+	}
+	public void assertOnOutputStream(String string, String failureMessage) {
+		if (getOutput().indexOf(string) == -1) {
+			// assertion does not hold
+			Assert.fail(failureMessage) ;
+		}
+	}
+	public void assertOnErrorStream(String string, String failureMessage) {
+		if (getError().indexOf(string) == -1) {
+			// assertion does not hold
+			Assert.fail(failureMessage) ;
+		}
+	}		
+	protected void closeAllStreams(Process process)
+	{
+		try {
+			process.getInputStream().close();
+			process.getOutputStream().close();
+			process.getErrorStream().close();
+		}
+		catch (IOException e) {
+		}
+	}   	
+	protected void writeShellCommand(String[] command ) {
+		// write the command to test case report
+		System.out.print("ShellScriptExecutor: executing shell command -> ") ;
+		for (int i = 0; i < command.length; i++) {
+			System.out.print(command[i] + " ") ;
+		}
+		System.out.println() ;
+	}
+
+	/*
+	 * Simple output pumper
+	 */
+	protected class OutputPumper extends Thread
+	{
+		private BufferedReader outputReader;
+		private PrintWriter logWriter;
+		public OutputPumper(BufferedReader outputReader, PrintWriter logWriter)
+		{
+			this.outputReader = outputReader;
+			this.logWriter = logWriter;
+		}
+		public void run()
+		{
+			try {
+				String line = null;
+				while ((line = outputReader.readLine()) != null) {
+					// System.out.println("Pumper trace:" +line) ;
+					logWriter.println(line);
+				}
+			}
+			catch (IOException e) {
+			}
+		}
+	}
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AsyncShellScriptExecutor.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AsyncShellScriptExecutor.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/AsyncShellScriptExecutor.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,303 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.scripts.support;
+
+import java.lang.InterruptedException ;
+import java.io.BufferedReader ;
+import java.io.InputStreamReader ;
+import java.io.PrintWriter ;
+import java.io.StringWriter ;
+import java.io.FileReader ;
+import java.io.FileWriter ;
+import java.io.File ;
+import java.io.FileInputStream ;
+import java.io.FileOutputStream ;
+import java.io.FileNotFoundException ;
+import java.io.IOException ;
+
+import org.jboss.test.scripts.support.AbstractShellScriptExecutor ;
+
+/**
+ * Class to execute shell scripts asynchronously and collect output
+ * 
+ * @author Richard Achmatowicz
+ * @version $Revision: 1.0
+ */
+public class AsyncShellScriptExecutor extends AbstractShellScriptExecutor {
+
+	/* variables for controlling use of shutdown.sar */
+	boolean useShutdown = false ;
+	String pathToShutdownSar = null ;
+	String deployDir = null ;
+
+	public boolean isRunning() {
+		return process != null ;
+	}		
+	public boolean getUseShutdown() {
+		return useShutdown ;
+	}
+	public void setUseShutdown(boolean useShutdown) {
+		this.useShutdown = useShutdown ;
+	}
+	public String getPathToShutdownSar() {
+		return pathToShutdownSar ;
+	}
+	public void setPathToShutdownSar(String pathToShutdownSar) {
+		this.pathToShutdownSar = pathToShutdownSar ;
+	}
+	public String getDeployDir() {
+		return deployDir ;
+	}
+	public void setDeployDir(String deployDir) {
+		this.deployDir = deployDir ;
+	}
+	public void startShellCommand(String[] commandArray) throws Exception {
+		startShellCommand(commandArray, null, null) ;
+	}
+	public void startShellCommand(String[] commandArray, String[] envp) throws Exception {
+		startShellCommand(commandArray, envp, null) ;
+	}    
+	public void startShellCommand(String[] commandArray, String[] envp, File workingDir) throws Exception {
+
+		/* create strings to write output to */
+		outWriter = new StringWriter() ;
+		outlog = new PrintWriter(outWriter,true);
+		errWriter = new StringWriter() ;
+		errorlog = new PrintWriter(errWriter,true);
+
+		/* transparency */
+		writeShellCommand(commandArray) ;
+
+		try {
+			process = Runtime.getRuntime().exec(commandArray, envp, workingDir);
+		} catch (IOException ioe) {
+			System.err.println("Could not start command."+ ioe);
+			return;
+		}
+
+		/* open the streams here */ 
+		final BufferedReader inStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
+		final BufferedReader errStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+		/* start pumping output from process to files */
+		Thread outPump = new OutputPumper(inStream, outlog);
+		outPump.start();
+		Thread errPump = new OutputPumper(errStream, errorlog);
+		errPump.start();
+
+		/* if we don't give the pumpers a little time, we can miss lines */
+		try {
+			Thread.sleep(100) ;
+		}
+		catch(InterruptedException ie) {
+		}
+		/* return control to the caller */
+	}
+
+	/*
+	 * Join and wait
+	 */
+	public void joinShellCommand() {
+		boolean terminated = false ;
+
+		/* check for tetrmination of the command */
+		int exitCode = 0 ;
+		try {
+			exitCode = process.exitValue() ;
+			terminated = true ;
+		}
+		catch (IllegalThreadStateException itse) {
+			System.out.println("Process not yet terminated - waiting for termination (possibly forever)") ;
+			// only wait if the stuff wa not found? The process has terminated already?
+			try {
+				exitCode = process.waitFor();
+				terminated = true ;
+			} catch (InterruptedException ie) {
+				System.out.println("Error in wait") ;
+			}
+		}
+		if (terminated) {
+			System.out.println("Process terminated exit code = " + exitCode) ;	    
+		}	
+
+		/* close the streams here */
+		outlog.close() ;
+		errorlog.close() ;
+		closeAllStreams(process) ;
+
+		/* indicate process is no longer running */
+		process = null ;
+	}
+
+	/*
+	 * Join with timeout
+	 */
+	public void joinShellCommand(int timeout) {
+		int timeLeft = timeout ;
+		boolean terminated = false ;
+
+		/* check for termination of the command */
+		int exitCode = 0 ;
+		try {
+			exitCode = process.exitValue() ;
+			terminated = true ;
+		}
+		catch (IllegalThreadStateException itse) {
+			/* the command has not terminated, wait for timeout seconds */
+			System.out.println("Process not yet terminated - waiting for " + timeout + " seconds") ;
+			while (timeLeft > 0) {
+				try {
+					exitCode = process.exitValue();
+					terminated = true ;
+					break ;
+				} catch (IllegalThreadStateException itse2) {
+					System.out.println("Still waiting...") ;
+					
+					try {
+						Thread.sleep(1*1000) ;
+					}
+					catch(InterruptedException ie) {
+					}
+					timeLeft-- ;
+				}
+			}
+
+			/* the command has not terminated, we need to kill it (somehow) */
+			if (!terminated) {
+				/* we are running a server instance via a shell */
+				if (useShutdown) {
+					
+					if (getPathToShutdownSar() == null || getDeployDir() == null) {
+						System.out.println("Skipping deployment of shutdown.sar: check that path to shutdown and deploy dir are set") ;
+					}
+					else {
+						try {
+							// shutdownServer(getDeployURL("shutdown.sar").getPath(), getDeployDir()) ;
+							shutdownServer(getPathToShutdownSar(), getDeployDir()) ;
+						}
+						catch(IOException e) {
+							/* we have got to do something about this case... */
+							/* short of getting the pid of the shell and sending a signal, I don't know */
+							System.out.println("Critical error: can't shut down server: " + e.getMessage()) ;
+						}
+					}
+					
+				}
+				/* now kill the shell process if it is still active */
+				try {
+					exitCode = process.exitValue();
+				} catch (IllegalThreadStateException itse3) {
+					System.out.println("Shell command did not terminate - destroying shell process...command may still be running") ;
+					// close the streams first
+					outlog.close() ;
+					errorlog.close() ;
+					closeAllStreams(process) ;
+					// kill the shell process
+					process.destroy() ;
+				}
+			}
+		}
+
+		if (terminated) {
+			System.out.println("Process terminated with exit code " + exitCode) ;
+		}
+
+		/* close the streams here */
+		outlog.close() ;
+		errorlog.close() ;
+		closeAllStreams(process) ;
+
+		/* indicate process is no longer running */
+		process = null ;
+	}		
+
+	/* 
+	 * Shutdown a server by deploying shutdown.sar into its deploy directory
+	 * and then deleting it.
+	 * 
+	 * This is about the only way we can kill a server started with run.sh/run.bat
+	 * due to the difficulty of: 
+	 * (i) discovering the process id of the shell or the server started by the shell
+	 * (ii) sending a signal to that process
+	 * on both Windows and UNIX. 
+	 */
+	private void shutdownServer(String pathToShutdownSar, String deployDir) throws IOException {
+
+		final int SHUTDOWN_DEPLOY_TIME = 5 ;
+		final int SHUTDOWN_UNDEPLOY_TIME = 10 ;
+
+		/* first try to shutdown the server instance */
+		System.out.println("Shell command did not terminate - deploying shutdown.sar...") ;
+		String shutdownSource = null ;
+		String shutdownTarget = null ;
+		try {
+			shutdownSource = pathToShutdownSar ;
+			shutdownTarget = deployDir + "/shutdown.sar" ;
+			// System.out.println("source = " + source) ;
+			// System.out.println("target = " + target) ;
+			copyFile(new File(shutdownSource), new File(shutdownTarget));
+		}
+		catch(Exception e) {
+			throw new IOException("Problem deploying shutdown: " + e.getMessage()) ;
+		} ;
+
+		// give shutdown.sar time to deploy
+		try {
+			Thread.sleep(SHUTDOWN_DEPLOY_TIME*1000) ;
+		}
+		catch(InterruptedException ie) {
+		}
+
+		// now undeploy shutdown.sar
+		File shutdown = new File(shutdownTarget) ;
+		if (!shutdown.exists()) {
+			throw new IOException("Problem undeploying shutdown: shutdown.sar file not found") ;
+		}
+		shutdown.delete() ;
+
+		// give shutdown.sar time to undeploy (and cause the AS to exit)
+		try {
+			Thread.sleep(SHUTDOWN_UNDEPLOY_TIME*1000) ;
+		}
+		catch(InterruptedException ie2) {
+		}
+	}
+
+	private void copyFile(File in, File out) throws Exception {
+		FileInputStream fis  = new FileInputStream(in);
+		FileOutputStream fos = new FileOutputStream(out);
+		try {
+			byte[] buf = new byte[1024];
+			int i = 0;
+			while ((i = fis.read(buf)) != -1) {
+				fos.write(buf, 0, i);
+			}
+		} 
+		catch (Exception e) {
+			throw e;
+		}
+		finally {
+			if (fis != null) fis.close();
+			if (fos != null) fos.close();
+		}
+	}
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/LogFileAssertionChecker.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/LogFileAssertionChecker.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/LogFileAssertionChecker.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.scripts.support;
+
+import java.io.BufferedReader ;
+import java.io.FileReader ;
+import java.io.IOException ;
+import java.io.FileNotFoundException ;
+
+/**
+ * Class to read error logs in incremental fashion.
+ * 
+ * @author Richard Achmatowicz
+ * @version $Revision: 1.0
+ */
+public class LogFileAssertionChecker {
+	int checkpoint ;
+	String filename = null ;
+	BufferedReader bufferedReader = null ;
+
+	public LogFileAssertionChecker(String filename) {
+		checkpoint = 0 ;
+		this.filename = filename ;
+	}
+
+	public void setCheckpoint(int checkpoint) {
+		this.checkpoint = checkpoint ;
+	}
+
+	public int getCheckpoint() {
+		return checkpoint ;
+	}
+
+	public boolean isStringInLog(String s, boolean useCheckpoint, boolean resetCheckpoint) {
+
+		int linesRead = 0 ;
+		String line = null ;
+		boolean found = false ;
+		
+		openLogFile() ;
+		try {
+			// if use check point, move the file to the check point before reading
+			if (useCheckpoint) {
+				for (int i = 0; i < checkpoint; i++) {
+					// read a line
+					line = bufferedReader.readLine() ;
+				}
+			}
+			// we are now at the last checkpoint in the file
+			while ((line = bufferedReader.readLine()) != null) {
+				// increment count of lines read
+				linesRead++ ;
+
+				// check if string in line
+				if (line.indexOf(s) > -1) {
+					// found the string
+					found = true ;
+					break ;
+				}
+			}
+		}
+		catch(IOException ioe) {
+			System.out.println("LogFileAssertionChecker: error while reading log file: " + filename) ;
+		}
+		// we can reset the checkpoint if no further searches required
+		if (resetCheckpoint) {
+			// set new checkpoint
+			checkpoint = checkpoint + linesRead ;
+		}
+		closeLogFile() ;
+		return found ;
+	}
+
+	/*
+	 * Open the log file for reading
+	 */
+	private void openLogFile() {
+		try {
+			bufferedReader = new BufferedReader(new FileReader(filename)) ;
+		}
+		catch(FileNotFoundException fnf) {
+			System.out.println("The file " + filename + " was not found: ex=" + fnf.toString()) ;
+		}
+	}
+
+	private void closeLogFile() {
+
+		try {
+			bufferedReader.close() ;
+		}
+		catch(IOException ioe) {
+			System.out.println("The file " + filename + " could not be closed: ex=" + ioe.toString()) ;
+		}
+	}
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/support/ShellScriptExecutor.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.scripts.support;
+
+import java.lang.InterruptedException ;
+import java.io.BufferedReader ;
+import java.io.InputStreamReader ;
+import java.io.PrintWriter ;
+import java.io.StringWriter ;
+import java.io.File ;
+import java.io.IOException ;
+
+import org.jboss.test.scripts.support.AbstractShellScriptExecutor ;
+
+/**
+ * Class to execute shell scripts synchronously and collect output
+ * 
+ * @author Richard Achmatowicz
+ * @version $Revision: 1.0
+ */
+public class ShellScriptExecutor extends AbstractShellScriptExecutor {
+
+	public void runShellCommand(String[] commandArray) throws Exception {
+		runShellCommand(commandArray, null, null) ;
+	}
+	public void runShellCommand(String[] commandArray, String[] envp) throws Exception {
+		runShellCommand(commandArray, envp, null) ;
+	}    
+	public void runShellCommand(String[] commandArray, String[] envp, File workingDir) throws Exception {
+
+		/* create strings to write output to */
+		outWriter = new StringWriter() ;
+		outlog = new PrintWriter(outWriter,true);
+		errWriter = new StringWriter() ;
+		errorlog = new PrintWriter(errWriter,true);
+
+		/* transparency */
+		writeShellCommand(commandArray) ;
+
+		try {
+			process = Runtime.getRuntime().exec(commandArray, envp, workingDir);
+		} catch (IOException ioe) {
+			System.err.println("Could not start command."+ ioe);
+			return;
+		}
+
+		/* open the streams here */ 
+		final BufferedReader inStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
+		final BufferedReader errStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+		/* start pumping output from process to files */
+		Thread outPump = new OutputPumper(inStream, outlog);
+		outPump.start();
+		Thread errPump = new OutputPumper(errStream, errorlog);
+		errPump.start();
+
+		/* check for tetrmination of the command */
+		int exitCode = 0 ;
+		try {
+			exitCode = process.exitValue() ;
+			// System.out.println("exit code = " + exitCode) ;
+		}
+		catch (IllegalThreadStateException itse) {
+			System.out.println("Process not yet terminated - waiting") ;
+			// only wait if the stuff wa not found? The process has terminated
+			// already?
+			try {
+				process.waitFor();
+			} catch (InterruptedException ie) {
+				System.out.println("Error in wait") ;
+			}
+		}
+
+		/* if we don't give the pumpers a little time, we can miss lines */
+		try {
+			Thread.sleep(1000) ;
+		}
+		catch(InterruptedException ie) {
+		}
+
+		/* close the streams here */
+		outlog.close() ;
+		errorlog.close() ;
+		closeAllStreams(process) ;
+	}
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ProbeTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ProbeTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ProbeTestCase.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009 Red Hat Middleware, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.scripts.test;
+
+import java.io.File ;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.jboss.test.JBossTestSetup ;
+
+/**
+ * Unit tests of probe.sh and probe.bat.
+ * 
+ * Requires testing against the all config.
+ * 
+ * There are a number of tests which need covering and their priority:
+ * (high) - that we get at least 4 responses (for the four channels in the AS) [DONE]
+ * (high) - that -match Tomcat-Cluster returns only one response (need isolation, need negative assertion) [DONE]
+ * (low)  - that -addr and -port when used in conjunction with server which has had 
+ * its diagnostics address and port changed returns exactly 4 replies
+ * 
+ * @author Richard Achmatowicz
+ * @version $Revision: $
+ */
+public class ProbeTestCase extends ScriptsTestBase
+{
+   /**
+    * Create a new ProbeTestCase.
+    * 
+    * @param name
+    */
+   public ProbeTestCase(String name)
+   {
+      super(name);      
+   }
+   
+   /**
+    * Prints out some basic info about the environment 
+    */
+   public void testExecutionEnvironment() {
+	   String os = isWindows() ? "Windows" : "non-Windows" ;
+	     
+	   // dump out some basic config information
+	   System.out.println("\nTesting probe on " + os + " host") ;
+	   System.out.println("Working directory: " + getBinDir()) ;
+	   System.out.println("Dist directory: " + getDistDir()) ;	   
+   }
+   
+   /**
+    * Tests probe "help" command 
+    *  
+    * @throws Exception
+    */
+   public void testNoArgs() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "probe" ;
+	   String options = null ;  
+	   String args = "-help" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("Probe [-help]","Usage string not found in command output") ;
+   }  
+
+   /**
+    * Tests probe receives a response for every channel in the AS 
+    *  
+    * @throws Exception
+    */
+   public void testResponseSet() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "probe" ;
+	   String options = null ;  
+	   String args = null ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("#4","Less than 4 channel responses found in command output") ;
+	   getShellScriptExecutor().assertOnOutputStream("DefaultPartition-SFSBCache","DefaultPartition-SFSBCache channel response not found in command output") ;
+	   getShellScriptExecutor().assertOnOutputStream("DefaultPartition-EntityCache","DefaultPartition-EntityCache channel response not found in command output") ;
+	   getShellScriptExecutor().assertOnOutputStream("DefaultPartition","DefaultPartition channel response not found in command output") ;
+	   getShellScriptExecutor().assertOnOutputStream("Tomcat-Cluster","Tomcat-Cluster channel response not found in command output") ;
+   }  
+   
+   
+   /**
+    * Tests probe -query jmx command (returns a list of JMX statistics for each protocol)
+    *  
+    * @throws Exception
+    */
+   public void testQueryJMX() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "probe" ;
+	   String options = null ;  
+	   String args = "-query jmx" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("stats:","'stats:' string not found in command output") ;
+   }  
+   
+   /**
+    * Tests probe -query props command (returns the stack used by each channel)
+    *  
+    * @throws Exception
+    */
+   public void testQueryProps() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "probe" ;
+	   String options = null ;  
+	   String args = "-query props" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("props:","'props:' string not found in command output") ;
+   }  
+   
+   /**
+    * Tests probe -match command (returns only responses containing the match text)
+    *  
+    * @throws Exception
+    */
+   public void testQueryMatch() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "probe" ;
+	   String options = null ;  
+	   String args = "-match Tomcat-Cluster" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   // need to check the absence of a string here!
+	   // assertNotOnOutputStream("Default-Partition", "'Default-Partition' found in match list")
+	   getShellScriptExecutor().assertOnOutputStream("Tomcat-Cluster","'Tomcat-Cluster' string not found in command output") ;
+   }  
+  
+   /* 
+    * one time setup mechamism
+    * only good for static stuff
+    *  
+   public static Test suite() throws Exception
+   {
+	   TestSuite suite = new TestSuite();
+	   suite.addTest(new TestSuite(TwiddleTestCase.class));
+	   
+	   JBossTestSetup setup = new JBossTestSetup(suite) {
+		   
+           protected void setUp() throws Exception {
+           }
+           
+           protected void tearDown() throws Exception {
+        	   
+           }
+	   } ;
+      return setup ;
+   }
+   */
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/RunTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/RunTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/RunTestCase.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,222 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009 Red Hat Middleware, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.scripts.test;
+
+import java.io.File ;
+import java.io.IOException ;
+import java.lang.InterruptedException ;
+import java.net.URL ;
+import java.net.MalformedURLException ;
+import javax.management.ObjectName ;
+import javax.management.MalformedObjectNameException ;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.test.JBossTestSetup ;
+
+/**
+ * Unit tests of run.sh and run.bat.
+ *
+ * Need to test the following features (in order of importance):
+ * 1. error-free statup on non-loopback bind address 
+ *    (-c <server> -b <non-loopback IP>)
+ * 2. error-free startup on loopback bind address 
+ *    (-c <server> without -b param)
+ * 3. default server assignment (i.e. production)
+ *    (-b <non-loopback IP>   
+ * 4. options for configuring partition, multicast address and port 
+ *    (-g <partition name> -u <mcast IP addr> -m <mcast port>)
+ * 5. options for configuring startup directories 
+ *    (-d <boot patch directory> -p <patch directory> -B <bootlib> -L <loader lib> -C <clapsspath lib>)
+ * 6. help and version text
+ *    (-h)
+ *    
+ * In order to avoid dependency on an untested shutdown.sh/shutdown.bat script, we start up run.sh/run.bat
+ * using the AsyncShellScriptExecutor and shut it down using JMX.    
+ * 
+ * This test case should not be run with a server started by Server/Servermanager/ServerController.
+ *    
+ * @author Richard Achmatowicz
+ * @version $Revision: $
+ */
+public class RunTestCase extends ScriptsTestBase
+{
+	private ObjectName SERVER_OBJ_NAME = null ;
+	private int START_TIMEOUT = 120 ;
+	private int STOP_TIMEOUT = 120 ;
+		
+   /**
+    * Create a new RunTestCase.
+    * 
+    * @param name
+    */
+   public RunTestCase(String name)
+   {
+      super(name);     
+      
+      // init the server ON
+      try {
+    	  SERVER_OBJ_NAME = new ObjectName("jboss.system:type=Server") ;
+      }
+      catch(MalformedObjectNameException mfe) {
+      }      
+   }
+   
+   
+   /**
+    * Prints out some basic info about the environment 
+    */
+   public void testExecutionEnvironment() {
+	   String os = isWindows() ? "Windows" : "non-Windows" ;
+	     
+	   // dump out some basic config information
+	   System.out.println("\nTesting run on " + os + " host") ;
+	   System.out.println("Working directory: " + getBinDir()) ;
+	   System.out.println("Dist directory: " + getDistDir()) ;	
+	   System.out.println("Log directory: " + getLogDir()) ;
+	   System.out.println("Server config: " + getServerConfig()) ;
+   }
+   
+   /**
+    * Tests run "help" command (no args)
+    *  
+    * @throws Exception
+    */
+   public void testNoArgs() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "run" ;
+	   String options = null ;  
+	   String args = "-h" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("usage: run","usage string not found in command output") ;
+   }  
+   
+   /**
+    * Tests run startup command
+    * 
+    * We check the following assertions in this test:
+    * A1. error free startup of server
+    * A2. bind address
+    * A3. multicast address 
+    * A4. ... 
+    *  
+    * @throws Exception
+    */
+   public void testNonLoopbackErrorFreeStartup() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "run" ;
+	   String options = " -c " + getServerConfig() + " -b " + getServerHost()   ;  
+	   String args = null ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // point to the server config we are going to use
+	   // System.setProperty("jbosstest.server.config", "default") ;
+	   
+	   // execute command
+	   getAsyncShellScriptExecutor().startShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // waitForServerStart kills the process and throws an exception if server does not start 
+	   try {
+		   ScriptsTestBase.waitForServerStart(getAsyncShellScriptExecutor(), getServerHost(), START_TIMEOUT) ;
+		   System.out.println("Server started successfully") ;
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeLogsToTestCase() ;
+		   
+		   fail("Server failed to start") ;
+	   }
+	   
+	   // check assertions on the console output generated by the run command
+	   getAsyncShellScriptExecutor().assertOnOutputStream("Started in","Started string not found in command output") ;
+	   
+	   // shutdown the server using JMX and the MBean server (jboss.system:type=Server
+	   System.out.println("Calling shutdown") ;
+	   getServer().invoke(SERVER_OBJ_NAME, "shutdown", new Object[0], new String[0]) ;
+	   
+	   // waitForServerStop kills the process and throws an exception if server does not stop 
+	   try {
+		   ScriptsTestBase.waitForServerStop(getAsyncShellScriptExecutor(), STOP_TIMEOUT) ;
+		   System.out.println("Server stopped successfully") ;
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeLogsToTestCase() ;
+		   
+		   fail("Server failed to stop") ;
+	   }
+   }  
+   
+   private void writeLogsToTestCase() {
+	   
+	   // write the logs to output for diagnosis
+	   System.out.println("============================== system.out ==============================") ;
+	   System.out.println(getAsyncShellScriptExecutor().getOutput()) ;
+	   System.out.println("============================== system.err ==============================") ;
+	   System.out.println(getAsyncShellScriptExecutor().getError()) ;
+	   System.out.println("========================================================================") ;	   
+   }
+   
+   /* 
+    * one time setup mechamism
+    * only good for static stuff
+    *  
+   public static Test suite() throws Exception
+   {
+	   TestSuite suite = new TestSuite();
+	   suite.addTest(new TestSuite(TwiddleTestCase.class));
+	   
+	   JBossTestSetup setup = new JBossTestSetup(suite) {
+		   
+           protected void setUp() throws Exception {
+           }
+           
+           protected void tearDown() throws Exception {
+        	   
+           }
+	   } ;
+      return setup ;
+   }
+   */
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ScriptsTestBase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ScriptsTestBase.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ScriptsTestBase.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,405 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.scripts.test;
+
+import java.lang.InterruptedException ;
+import java.io.OutputStream ;
+import java.io.ByteArrayOutputStream ;
+import java.io.BufferedReader ;
+import java.io.InputStreamReader ;
+import java.io.PrintWriter ;
+import java.io.StringWriter ;
+import java.io.FileReader ;
+import java.io.FileWriter ;
+import java.io.File ;
+import java.io.FileInputStream ;
+import java.io.FileOutputStream ;
+import java.io.FileNotFoundException ;
+import java.io.IOException ;
+
+import java.net.URL ;
+import java.net.MalformedURLException ;
+import java.net.URLConnection ;
+import java.net.HttpURLConnection ;
+
+import org.jboss.test.scripts.support.LogFileAssertionChecker ;
+import org.jboss.test.scripts.support.ShellScriptExecutor ;
+import org.jboss.test.scripts.support.AsyncShellScriptExecutor ;
+
+import org.jboss.test.JBossTestCase ;
+import junit.framework.Assert ;
+
+/**
+ * Base class to test command-line scripts.
+ * 
+ * @author Richard Achmatowicz
+ * @version $Revision: 1.0
+ */
+public abstract class ScriptsTestBase extends JBossTestCase
+{
+	public static final String SERVER_STARTED_MESSAGE = "Started in" ;
+	public static final String SERVER_STOPPED_MESSAGE = "Shutdown complete" ;
+	public static final String SERVER_HALT_MESSAGE = "Server halt" ;
+	public static final String SERVER_EXIT_MESSAGE = "Server exit" ;
+	public static final String SERVER_HALTED_MESSAGE = "halting the JVM now" ;	
+	
+	ShellScriptExecutor se = null ;
+	AsyncShellScriptExecutor ase = null ;
+	LogFileAssertionChecker errorLogChecker = null ;
+	LogFileAssertionChecker outputLogChecker = null ;
+	LogFileAssertionChecker bootLogChecker = null ;
+	LogFileAssertionChecker systemLogChecker = null ;
+	
+	public ScriptsTestBase(String name)
+	{
+		super(name);
+		
+		// initialise the script executors
+		se = new ShellScriptExecutor() ;
+		ase = new AsyncShellScriptExecutor() ;
+				
+		// initialise the log checkers (error checking here could be improved)
+		// these will be initialised to a single server instance, so we canb't change server instances
+		// part way through a test suite! :-(
+		String logDir = getLogDir() ;
+		errorLogChecker = new LogFileAssertionChecker(logDir + "/error.log") ;
+		outputLogChecker = new LogFileAssertionChecker(logDir + "/output.log") ;
+		bootLogChecker = new LogFileAssertionChecker(logDir + "/boot.log") ;
+		systemLogChecker = new LogFileAssertionChecker(logDir + "/system.log") ;
+	}
+
+	protected void setUp() throws Exception {
+		super.setUp();		
+		// setup AsyncShellScriptExecutor to deploy shutdown.sar 
+		ase.setUseShutdown(true) ;
+		ase.setPathToShutdownSar(getDeployURL("shutdown.sar").getPath()) ;
+		ase.setDeployDir(getDeployDir()) ;
+	}
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+	public ShellScriptExecutor getShellScriptExecutor() {
+		return se ;
+	}
+	public AsyncShellScriptExecutor getAsyncShellScriptExecutor() {
+		return ase ;
+	}
+	public LogFileAssertionChecker getOutputLogChecker() {
+		return outputLogChecker ;
+	}
+	public LogFileAssertionChecker getErrorLogChecker() {
+		return errorLogChecker ;
+	}
+	public LogFileAssertionChecker getBootLogChecker() {
+		return bootLogChecker ;
+	}
+	public LogFileAssertionChecker getSystemLogChecker() {
+		return systemLogChecker ;
+	}
+	
+	/* location helpers 
+	 * 
+	 * these really need to be improved to use JBossTestCase, but unfortunately
+	 * JBossTestCase does not give us direct access to the deploy directory
+	 * Here, i'm mimicking what they do
+	 */
+	public String getDistDir() {
+		String distDir = System.getProperty("jboss.dist") ;
+		if (distDir == null)
+			fail("Can't get the JBoss distribution directory") ;
+		return distDir ;
+	}
+	
+	/*
+	 * how to get the server directory?
+	 */
+	public String getServerConfig() {
+		String serverConfig = System.getProperty("jbosstest.server.config");
+	    if (serverConfig == null)
+	    {
+	       serverConfig = "default";
+	    }
+		return serverConfig ;
+	}
+	
+	public String getBinDir() {		
+		return getDistDir() + "/bin" ;
+	}
+	
+	public String getLogDir() {		
+		return getDistDir() + "/server/" + getServerConfig() + "/log" ;
+	}
+	
+	public String getDeployDir() {		
+		return getDistDir() + "/server/" + getServerConfig() + "/deploy" ;
+	}
+	
+	public boolean isWindows() {
+		String osName = System.getProperty("os.name") ;
+		if (osName == null)
+			fail("Can't get the operating system name") ;		
+		return (osName.indexOf("Windows") > -1) || (osName.indexOf("windows") > -1) ;
+	}
+	
+	/* 
+	 * method for constructing command lines for the shell executor, which
+	 * in general takes three arguments
+	 * String[] command, String[] envp, File workingDirectory
+	 * 
+	 * This command creates the first argument. 
+	 * 
+	 * Windows: three tokens need to be passed in String[] command
+	 * cmd /c <entire command string to execute>
+	 * cmd /c "twiddle.bat -s jnp://192.168.0.100 jsr77" 
+	 *  
+	 * UNIX: three tokens need to be passed in String[] command
+	 * bash -c <entire command string to execute>
+	 * bash -c "./twiddle.sh -s jnp://192.168.0.100 jsr77"
+	 * 
+	 * This arrangement may not be optimal ...
+	 */
+	public String[] getShellCommand(String commandName, String options, String args) {
+		
+		String[] shellCommand = new String[3] ;
+		String commandLine = null ;
+		
+		if (commandName == null)
+			fail("No command name specified for shell to execute") ;
+		
+		// set up the base command (platform specific)
+		if (isWindows()) {
+			shellCommand[0] = "cmd" ;
+			shellCommand[1] = "/c" ;
+			commandLine = commandName + ".bat" ;
+		}
+		else {
+			shellCommand[0] = "bash" ;
+			shellCommand[1] = "-c" ;
+			commandLine = "./" + commandName + ".sh" ;
+		}
+		// add in the rest (platform-independent)
+		if (options != null)
+			commandLine += " " + options ;
+		if (args != null)
+			commandLine += " " + args ;
+		
+		shellCommand[2] = commandLine ;
+		
+		return shellCommand ;
+	}
+	
+	/* assertion helpers */	
+	public void assertOnOutputLog(String string, String failureMessage, boolean useCheckpoint, boolean resetCheckpoint) {
+		if (!outputLogChecker.isStringInLog(string, useCheckpoint, resetCheckpoint)) {
+			// assertion does not hold
+			Assert.fail(failureMessage) ;
+		}
+	}
+	
+	public void assertOnErrorLog(String string, String failureMessage, boolean useCheckpoint, boolean resetCheckpoint) {
+		if (!errorLogChecker.isStringInLog(string, useCheckpoint, resetCheckpoint)) {
+			// assertion does not hold
+			Assert.fail(failureMessage) ;
+		}
+	}
+	
+	public void assertOnBootLog(String string, String failureMessage, boolean useCheckpoint, boolean resetCheckpoint) {
+		if (!bootLogChecker.isStringInLog(string, useCheckpoint, resetCheckpoint)) {
+			// assertion does not hold
+			Assert.fail(failureMessage) ;
+		}
+	}
+	
+	public void assertOnSystemLog(String string, String failureMessage, boolean useCheckpoint, boolean resetCheckpoint) {
+		if (!systemLogChecker.isStringInLog(string, useCheckpoint, resetCheckpoint)) {
+			// assertion does not hold
+			Assert.fail(failureMessage) ;
+		}
+	}		
+			
+	/* check if there is a Tomcat connection to the server */
+	private static boolean isServerStarted(String host) throws MalformedURLException {
+		// URL to Tomcat 
+		URL url = new URL("http", host, 8080, "/") ;
+		try {
+			URLConnection conn = url.openConnection() ;
+			if (conn instanceof HttpURLConnection) {
+				HttpURLConnection http = (HttpURLConnection) conn ;
+				int responseCode = http.getResponseCode();
+				
+				if (responseCode > 0 && responseCode < 400) {
+					return true ;
+				}
+			}
+		}
+		catch(IOException e) {
+			return false ;
+		}
+		return false ;
+	}
+	
+	/* 
+	* Wait for the server (started by the AsyncShellExecutor) to start
+	* 
+	* @throws Exception 	if server does not start successfully
+	*  
+	* A successful server start means: 
+	* (i) we can reach Tomcat 
+	* (ii) no exceptions in error log
+	* (iii) no ERROR statements in the server log
+	* If the server does not start successfully, we call joinShellCommand with a 1 second timout.
+	* This will wait for one second and then attempt to shutdown both the server and the bash shell,
+	* before throwing an exception. 
+	*   
+	* NOTE: this is a hack, and assumes the process has been started using the AsynchShellExecutor   
+	*/
+	protected static void waitForServerStart(AsyncShellScriptExecutor ase, String host, int timeout) throws IOException  {
+		boolean serverStarted = false ;
+		boolean logsExceptionFree = true ;
+		
+		int tries = 0 ;	
+		while (tries++ < timeout) {
+			if (!ase.isRunning()) {
+				throw new IOException("Server failed to start. See logs.") ;
+			}
+			// wait for a sec
+			sleepForSeconds(1) ;
+			
+			if (isServerStarted(host)) {
+				serverStarted = true ;
+				break ;
+			}
+		}		
+		
+		// problem here is that if another server is started:
+		// (i) the preceeding code will indicate serverStarted=true
+		// (iI) the following code will get executed before the starting server has had a chance to start 
+		// (and before exceptions are written).
+		// This results in two servers being started, one incompletely.
+		// So wait here for 5 seconds to allow the logs to accumulate exceptions.
+		sleepForSeconds(5) ;
+		
+		// check for startup errors in the server logs. We check both because:
+		// (i) log4j will write all CONSOLE appender logging to System.in only, and these
+		// may contain ERROR log entries corresponding to exceptions
+		// (ii) other exceptions in the AS should get written to System.err if not handled
+		// via log4j
+		if (ase.getOutput().indexOf("ERROR") > -1 || ase.getError().indexOf("Exception") > -1) {
+			logsExceptionFree = false ;
+		}
+		
+		// debugging
+		//System.out.println("Server started = " + serverStarted) ;
+		//System.out.println("logsExceptionFree = " + logsExceptionFree) ;
+		//System.out.println("output = " + ase.getOutput()) ;
+		//System.out.println("error = " + ase.getError()) ;
+		
+		// kill the server before going on if not correctly started 
+		if (!serverStarted || !logsExceptionFree) {
+			// kill process and close streams
+			ase.joinShellCommand(1) ;
+			
+			// now throw exception 
+			if (!serverStarted)
+				throw new IOException("Server failed to start: couldn't connect to Tomcat. See logs.") ;
+			else if (!logsExceptionFree) {
+				throw new IOException("Server failed to start: ERROR statements found. See logs.") ;				
+			}
+		}
+		// if we reach here, the server started and no ERRORs were found
+	}
+	
+	/* Wait for the server (started by the AsyncShellExecutor) to stop
+	* 
+	* @throws Exception 	if server does not stop successfully
+	*  
+	* A successful server start means: 
+	* (i) we see the "VM halted" message in the server log
+	* (ii) no ERROR statements in the server log
+	* If the server does not stop successfully, we call joinShellCommand with a 1 second timout.
+	* This will wait for one second and then attempt to shutdown both the server and the bash shell,
+	* before throwing an exception. 
+	*/
+	protected static void waitForServerStop(AsyncShellScriptExecutor ase, int timeout) throws IOException {
+		boolean serverStopped = false ;
+		boolean logsExceptionFree = true ;
+		boolean haltCalled = false ;
+
+		System.out.println("waitForServerStop: waiting " + timeout + " seconds") ;
+		
+		int tries = 0 ;
+		while (tries++ < timeout) {
+			if (!ase.isRunning()) {
+				// FIX-ME
+				throw new IOException("Server not running on shutdown. Something fishy") ;
+			}	
+			// check if stopped by inspecting console log
+			String currentOutput = ase.getOutput() ;
+			if (currentOutput.indexOf(SERVER_STOPPED_MESSAGE) > -1 || currentOutput.indexOf(SERVER_HALTED_MESSAGE) > -1) {
+				serverStopped = true ;
+			}
+			
+			// wait for a sec
+			sleepForSeconds(1) ;
+		}
+		
+		// Wait here for 5 seconds to allow the logs to accumulate.
+		sleepForSeconds(5) ;
+
+		// check for shutdown errors in the server logs. We check both because:
+		// (i) log4j will write all CONSOLE appender logging to System.in only, and these
+		// may contain ERROR log entries corresponding to exceptions
+		// (ii) other exceptions in the AS should get written to System.err if not handled
+		// via log4j
+		
+		// NOTE: when we halt, an ERROR log message is written so we have to be careful
+		// 
+		if (ase.getOutput().indexOf(SERVER_HALTED_MESSAGE) > -1)
+			haltCalled = true ;
+		
+		if (!haltCalled && (ase.getOutput().indexOf("ERROR") > -1 || ase.getError().indexOf("Exception") > -1)) {
+			logsExceptionFree = false ;
+		}
+		
+		// kill the server before going on if not correctly started 
+		if (!serverStopped || !logsExceptionFree) {
+			// kill process and close streams
+			ase.joinShellCommand(1) ;
+			
+			// now throw exception 
+			if (!serverStopped)
+				throw new IOException("Server failed to stop: didn't find message in logs. See logs.") ;
+			else if (!logsExceptionFree) {
+				throw new IOException("Server failed to stop: ERROR statements found. See logs.") ;				
+			}
+		}
+		// if we reach here, the server stopped and no ERRORs were found
+	}
+	
+	private static void sleepForSeconds(int seconds) {
+		try {
+			Thread.sleep(seconds * 1000) ;
+		}
+		catch(InterruptedException e) {
+		}			
+	}	
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ShutdownTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ShutdownTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/ShutdownTestCase.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,294 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009 Red Hat Middleware, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.scripts.test;
+
+import java.io.File ;
+import java.io.IOException ;
+import java.lang.InterruptedException ;
+import java.net.URL ;
+import java.net.MalformedURLException ;
+import javax.management.ObjectName ;
+import javax.management.MalformedObjectNameException ;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.test.JBossTestSetup ;
+
+/**
+ * Unit tests of shutdown.sh and shutdown.bat.
+ *
+ * Need to test the following features (in order of importance):
+ * 1. error-free statup on non-loopback bind address 
+ *    (-c <server> -b <non-loopback IP>)
+ * 2. error-free startup on loopback bind address 
+ *    (-c <server> without -b param)
+ * 3. default server assignment (i.e. production)
+ *    (-b <non-loopback IP>   
+ * 4. options for configuring partition, multicast address and port 
+ *    (-g <partition name> -u <mcast IP addr> -m <mcast port>)
+ * 5. options for configuring startup directories 
+ *    (-d <boot patch directory> -p <patch directory> -B <bootlib> -L <loader lib> -C <clapsspath lib>)
+ * 6. help and version text
+ *    (-h)
+ *        
+ * @author Richard Achmatowicz
+ * @version $Revision: $
+ */
+public class ShutdownTestCase extends ScriptsTestBase
+{
+	private ObjectName SERVER_OBJ_NAME = null ;
+	private int START_TIMEOUT = 120 ;
+	private int STOP_TIMEOUT = 120 ;
+		
+   /**
+    * Create a new ShutdownTestCase.
+    * 
+    * @param name
+    */
+   public ShutdownTestCase(String name)
+   {
+      super(name);     
+      
+      // init the server ON
+      try {
+    	  SERVER_OBJ_NAME = new ObjectName("jboss.system:type=Server") ;
+      }
+      catch(MalformedObjectNameException mfe) {
+      }      
+   }
+   
+   
+   /**
+    * Prints out some basic info about the environment 
+    */
+   public void testExecutionEnvironment() {
+	   String os = isWindows() ? "Windows" : "non-Windows" ;
+	   // dump out some basic config information
+	   System.out.println("\nTesting run on " + os + " host") ;
+	   System.out.println("Working directory: " + getBinDir()) ;
+	   System.out.println("Dist directory: " + getDistDir()) ;	
+	   System.out.println("Log directory: " + getLogDir()) ;
+	   System.out.println("Server config: " + getServerConfig()) ;
+   }
+   
+   /**
+    * Tests run "help" command (no args)
+    *  
+    * @throws Exception
+    */
+   public void testNoArgs() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String[] shellCommand = getShellCommand("shutdown", null, "-h") ;
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("usage: shutdown","usage string not found in command output") ;
+   }  
+   
+   /**
+    * Tests shutdown command with -S option
+    * 
+    * @throws Exception
+    */
+   public void testNonLoopbackShutdown() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String[] shellCommand = getShellCommand("run","-c " + getServerConfig() + " -b " + getServerHost(), null) ; 
+	   String[] envp = null ;
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getAsyncShellScriptExecutor().startShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // waitForServerStart kills the process and throws an exception if server does not start 
+	   try {
+		   ScriptsTestBase.waitForServerStart(getAsyncShellScriptExecutor(), getServerHost(), START_TIMEOUT) ;
+		   System.out.println("Server started successfully") ;
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeServerLogsToTestCase() ;
+		   fail("Server failed to start") ;
+	   }
+	   
+	   // check assertions on the console output generated by the run command
+	   getAsyncShellScriptExecutor().assertOnOutputStream("Started in","Started string not found in command output") ;
+	   
+	   // shutdown the server using the shutdown command
+	   String[] shutdownCommand = getShellCommand("shutdown", "-s " + getJndiURL() + " -S", null) ;
+	   getShellScriptExecutor().runShellCommand(shutdownCommand, envp, workingDir) ;
+	   
+	   System.out.println("shutdown output = " + getShellScriptExecutor().getOutput()) ;
+	   System.out.println("shutdown error = " + getShellScriptExecutor().getError()) ;
+	   
+	   // waitForServerStop kills the process and throws an exception if server does not stop 
+	   try {
+		   ScriptsTestBase.waitForServerStop(getAsyncShellScriptExecutor(), STOP_TIMEOUT) ;
+		   System.out.println("Server stopped successfully") ;
+		   getAsyncShellScriptExecutor().assertOnOutputStream(SERVER_STOPPED_MESSAGE,"Server shutdown message did not appear in logs") ;
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeServerLogsToTestCase() ; 
+		   fail("Server failed to stop") ;
+	   }
+   }  
+
+   /**
+    * Tests shutdown command with -e option
+    * 
+    * @throws Exception
+    */
+   public void testNonLoopbackExit() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String[] shellCommand = getShellCommand("run","-c " + getServerConfig() + " -b " + getServerHost(), null) ; 
+	   String[] envp = null ;
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getAsyncShellScriptExecutor().startShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // waitForServerStart kills the process and throws an exception if server does not start 
+	   try {
+		   ScriptsTestBase.waitForServerStart(getAsyncShellScriptExecutor(), getServerHost(), START_TIMEOUT) ;
+		   System.out.println("Server started successfully") ;
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeServerLogsToTestCase() ;
+		   fail("Server failed to start") ;
+	   }
+	   
+	   // check assertions on the console output generated by the run command
+	   getAsyncShellScriptExecutor().assertOnOutputStream("Started in","Started string not found in command output") ;
+	   
+	   // shutdown the server using the shutdown command
+	   String[] shutdownCommand = getShellCommand("shutdown", "-s " + getJndiURL() + " -e 1", null) ;
+	   getShellScriptExecutor().runShellCommand(shutdownCommand, envp, workingDir) ;
+	   
+	   System.out.println("shutdown output = " + getShellScriptExecutor().getOutput()) ;
+	   System.out.println("shutdown error = " + getShellScriptExecutor().getError()) ;
+	   
+	   // waitForServerStop kills the process and throws an exception if server does not stop 
+	   try {
+		   ScriptsTestBase.waitForServerStop(getAsyncShellScriptExecutor(), STOP_TIMEOUT) ;
+		   System.out.println("Server stopped successfully") ;
+		   getAsyncShellScriptExecutor().assertOnOutputStream(SERVER_EXIT_MESSAGE,"Server exit message did not appear in logs") ;		   
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeServerLogsToTestCase() ;
+		   fail("Server failed to stop") ;
+	   }
+   }  
+   
+   /**
+    * Tests shutdown command with -H option
+    * 
+    * @throws Exception
+    */
+   public void testNonLoopbackHalt() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String[] shellCommand = getShellCommand("run","-c " + getServerConfig() + " -b " + getServerHost(), null) ; 
+	   String[] envp = null ;
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getAsyncShellScriptExecutor().startShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // waitForServerStart kills the process and throws an exception if server does not start 
+	   try {
+		   ScriptsTestBase.waitForServerStart(getAsyncShellScriptExecutor(), getServerHost(), START_TIMEOUT) ;
+		   System.out.println("Server started successfully") ;
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeServerLogsToTestCase() ;	   
+		   fail("Server failed to start") ;
+	   }
+	   
+	   // check assertions on the console output generated by the run command
+	   getAsyncShellScriptExecutor().assertOnOutputStream("Started in","Started string not found in command output") ;
+	   
+	   // shutdown the server using the shutdown command
+	   String[] shutdownCommand = getShellCommand("shutdown", "-s " + getJndiURL() + " -H 1", null) ;
+	   getShellScriptExecutor().runShellCommand(shutdownCommand, envp, workingDir) ;
+	   
+	   // waitForServerStop kills the process and throws an exception if server does not stop 
+	   try {
+		   ScriptsTestBase.waitForServerStop(getAsyncShellScriptExecutor(), STOP_TIMEOUT) ;
+		   System.out.println("Server stopped successfully") ;
+		   getAsyncShellScriptExecutor().assertOnOutputStream(SERVER_HALTED_MESSAGE,"Server halted message did not appear in logs") ;		   
+	   }
+	   catch(IOException e) {
+		   System.out.println("IOException: message = " + e.getMessage()) ;
+		   writeServerLogsToTestCase() ;
+		   fail("Server failed to stop") ;
+	   }
+   }  
+   
+   public void writeServerLogsToTestCase() {
+	   // write the logs to output for diagnosis
+	   System.out.println("============================== system.out ==============================") ;
+	   System.out.println(getAsyncShellScriptExecutor().getOutput()) ;
+	   System.out.println("============================== system.err ==============================") ;
+	   System.out.println(getAsyncShellScriptExecutor().getError()) ;
+	   System.out.println("========================================================================") ;	   
+   }
+   /* 
+    * one time setup mechamism
+    * only good for static stuff
+    *  
+   public static Test suite() throws Exception
+   {
+	   TestSuite suite = new TestSuite();
+	   suite.addTest(new TestSuite(TwiddleTestCase.class));
+	   
+	   JBossTestSetup setup = new JBossTestSetup(suite) {
+		   
+           protected void setUp() throws Exception {
+           }
+           
+           protected void tearDown() throws Exception {
+        	   
+           }
+	   } ;
+      return setup ;
+   }
+   */
+}

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/TwiddleTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/TwiddleTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/scripts/test/TwiddleTestCase.java	2010-05-07 16:27:21 UTC (rev 104566)
@@ -0,0 +1,336 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009 Red Hat Middleware, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.scripts.test;
+
+import java.io.File ;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.jboss.test.JBossTestSetup ;
+
+/**
+ * Unit tests of twiddle.sh and twiddle.bat.
+ *
+ * @author Richard Achmatowicz
+ * @version $Revision: $
+ */
+public class TwiddleTestCase extends ScriptsTestBase
+{
+   /**
+    * Create a new TwiddleTestCase.
+    * 
+    * @param name
+    */
+   public TwiddleTestCase(String name)
+   {
+      super(name);      
+   }
+   
+   /**
+    * Prints out some basic info about the environment 
+    */
+   public void testExecutionEnvironment() {
+	   String os = isWindows() ? "Windows" : "non-Windows" ;
+	     
+	   // dump out some basic config information
+	   System.out.println("\nTesting twiddle on " + os + " host") ;
+	   System.out.println("Working directory: " + getBinDir()) ;
+	   System.out.println("Dist directory: " + getDistDir()) ;	   
+   }
+   
+   /**
+    * Tests twiddle "help" command (no args)
+    *  
+    * @throws Exception
+    */
+   public void testNoArgs() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = null ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // System.out.println("Output: " + getShellScriptExecutor().getOutput()) ;
+	   // System.out.println("Error: " + getShellScriptExecutor().getError()) ;
+	   
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("usage: twiddle","usage string not found in command output") ;
+   }  
+   
+   /**
+    * Tests twiddle "jsr77" command
+    *  
+    * @throws Exception
+    */
+   public void testJSR77() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "jsr77" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+	   
+	   // check assertions
+	   // need to check that there are no errors in error log too! 
+	   getShellScriptExecutor().assertOnOutputStream("J2EEDomain","J2EEDomain string not found in output") ;
+   }  
+
+   /**
+    * Tests twiddle "xmbean" command (display xmbean descriptor for mbean)
+    *  
+    * @throws Exception
+    */
+   public void testXMbean() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "xmbean jboss.system:type=Server" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("jboss.system:type=Server","ObjectName string not found in output") ;
+   }   
+   
+   /**
+    * Tests twiddle "info" command (display attributes and operations for mbean)
+    *  
+    * @throws Exception
+    */
+   public void testInfo() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "info jboss.system:type=Server" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("Version","attribute 'Version' not found in output") ;
+	   getShellScriptExecutor().assertOnOutputStream("void shutdown()","operation 'shutdown' not found in output") ;
+   }   
+   
+   /**
+    * Tests twiddle "get" command (gets an MBean attribute)
+    *  
+    * @throws Exception
+    */
+   public void testGet() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "get jboss.system:type=Server Started" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("true","attribute value 'true' not found in output") ;
+   }   
+   
+   /**
+    * Tests twiddle "invoke" command (invoke an operation on an MBean)
+    *  
+    * @throws Exception
+    */
+   public void testInvoke() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "invoke jboss:service=JNDIView list true" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("Global JNDI Namespace","category 'Global JNDI Namepspace' not found in output") ;
+   }   
+   
+   /**
+    * Tests twiddle "create" command (create an MBean)
+    *  
+    * @throws Exception
+    * 
+    */
+   public void testCreate() throws Exception
+   {
+	   System.out.println("Help: Please implement me!") ;
+   }   
+   
+   /**
+    * Tests twiddle "setattrs" command (set the values of an MBean attribute)
+    *  
+    * @throws Exception
+    */
+   public void testSetattrs() throws Exception
+   {
+	   System.out.println("Help: Please implement me!") ;
+   }   
+   
+   /**
+    * Tests twiddle "unregister" command (unregister an MBean)
+    *  
+    * @throws Exception
+    */
+   public void testUnregister() throws Exception
+   {
+	   System.out.println("Help: Please implement me!") ;
+   }   
+  
+   /**
+    * Tests twiddle "query" command (query the server for a list of matching MBeans)
+    *  
+    * @throws Exception
+    */
+   public void testQuery() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "query 'jboss.system:*'" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("jboss.system:type=ServerInfo","MBean 'jboss.system:type=ServerInfo' not found in output") ;
+   }   
+   
+   /**
+    * Tests twiddle "set" command (set the value of an MBean attribute)
+    *  
+    * @throws Exception
+    */
+   public void testSet() throws Exception
+   {
+	   System.out.println("Help: Please implement me!") ;
+   }   
+   
+   /**
+    * Tests twiddle "serverinfo" command (get information about the MBean server)
+    *  
+    * @throws Exception
+    */
+   public void testServerInfo() throws Exception
+   {
+	   // build the shell command to execute
+	   // supply the command name prefix, any options as a string, and any args
+	   String command = "twiddle" ;
+	   String options = "-s " + getJndiURL() ;  
+	   String args = "serverinfo -l" ;
+	   String[] shellCommand = getShellCommand(command, options, args) ;
+	   
+	   // set the environment if necessary 
+	   String[] envp = null ;
+	   // set the working directory
+	   File workingDir = new File(getBinDir()) ;
+
+	   // execute command
+	   getShellScriptExecutor().runShellCommand(shellCommand, envp, workingDir) ; 
+
+	   // check assertions
+	   getShellScriptExecutor().assertOnOutputStream("jboss.system:type=Server","MBean 'jboss.system:type=Server' not found in output") ;
+   }   
+
+   /* 
+    * one time setup mechamism
+    * only good for static stuff
+    *  
+   public static Test suite() throws Exception
+   {
+	   TestSuite suite = new TestSuite();
+	   suite.addTest(new TestSuite(TwiddleTestCase.class));
+	   
+	   JBossTestSetup setup = new JBossTestSetup(suite) {
+		   
+           protected void setUp() throws Exception {
+           }
+           
+           protected void tearDown() throws Exception {
+        	   
+           }
+	   } ;
+      return setup ;
+   }
+   */
+}




More information about the jboss-cvs-commits mailing list