org.ourgrid.test
Class TestUtils

java.lang.Object
  extended by org.ourgrid.test.TestUtils

public class TestUtils
extends java.lang.Object

This class provides several methods to help during the test/development phase of the software. It eases the customization of the unit tests.


Field Summary
static java.lang.String CORE_PEER_COMMAND
           
static java.lang.String COREPEER_PORT
           
static java.lang.String FAKE_FILE
           
static java.lang.String FAKE_MACHINE_NAME
           
static java.lang.String FAKE_PORT
           
static java.lang.String GUI_PORT
           
static java.lang.String INVALID_TRUSTSTORE_FILENAME
           
static java.lang.String INVALID_TRUSTSTORE_PASSWORD
           
static java.lang.String KEYSTORE_FILENAME
           
static java.lang.String KEYSTORE_PASSWORD
           
static java.lang.String MG_HOMEMACHINE
           
static java.lang.String MG_PORT
           
static java.lang.String MYGRID_COMMAND
           
static java.lang.String MYGUMP_DEFAULT_COPYFROM
           
static java.lang.String MYGUMP_DEFAULT_COPYTO
           
static java.lang.String MYGUMP_DEFAULT_PLAYPENROOT
           
static java.lang.String MYGUMP_DEFAULT_PORT
           
static java.lang.String MYGUMP_DEFAULT_REMEXEC
           
static java.lang.String MYGUMP_DEFAULT_STORAGEDIR
           
static java.lang.String MYGUMP_MACHINE
           
static java.lang.String NONEXISTENT_MACHINE
           
static java.lang.String NOT_WRITABLE_FILE
           
static java.lang.String OG_PORT
           
static java.lang.String OG_PORT_II
           
static java.lang.String PEER_COMMAND
           
static java.lang.String PROTECTED_DIR
           
static java.lang.String REMOTE_FAKE_FILE
           
static java.lang.String REMOTE_FILE
           
static java.lang.String REMOTE_PROTECTED_DIR
           
static java.lang.String REMOTE_PROTECTED_FILE
           
static java.lang.String REMOTE_TEMP_DIR
           
static java.lang.String RMI_PORT
           
static java.lang.String SYSTEM_TEMP_DIR
           
static java.lang.String TRUSTSTORE_FILENAME
           
static java.lang.String TRUSTSTORE_PASSWORD
           
static java.lang.String TYPE_LOCALHOST
           
static java.lang.String TYPE_SWAN
           
static java.lang.String TYPE_UALINUX
           
static java.lang.String TYPE_UAWINDOWS
           
 
Constructor Summary
TestUtils()
           
 
Method Summary
 boolean checkFileContent(java.lang.String expectedContent, java.io.File file)
           
 void createCorepeerProperties()
          Creates an corepeer.properties file in the getCorepeerPropertiesFileName() location.
 java.lang.String createLocalPeerGDF()
           
 void createMGProperties()
          Creates a MG.properties file in the getMGPropertiesFileName() location.
 void createOGProperties()
          Creates an peer.properties file in the getOGPropertiesFileName() location.
 java.lang.String createSDF(java.util.List guMSpecs)
          Generates a GDF and returns the full path to it.
static void executeCommand(java.lang.String command, java.lang.String[] args)
          Executes a command with its arguments.
 java.lang.String getCorepeerPropertiesFileName()
          Returns the path to the corepeer.properties file.
 java.util.List<GumSpec> getGumSpecs(int numberOfGums, java.lang.String type)
          Returns a List containing GuMSpecs that were defined as usable in the test.properties file.
 GumSpec getLocalGuMSpec(java.lang.String type)
          Generates a GuMSpec for LocalMachine.
 java.lang.String getMGPropertiesFileName()
          Returns the path to the MG.properties file.
 int getNumberOfGuMSpecsAvailable(java.lang.String type)
          Returns the number of GuMSpecs available according to the test.properties file.
 java.lang.String getOGPropertiesFileName()
          Returns the path to the peer.properties file.
 java.lang.String getProperty(java.lang.String propertyKey)
          Returns the property specified.
 int getRMIPort()
           
 JobSpec getSimpleJobSpec()
           
 int guiPort()
           
 void load()
          Loads the tests properties from the default file.
 void load(java.lang.String fileName)
          Loads the tests properties from the specified file.
 void reset()
          Resets all data.
 void restartMygrid()
           
static void runCommand(java.lang.String[] commands, long timeWaiting)
          Runs a command.
 void setProperty(java.lang.String propertyKey, java.lang.String propertyValue)
          Sets a property.
 void stopMygrid()
           
 boolean testUA(java.util.List GuMSpecsList)
          Tests if all UA in a GUM are alive.
 boolean testUA(java.util.List GuMSpecsList, long timeout)
          Tests if all UA in a GUM are alive.
 void waitUntilMyGridIsDown()
          Wait until mygrid is down with a busy-wait call.
 void waitUntilMyGridIsUp()
          Wait until mygrid is up with a busy-wait call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONEXISTENT_MACHINE

