Skip to content

Analyzers

itaiag edited this page Aug 9, 2016 · 1 revision

Analyzers

Analyzers provide an easy way to verify “SystemObjects” (driver) operations. The system object operations are used to manage and or receive information from the SUT. Every operation takes the result object and defines it as the object to be analyzed using the “setTestAgainstObject” method. Thus, the analyzers can be used to analyze the object and compare it with an expected result. The analysis service comprises an architecture that supports two kinds of users, an advanced programmer that writes the system object and analyzers, and users that use the analyzers to in order to examine operation results. Predefined analyzers provide an easy method to verify system object operations. Every system object operation takes the command output and sets it to be the “testAgainst” object.

Using Analyzers

The components that comprise the analysis process are as follows:

  1. The system object that performs the operation on the SUT, and defines the received results of the operation on the system object that will be performed by the analysis.

  2. The test that activates the analyzer on received operation results.

  3. The analyzer java class that perform the actual analysis.

Simple Traffic

The code example illustrates a simple traffic test that generates traffic and then analysis it. The purpose of this piece of code is to demonstrate how analyzers are used.

Simple Traffic Code Example

In the code example “testIsFileExists”, the programmer activates the “dir” operation of the system object. The result of the operation defines the object on which the analysis is performed.

  /**
     * Checks whether file <code>fileToFind</code> exists in 
     * <code>folder</code>.
     * Demonstrates basic analysis usage
     * @params.include fileToFind,folder
     */
    public void testIsFileExists() throws Exception {
      station.dir(getFolder());
      station.analyze(new SimpleTextFinder(getFileToFind()));
 }

Analyzer Methodology

In order to perform an analysis the programmer activates the analyzer using the analyze method. If the analysis performed is successful the reporter service will produce a positive result. If unsuccessful an error indication will be reported and the system object will throw an assertion exception.

Directory Operation Code Example

In the code example the stations system object uses the Cli system object to send the “dir” command, it then takes the command results and defines them to be the data on which the analysis is performed, this is achieved by activating the “setTestAgainstObject” method.

  public void dir(String folderName) throws Exception {
      CliCommand cmd = new CliCommand("dir " + folderName);
      cmd.addErrors("unknown command");
      cliConnection.handleCliCommand("dir " + folderName, cmd);
      setTestAgainstObject(cmd.getResult());
 }

Writing an Analyzer

In the two previous sections the user learned about analyzer functionality. Now that the analyzer has been defined the user must now learn how to implement an analyzer. In order to implement an analyzer the user must extend the “AnalyzerParameterImpl” class. This is achieved by performing the following implementation of an analyzer method as shown in the following example:

Analyzer Implementation Guidelines

The following Guidelines refer to analysis analyze() method implementation:

  1. In order to signal the JSystem framework if the analysis has failed or succeeded, the programmer must set the status class member field to a true or false value. False = failure and true = success.

  2. Implementing the title and message fields. The “title” class member should be set with the summary of the analysis results. The “message” class member is usually used in the case of an analysis failure and is set with the “toString()” of operation results.

 /**
  * Simple analyzer example
  */

public class SimpleTextFinder extends AnalyzerParameterImpl {
    private String txtToFind;
    int result;
    
    public SimpleTextFinder(String txtToFind){
        this.txtToFind = txtToFind;
    }
   
    public void analyze() {
        String txt = testAgainst.toString();
        if (StringUtils.isEmpty(txt)){
            title = "No text was given to analyzer";
            status= false;
            return;
        }
        if (txt.indexOf(txtToFind) > 0){
            title = "Text " + txtToFind + " was found";
            status = true;
            return;
        }
     
        title = "Text " + txtToFind + " was not found found";
        message = txtToFind;
        status = false;
        result = 5;
    }
 
    public int getResult(){
        return result;
    }
 }

Advanced Analyzers Features

Default usage of the analyze method throws an “AnalyzerException” java class and issues an error report when an error is received. There are two options that the programmer can implement in order to prevent JSystem from throwing an exception. They are as follows:

  1. Before analysis, activate the method station.setThrowException(false);

  2. In order to see the method documentation use the following analysis method station.analyze(analyzer,false,false);

/**
  * Analyze the result. Report analysis results to the reporter
    * 
    * @param parameter
    *            The analyzer parameter object.
    * @param silent
    *            if silent no reports will be submit
    * @param throwException 
    *             if false an AnalyzeException will not be thrown in case of analysis
    *             failure 
    * 
    * @exception AnalyzerException
    */
   @SuppressWarnings("unchecked")
   public void analyze(AnalyzerParameter parameter, boolean silent, boolean throwException) throws AnalyzerException {

Prevent Publishing Error Reports

In order to prevent the analyzer from throwing exceptions and not publishing error reports to the reporter the programmer must implement the following method, isAnalyzeSuccess(AnalyzerParameter parameter). This method activates the Analyzer and returns the analysis results.

Clone this wiki locally