com.rational.test.ft.services

Class LogExtensionAdapter

  • All Implemented Interfaces:
    ILog, ISimpleLog
    Direct Known Subclasses:
    ExecutionHistoryLog, HTMLLog, NullLog, TextLog


    public abstract class LogExtensionAdapter
    extends LogAdapter
    This is the base class for all Functional Test log extensions

    Implementors should only write the following methods to get the desired log results they wish to design.
    public void initLog()
    public void closeLog()
    public void writeLog(ILogMessage message)

    Sample implementation of the subclass is shown below to get the sample text log output of a sample script
    Sample Text Log
    July 23, 2007 8:30:12 PM IST :Script Name Script1.java Result :INFO Event SCRIPT START headlind Script start [Script1]
    Property Name =line_number Property Value =1
    Property Name =script_name Property Value =Script1
    Property Name =script_id Property Value =Script1.java



    July 23, 2007 8:30:12 PM IST :Script Name Script1.java Result :PASS Event SCRIPT END headlind Script end [Script1]
    Property Name =line_number Property Value =-1
    Property Name =script_name Property Value =Script1
    Property Name =script_id Property Value =Script1.java



    Sample Implementation
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Vector;

    import com.rational.test.ft.services.ILogMessage;
    import com.rational.test.ft.services.LogException;
    import com.rational.test.ft.services.LogExtensionAdapter;
    import com.rational.test.ft.services.LogMessageProperty;

    public class ExampleLog extends LogExtensionAdapter {

    private String logName=null;
    private String logDirectory=null;
    private PrintWriter out=null;

    public ExampleLog(String logName) {
     super(logName);
     this.logName=logName;
     this.logDirectory=null;
    }

    public ExampleLog() {
     super();
     this.logName=null;
     this.logDirectory=null;
    }

    public void closeLog() {
     try{
       out.close();
     }catch(Exception e)
     
     
     }
    }

    public void initLog() throws LogException {
     try{
      this.logName=getLogName();
      this.logDirectory=getLogDirectory();
      File logFile=new File(logDirectory,logName+".txt");
      FileOutputStream fos=new FileOutputStream(logFile);
      out=new PrintWriter(fos);
     }catch(IOException e)
     {
     
     }
    }

    public void writeLog(ILogMessage message) {
     Vector properties=message.getProperties();
      String result=getResult(message);
      String event_type=getEventType(message);
      String headline=getHeadline(message);
      String timestamp=getTimestamp();
      String currentScriptName=getScriptName(message);
      out.println(timestamp + " :Script Name " + currentScriptName + " Result :" + result + " Event " + event_type + " headlind " + headline );
      for(int i=0,size=properties.size();i  {
      LogMessageProperty property =
       (LogMessageProperty) properties.elementAt( i );
      out.println("Property Name =" + property.getName().toString() + " Property Value =" +property.getValue().toString() );
      }
      out.println();
    }

    private String getResult(ILogMessage message) {
      String result=null;
      switch (message.getResult())
      {
       case LOG_FAILURE : result="FAILURE";break;
       case LOG_PASS : result="PASS";break;
       case LOG_WARNING : result="WARNING";break;
       default: result= "INFO";
     }
     return result;
    }

    private String getEventType(ILogMessage message) {
      String eventType=null;
      switch(message.getEvent())
      {
       case EVENT_SCRIPT_START : eventType="SCRIPT START";break;
       case EVENT_SCRIPT_END : eventType="SCRIPT END";break;
       case EVENT_VP : eventType="VERIFCATION POINT";break;
       case EVENT_CALL_SCRIPT : eventType = "CALL_SCRIPT"; break;
       case EVENT_APPLICATION_START : eventType="APPLICATION START";break;
       case EVENT_APPLICATION_END : eventType="APPLICATION END";break;
       case EVENT_TIMER_START : eventType="TIMER START";break;
       case EVENT_TIMER_END : eventType= "TIMER END" ;break;
       case EVENT_CONFIGURATION : eventType="CONFIGURATION"; break;
       default : eventType="GENERAL";
     }
     return eventType;
    }

    private String getHeadline(ILogMessage message) {
      return message.getHeadline();
    }

    private String getScriptName(ILogMessage message) {
      String scriptName=null;
      Vector properties=message.getProperties();
      for(int i=0,size=properties.size();i  {
       LogMessageProperty property =
       (LogMessageProperty) properties.elementAt( i );
       if(property.getName().equalsIgnoreCase(PROP_SCRIPT_ID))
       {
         scriptName=property.getValue().toString();
       }
      }
      return scriptName;
    }
    }
    • Constructor Detail

      • LogExtensionAdapter

        public LogExtensionAdapter(java.lang.String logName)
      • LogExtensionAdapter

        public LogExtensionAdapter()
    • Method Detail

      • persistImage

        protected void persistImage(ILogMessage message)
        Persist the screen snap shot if present in the message
        Parameters:
        message - The message that is to be logged
      • getLocationForImagePersistance

        protected java.lang.String getLocationForImagePersistance()
        Return the location to persist images.
        Returns:
      • setLogDirectory

        public final void setLogDirectory(java.lang.String logDirectory)
        Sets the directory the log is beging written to.
        Overrides:
        setLogDirectory in class LogAdapter
      • setLogName

        public final void setLogName(java.lang.String log_Name)
        Sets the log name the log is beging written to.
        Overrides:
        setLogName in class LogAdapter
      • scriptStart

        public final void scriptStart(java.lang.String name,
                                      IScriptDefinition scriptDef)
        Write a script start message into the log
        Specified by:
        scriptStart in interface ILog
        Overrides:
        scriptStart in class LogAdapter
        Parameters:
        name - The script name.
        language - The language used for the script ( i.e. java )
      • scriptEnd

        public final void scriptEnd(java.lang.String name,
                                    java.lang.String language)
        Write a script end message into the log
        Specified by:
        scriptEnd in interface ILog
        Overrides:
        scriptEnd in class LogAdapter
        Parameters:
        name - The script name.
        language - The language used for the script ( i.e. java )
      • callScript

        public final void callScript(java.lang.String name,
                                     java.lang.String language)
        Write a call script message into the log
        Specified by:
        callScript in interface ILog
        Overrides:
        callScript in class LogAdapter
        Parameters:
        name - The script being called.
        language - The language used for the script ( i.e. java )
      • applicationStart

        public final void applicationStart(java.lang.String name,
                                           java.lang.String language)
        Write an application start message into the log.
        Specified by:
        applicationStart in interface ILog
        Overrides:
        applicationStart in class LogAdapter
        Parameters:
        name - The application's name.
        language - The language used for the script ( i.e. java )
      • applicationStart

        public final void applicationStart(java.lang.String name,
                                           int status,
                                           java.lang.String description,
                                           java.lang.String language)
        Writes an application start message into the log.
        Specified by:
        applicationStart in interface ILog
        Overrides:
        applicationStart in class LogAdapter
        Parameters:
        name - The application's name
        status - Result of starting the application (@see ISimpleLog.LOG_FAILURE
        description - Additional text for the status (e.g. reason for failure)
        language - The language used for the script ( i.e. java )
        See Also:
        ISimpleLog.LOG_WARNING, ISimpleLog.LOG_INFORMATION
      • createApplicationStartMessage

        public final ILogMessage createApplicationStartMessage(java.lang.String name,
                                                               int status,
                                                               java.lang.String description,
                                                               java.lang.String language)
        Return a application start message. This interface allows the caller to add detailed information and then write the message.
        Specified by:
        createApplicationStartMessage in interface ILog
        Overrides:
        createApplicationStartMessage in class LogAdapter
        Parameters:
        name - The application's name.
        status - Result of starting the application (@see ISimpleLog.LOG_FAILURE
        description - Additional text for the status (e.g. reason for failure)
        language - The language used for the script ( i.e. java )
        Returns:
        An application start message.
        See Also:
        ISimpleLog.LOG_WARNING, ISimpleLog.LOG_INFORMATION
      • timerStart

        public void timerStart(java.lang.String name,
                               java.lang.String language)
        Write a start timer message into the log.
        Specified by:
        timerStart in interface ILog
        Overrides:
        timerStart in class LogAdapter
        Parameters:
        name - The timer name.
        language - The language used for the script ( i.e. java )
      • createTimerStartMessage

        public final ILogMessage createTimerStartMessage(java.lang.String name,
                                                         java.lang.String language)
        Return a start timer message. This interface allows the caller to add detailed information and then write the message.
        Specified by:
        createTimerStartMessage in interface ILog
        Overrides:
        createTimerStartMessage in class LogAdapter
        Parameters:
        name - The timer name.
        language - The language used for the script ( i.e. java )
        Returns:
        A timer start message. This message has the result, event, and note initialized.
      • timerEnd

        public void timerEnd(java.lang.String name,
                             java.lang.String language)
        Write an end timer message into the log.
        Specified by:
        timerEnd in interface ILog
        Overrides:
        timerEnd in class LogAdapter
        Parameters:
        name - The timer name.
        language - The language used for the script ( i.e. java )
      • createTimerEndMessage

        public final ILogMessage createTimerEndMessage(java.lang.String name,
                                                       java.lang.String language)
        Return an end timer message. This interface allows the caller to add detailed information and then write the message.
        Specified by:
        createTimerEndMessage in interface ILog
        Overrides:
        createTimerEndMessage in class LogAdapter
        Parameters:
        name - The timer name.
        language - The language used for the script ( i.e. java )
        Returns:
        A timer end message. This message has the result, event, and note initialized.
      • createVPMessage

        public final ILogMessage createVPMessage(int resultCode,
                                                 java.lang.String type,
                                                 java.lang.String name,
                                                 java.lang.String language)
        Return a verification point message. This method allows the caller to add detailed information and then write the message.
        Specified by:
        createVPMessage in interface ILog
        Overrides:
        createVPMessage in class LogAdapter
        Parameters:
        resultCode - One of the ILog.LOG_ codes.
        type - One of the VP_TYPE_ codes.
        name - The verification point name.
        language - The language used for the script ( i.e. java )
        Returns:
        A verification point message. This message has the result, event, and note initialized.
      • configuration

        public final void configuration(java.lang.String language)
        Write the system configuration into the log. This method reads the configuration from the "system" utility and logs it.
        Specified by:
        configuration in interface ILog
        Overrides:
        configuration in class LogAdapter
        Parameters:
        language - The language used for the script ( i.e. java )
      • createConfigurationMessage

        public final ILogMessage createConfigurationMessage(java.lang.String language)
        Create a system configuration message. This method allows the caller to add detailed information and then write the message.
        Specified by:
        createConfigurationMessage in interface ILog
        Overrides:
        createConfigurationMessage in class LogAdapter
        Parameters:
        language - The language used for the script ( i.e. java )
        Returns:
        A configuration message. This message has the result, event, and note initialized.
      • exception

        public final void exception(java.lang.String note,
                                    java.lang.String context,
                                    java.lang.String throwableName,
                                    java.lang.String throwableMessage,
                                    java.lang.String scriptName,
                                    int line,
                                    java.lang.String stackTrace,
                                    java.lang.String language)
        Write an exception message. Include the classname, the detail message and the stack as three separate properties.
        Specified by:
        exception in interface ILog
        Overrides:
        exception in class LogAdapter
      • exception

        public final void exception(java.lang.String note,
                                    java.lang.String context,
                                    java.lang.String throwableName,
                                    java.lang.String throwableMessage,
                                    java.lang.String scriptName,
                                    int line,
                                    java.lang.String stackTrace,
                                    java.lang.String language,
                                    java.awt.image.BufferedImage screenSnapshot)
        Write an exception message. Include the classname, the detail message and the stack as three separate properties. Also include a screen snapshot taken at the time of the exception.
        Specified by:
        exception in interface ILog
        Overrides:
        exception in class LogAdapter
      • createTestResultMessage

        public final ILogMessage createTestResultMessage(java.lang.String headline,
                                                         boolean passed,
                                                         java.lang.String additionalInfo)
        Creates a test result message.
        Specified by:
        createTestResultMessage in interface ILog
        Overrides:
        createTestResultMessage in class LogAdapter
        Parameters:
        headline - The headline describing the test
        passed - A boolean indicating if the test passed or failed.
        additionalInfo - Additional information about the test
      • getTimestamp

        public static final java.lang.String getTimestamp()
        Gets the current locale timestamp that can be logged
        Returns:
        timeStamp CurrentTimeStamp
      • open

        public void open()
        Opens the log and initializes internal resources. Internal method for initializations and not to be used by implementor/extendors Sub classes can override initLog to perform log initialization.
        Specified by:
        open in interface ISimpleLog
        Overrides:
        open in class SimpleLogAdapter
      • close

        public void close()
        Closes the log, thereby releasing internal resources. It is an Internal method not to be used by implementor/extendors Sub classes can override closeLog when they are done with the log
        Specified by:
        close in interface ISimpleLog
        Overrides:
        close in class SimpleLogAdapter
      • isVisualStudioPlayback

        protected boolean isVisualStudioPlayback()
        The log extensions is used for VS and java. This API helps determine the source of execution. Returns true if the execution is for VB script and false for Java Script.
        Returns:
      • getLogFilename

        public java.lang.String getLogFilename()
        Returns the log file for the log. It return an empty string. Override the method to return a proper file name
        Specified by:
        getLogFilename in interface ILog
        Overrides:
        getLogFilename in class LogAdapter
        Returns:
        Return an empty string
      • initLog

        public abstract void initLog()
                              throws LogException
        The abstract method that needs to be overridden by the sub classes to initialize their custom logs
        Throws:
        LogException
      • closeLog

        public abstract void closeLog()
        The abstract method that needs to be overridden by sub classes to close their custom logs
      • writeLog

        public abstract void writeLog(ILogMessage message)
        The abstract method that needs to be overridden by sub classes to handle the log events in the form of ILogMessage
        Parameters:
        message - The log Message Structure that contains information of log events and properties