public static final java.lang.String NONEXISTENT_MACHINE
See Also:
Constant Field Values

SYSTEM_TEMP_DIR

public static final java.lang.String SYSTEM_TEMP_DIR
See Also:
Constant Field Values

MG_HOMEMACHINE

public static final java.lang.String MG_HOMEMACHINE
See Also:
Constant Field Values

MG_PORT

public static final java.lang.String MG_PORT
See Also:
Constant Field Values

MYGUMP_MACHINE

public static final java.lang.String MYGUMP_MACHINE
See Also:
Constant Field Values

KEYSTORE_FILENAME

public static final java.lang.String KEYSTORE_FILENAME
See Also:
Constant Field Values

KEYSTORE_PASSWORD

public static final java.lang.String KEYSTORE_PASSWORD
See Also:
Constant Field Values

TYPE_UALINUX

public static final java.lang.String TYPE_UALINUX
See Also:
Constant Field Values

TYPE_UAWINDOWS

public static final java.lang.String TYPE_UAWINDOWS
See Also:
Constant Field Values

TYPE_SWAN

public static final java.lang.String TYPE_SWAN
See Also:
Constant Field Values

TYPE_LOCALHOST

public static final java.lang.String TYPE_LOCALHOST
See Also:
Constant Field Values

MYGUMP_DEFAULT_PLAYPENROOT

public static final java.lang.String MYGUMP_DEFAULT_PLAYPENROOT
See Also:
Constant Field Values

MYGUMP_DEFAULT_PORT

public static final java.lang.String MYGUMP_DEFAULT_PORT
See Also:
Constant Field Values

TRUSTSTORE_FILENAME

public static final java.lang.String TRUSTSTORE_FILENAME
See Also:
Constant Field Values

TRUSTSTORE_PASSWORD

public static final java.lang.String TRUSTSTORE_PASSWORD
See Also:
Constant Field Values

INVALID_TRUSTSTORE_FILENAME

public static final java.lang.String INVALID_TRUSTSTORE_FILENAME
See Also:
Constant Field Values

INVALID_TRUSTSTORE_PASSWORD

public static final java.lang.String INVALID_TRUSTSTORE_PASSWORD
See Also:
Constant Field Values

MYGUMP_DEFAULT_STORAGEDIR

public static final java.lang.String MYGUMP_DEFAULT_STORAGEDIR
See Also:
Constant Field Values

MYGUMP_DEFAULT_REMEXEC

public static final java.lang.String MYGUMP_DEFAULT_REMEXEC
See Also:
Constant Field Values

MYGUMP_DEFAULT_COPYFROM

public static final java.lang.String MYGUMP_DEFAULT_COPYFROM
See Also:
Constant Field Values

MYGUMP_DEFAULT_COPYTO

public static final java.lang.String MYGUMP_DEFAULT_COPYTO
See Also:
Constant Field Values

OG_PORT

public static final java.lang.String OG_PORT
See Also:
Constant Field Values

OG_PORT_II

public static final java.lang.String OG_PORT_II
See Also:
Constant Field Values

RMI_PORT

public static final java.lang.String RMI_PORT
See Also:
Constant Field Values

GUI_PORT

public static final java.lang.String GUI_PORT
See Also:
Constant Field Values

FAKE_PORT

public static final java.lang.String FAKE_PORT
See Also:
Constant Field Values

FAKE_MACHINE_NAME

public static final java.lang.String FAKE_MACHINE_NAME
See Also:
Constant Field Values

FAKE_FILE

public static final java.lang.String FAKE_FILE
See Also:
Constant Field Values

NOT_WRITABLE_FILE

public static final java.lang.String NOT_WRITABLE_FILE
See Also:
Constant Field Values

REMOTE_PROTECTED_FILE

public static final java.lang.String REMOTE_PROTECTED_FILE
See Also:
Constant Field Values

REMOTE_FAKE_FILE

public static final java.lang.String REMOTE_FAKE_FILE
See Also:
Constant Field Values

REMOTE_TEMP_DIR

public static final java.lang.String REMOTE_TEMP_DIR
See Also:
Constant Field Values

PROTECTED_DIR

public static final java.lang.String PROTECTED_DIR
See Also:
Constant Field Values

REMOTE_PROTECTED_DIR

public static final java.lang.String REMOTE_PROTECTED_DIR
See Also:
Constant Field Values

REMOTE_FILE

public static final java.lang.String REMOTE_FILE
See Also:
Constant Field Values

MYGRID_COMMAND

public static final java.lang.String MYGRID_COMMAND

PEER_COMMAND

public static final java.lang.String PEER_COMMAND

CORE_PEER_COMMAND

public static final java.lang.String CORE_PEER_COMMAND

COREPEER_PORT

public static final java.lang.String COREPEER_PORT
See Also:
Constant Field Values
Constructor Detail

TestUtils

public TestUtils()
Method Detail

load

public void load()
Loads the tests properties from the default file.


load

public void load(java.lang.String fileName)
Loads the tests properties from the specified file.

