Previous Topic: Custom Java Test StepsNext Topic: Deploy a Custom Java Test Step


Create a Custom Java Test Step

Follow these steps:

  1. Create a Java class that implements com.itko.lisa.test.CustJavaNodeInterface (in

    lisa-core-8.0.0.jar).

    This tells the DevTest Solutions that your class is a custom Java test step.

    public class FTPCustJavaNode implements CustJavaNodeInterface
    {
     
    }
    
  2. Implement the required initialize method.

    This method is called when the DevTest first loads a custom test step during testing.

    In this example, the test step needs no initialization, so it simply logs the fact that the initialize method was called.

    static protected Log cat = LogFactory.getLog( "com.mycompany.lisa.ext.node.FTPCustJavaNode" );
     
    public void initialize( TestCase test, Element node ) throws TestDefException
    {
        cat.debug( "called initialize" );
    }
    
  3. Implement the required getParameters method.

    This method specifies the name-value pairs that define the parameters to the custom test step. The simplest way to define the parameter list is to pass one long string of all parameters, with each parameter separated by an ampersand (&). Values that are specified here are used as the default values when the node is defined in the model editor.

    public ParameterList getParameters()
    {
        ParameterList pl = new ParameterList( "username=&password=&host=ftp.suse.com&path=/pub&file=INDEX" );
        return pl;
    }
    

    The previous example uses ftp.suse.com/pub/INDEX as the file to retrieve. This is a publicly available FTP host that allows an anonymous login. Limit unnecessary hits on the SuSE FTP site.

  4. Implement the required executeNodeLogic method.

    This method defines the logic that runs when the test step executes. Typically, this method is used to instantiate and validate components of the system under test.

    The TestExec parameter provides access to the test environment, such as logs and events. The Map parameter provides access to the current value of the test step parameters. The Object return type allows you to pass data back to the running test, so that you can run assertions and filters on it.

    public Object executeNodeLogic( TestExec ts, Map params ) throws TestRunException
    {
        ts.log( "We got called with: " + params.toString() );
        String host = (String)params.get("host");
        String username = (String)params.get("username");
        String password = (String)params.get("password");
        String path = (String)params.get("path");
        String file = (String)params.get("file");
        String storedFile = runFTP(ts,host,username,password,path,file);
        FileDataObject fdo = new FileDataObject(storedFile);
        return fdo;
    }
    

    Using a custom data object for the return value is common. This strategy has two benefits:

    The previous code uses the FileDataObject custom data object to store only the path to the stored file, rather than passing an open File or FileInputStream. Any filter can perform conditional processing by checking that the type of the result object is FileDataObject.