/*
* Name: ExecutableCommandTest
* Author: Richard Rodger
*
* Copyright (c) 2003 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
// package
package org.jostraca.util.test;
// import
import org.jostraca.util.ExecutableCommand;
import org.jostraca.util.RecordingUserMessageHandler;
import org.jostraca.util.UserMessageHandler;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/** Test cases for BuildResource
*/
public class ExecutableCommandTest extends TestCase {
// test framework
public ExecutableCommandTest( String pName ) {
super( pName );
}
public static TestSuite suite() {
return new TestSuite( ExecutableCommandTest.class );
}
public static void main( String[] pArgs ) {
TestRunner.run( suite() );
}
// public methods
// REVIEW: need to use RecordingUserMessageHandler to verify test
public void testExecute() throws Exception {
String args = "/c echo %JAVA_HOME%";
ExecutableCommand ec = new ExecutableCommand( "badcmd", args );
final RecordingUserMessageHandler rumh = new RecordingUserMessageHandler();
ec.setUserMessageHandler( rumh );
ec.setActivityDescription("Activity:");
boolean outcome = ec.execute( new ExecutableCommand.AlternativeExecutableCommands
(
new ExecutableCommand( "badcmd2", args ),
new ExecutableCommand( "", args ) {
public boolean execute( ExecutableCommand pParent ) {
iCmdPrefix = "badcmd3";
return super.execute();
}
},
new ExecutableCommand() {
public boolean execute( ExecutableCommand pParent ) {
ExecutableCommand sec = new ExecutableCommand( "subcmd1", "r", "s", this );
sec.setUserMessageHandler( rumh );
return sec.execute( new ExecutableCommand.AlternativeExecutableCommands
(
new ExecutableCommand( "subcmd2", sec.getCmdRoot(), sec.getCmdSuffix() ),
new ExecutableCommand( "subcmd3", sec.getCmdRoot(), sec.getCmdSuffix() ),
new ExecutableCommand( "cmd", pParent.getCmdRoot() )
) );
}
}
) );
assertEquals( ("DEBUG: Unable to execute commmand: badcmd /c echo %JAVA_HOME% \n"+
"\n"+
"DEBUG: Trying alternative commands...\n"+
"DEBUG: Unable to execute commmand: badcmd2 /c echo %JAVA_HOME% \n"+
"\n"+
"DEBUG: Unable to execute commmand: badcmd3 /c echo %JAVA_HOME% \n"+
"\n"+
"DEBUG: Unable to execute commmand: subcmd1 r s\n"+
"\n"+
"DEBUG: Trying alternative commands...\n"+
"DEBUG: Unable to execute commmand: subcmd2 r s\n"+
"\n"+
"DEBUG: Unable to execute commmand: subcmd3 r s\n"+
"\n"+
"DEBUG: Activity: cmd /c echo %JAVA_HOME%\n"
),
rumh.toString( UserMessageHandler.DEBUG ) );
assertTrue( outcome );
}
}