Parameters:
fileName - The file name.

reset

public void reset()
Resets all data.


getProperty

public java.lang.String getProperty(java.lang.String propertyKey)
Returns the property specified.

Parameters:
propertyKey - The property key.
Returns:
Returns the property value or null case the property was not previously specified.

setProperty

public void setProperty(java.lang.String propertyKey,
                        java.lang.String propertyValue)
Sets a property.

Parameters:
propertyKey - The property key.
propertyValue - The property value.

getGumSpecs

public java.util.List<GumSpec> getGumSpecs(int numberOfGums,
                                           java.lang.String type)
                                    throws NotEnoughGumSpecsException
Returns a List containing GuMSpecs that were defined as usable in the test.properties file.

Parameters:
numberOfGums - The number of GuMSpecs desired.
type - The type of the GuMSpecs (if they will be UALinux, UAWindows, etc.)
Returns:
A List of GuMSpecs.
Throws:
NotEnoughGumSpecsException - Case the number of GuMSpecs available is less than the number of GuMSpecs required.

testUA

public boolean testUA(java.util.List GuMSpecsList)
Tests if all UA in a GUM are alive. It does it only once.

Parameters:
GuMSpecsList - List of GuMs
Returns:

testUA

public boolean testUA(java.util.List GuMSpecsList,
                      long timeout)
Tests if all UA in a GUM are alive. It does it only timeout milisecs.

Parameters:
GuMSpecsList - List of GuMs
Returns:

getLocalGuMSpec

public GumSpec getLocalGuMSpec(java.lang.String type)
Generates a GuMSpec for LocalMachine.

Parameters:
type - The GuM type.
Returns:
GuMSpec of the localmachine.

getNumberOfGuMSpecsAvailable

public int getNumberOfGuMSpecsAvailable(java.lang.String type)
Returns the number of GuMSpecs available according to the test.properties file.

Parameters:
type - The type of the GuMSpecs.
Returns:
The number of GuMSpecs available from the type specified.

createSDF

public java.lang.String createSDF(java.util.List guMSpecs)
                           throws java.io.IOException
Generates a GDF and returns the full path to it.

Parameters:
guMSpecs - A list of GuMSpecs that will compose the Grid Description File.
Returns:
The full path to the GDF created.
Throws:
java.io.IOException - Case file cannot be created (disk full or wrong setted temp directory)

getMGPropertiesFileName

public java.lang.String getMGPropertiesFileName()
Returns the path to the MG.properties file.

Returns:
A String containing the path to the MG.properties file.

createMGProperties

public void createMGProperties()
Creates a MG.properties file in the getMGPropertiesFileName() location. It will backup the old MG.properties file to be restored when this.reset() is invoked.


getOGPropertiesFileName

public java.lang.String getOGPropertiesFileName()
Returns the path to the peer.properties file.

Returns:
A String containing the path to the peer.properties file.

createOGProperties

public void createOGProperties()
Creates an peer.properties file in the getOGPropertiesFileName() location. It will backup the old peer.properties file to be restored when this.reset() is invoked.


getCorepeerPropertiesFileName

public java.lang.String getCorepeerPropertiesFileName()
Returns the path to the corepeer.properties file.

Returns:
A String containing the path to the peer.properties file.

createCorepeerProperties

public void createCorepeerProperties()
Creates an corepeer.properties file in the getCorepeerPropertiesFileName() location. It will backup the old corepeer.properties file to be restored when this.reset() is invoked.


createLocalPeerGDF

public java.lang.String createLocalPeerGDF()
                                    throws java.io.IOException
Throws:
java.io.IOException

runCommand

public static void runCommand(java.lang.String[] commands,
                              long timeWaiting)
                       throws java.lang.Exception
Runs a command.

Parameters:
commands - The command.
timeWaiting - The time to sleep after the command was performed - not recommended to use.
Throws:
java.lang.Exception - Case there's any problem.

checkFileContent

public boolean checkFileContent(java.lang.String expectedContent,
                                java.io.File file)
                         throws java.lang.Exception
Throws:
java.lang.Exception

executeCommand

public static void executeCommand(java.lang.String command,
                                  java.lang.String[] args)
                           throws java.lang.Exception
Executes a command with its arguments.

Parameters:
command - The command to be executed.
args - Its arguments.
Throws:
java.lang.Exception - Case the command cannot be executed.

waitUntilMyGridIsUp

public void waitUntilMyGridIsUp()
Wait until mygrid is up with a busy-wait call.


waitUntilMyGridIsDown

public void waitUntilMyGridIsDown()
Wait until mygrid is down with a busy-wait call.


getSimpleJobSpec

public JobSpec getSimpleJobSpec()
                         throws CompilerException
Throws:
CompilerException

restartMygrid

public void restartMygrid()
                   throws java.lang.Exception
Throws:
java.lang.Exception

stopMygrid

public void stopMygrid()
                throws java.lang.Exception
Throws:
java.lang.Exception

getRMIPort

public int getRMIPort()

guiPort

public int guiPort()