Example #1
0
  private static PluginCollection loadPlugins(RunTimeData anRtData) {
    Trace.println(Trace.UTIL, "loadPlugins(  runTimeData )", true);

    File tmpPluginDirectory = anRtData.getValueAsFile(Testium.PLUGINSDIR);
    File pluginDir;

    if (tmpPluginDirectory == null) {
      File baseDir = anRtData.getValueAsFile(Testium.BASEDIR);
      if (baseDir == null) {
        throw new Error(Testium.BASEDIR + " is not set in RunTimeData");
      }
      pluginDir = new File(baseDir, "plugins");
    } else {
      String tmpPluginDirPath = anRtData.substituteVars(tmpPluginDirectory.getPath());
      pluginDir = new File(tmpPluginDirPath);
    }

    RunTimeVariable pluginDirVar = new RunTimeVariable(Testium.PLUGINSDIR, pluginDir);
    anRtData.add(pluginDirVar);

    if (!pluginDir.isDirectory()) {
      throw new Error("Plugin Directory is not found: " + pluginDir.getAbsolutePath());
    }

    PluginCollection plugins;
    try {
      plugins = PluginClassLoader.loadPlugins(pluginDir, anRtData);
    } catch (ConfigurationException e) {
      Trace.print(Trace.UTIL, e);
      throw new Error("Failed to load plugins: " + e.getMessage(), e);
    }

    return plugins;
  }
Example #2
0
  /** @param args */
  public static void main(String[] args) {
    Trace.getInstance().addBaseClass("org.testium");
    Trace.getInstance().addBaseClass("org.testtoolinterfaces");

    RunTimeData rtData = new RunTimeData();

    defineBaseDir(rtData);
    defineUserHome(rtData);
    defineStartTime(rtData);

    parseCommandLine(rtData, args);

    readGlobalConfigFile(rtData);
    readPersonalConfigFile(rtData);

    PluginCollection plugins = loadPlugins(rtData);
    Testium testium = createTestium(rtData, plugins);

    String command = rtData.getValueAsString(Testium.COMMAND);
    if (command.equalsIgnoreCase(CmdLineParser.VALIDATE)) {
      doValidation(testium, rtData);
    } else if (command.equalsIgnoreCase(CmdLineParser.EXECUTE)) {
      doExecution(testium, rtData);
    } else if (command.equalsIgnoreCase(CmdLineParser.PREPARE)) {
      doPreparations(testium, rtData);
    } else if (command.equalsIgnoreCase(CmdLineParser.INTERFACES)) {
      showInterfaces(plugins);
    } else if (command.equalsIgnoreCase(CmdLineParser.KEYWORDS)) {
      showKeywords(plugins);
    } else {
      throw new Error("Unknown Command: " + command);
    }

    System.out.flush();
    System.err.flush();

    // Find the root thread group
    ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();
    System.out.println("We start with threadgroup: " + root.getName());

    while (root.getParent() != null) {
      root = root.getParent();
      System.out.println("Up one to: " + root.getName());
    }

    visit(root, 0);

    System.runFinalization();
    try {
      Thread.sleep(30000);
    } catch (InterruptedException e) {
      // none, just exit;
    }
    System.exit(0); // Some plugins can have hanging threads. This will stop them.
  }
Example #3
0
 /**
  * @param anRtData
  * @param plugins
  * @return
  */
 private static Testium createTestium(RunTimeData anRtData, PluginCollection plugins) {
   Trace.println(Trace.UTIL, "createTestium( runTimeData, plugins )", true);
   Testium testium;
   try {
     testium = new Testium(plugins, anRtData);
   } catch (ConfigurationException e) {
     Trace.print(Trace.UTIL, e);
     throw new Error(APPLICATIONNAME + " could not be started.", e);
   }
   return testium;
 }
Example #4
0
  /**
   * @param testium
   * @param tgFile
   * @return
   * @throws Error
   */
  private static TestGroup readTestGroup(Testium testium, RunTimeData anRtData) throws Error {
    Trace.println(Trace.UTIL, "readTestGroup( Testium, runTimeData )", true);

    File tgFile = anRtData.getValueAsFile(Testium.TESTFILE);
    TestGroup testGroup;
    try {
      testGroup = testium.readTestGroup(tgFile);
    } catch (IOError e) {
      Trace.print(Trace.UTIL, e);
      throw new Error("TestGroup could not be read: " + tgFile.getPath(), e);
    }
    return testGroup;
  }
Example #5
0
  /** @param rtData */
  private static void defineUserHome(RunTimeData anRtData) {
    Trace.println(Trace.UTIL, "defineUserHome(  runTimeData )", true);

    File userHome = new File(System.getProperty("user.home"));
    RunTimeVariable userHomeVar = new RunTimeVariable(Testium.USERHOME, userHome);
    anRtData.add(userHomeVar);
  }
  /**
   * Creates the XML Handler
   *
   * @param anXmlReader the xmlReader
   * @param anInterfaceList a list of interfaces
   * @param aCheckStepParameter flag to indicate if specified parameters of a step must be verified
   *     in the interface
   */
  public TestExecItemXmlHandler(
      XMLReader anXmlReader,
      String aStartElement,
      TestInterfaceList anInterfaceList,
      boolean aCheckStepParameter) {
    super(anXmlReader, aStartElement);
    Trace.println(Trace.CONSTRUCTOR);

    //	    ArrayList<TestStep.StepType> prepRestAllowedTypes = new ArrayList<TestStep.StepType>();
    //	    prepRestAllowedTypes.add( TestStep.StepType.action );
    //	    prepRestAllowedTypes.add( TestStep.StepType.set );

    myRequirementIdXmlHandler = new GenericTagAndStringXmlHandler(anXmlReader, REQUIREMENT_ELEMENT);
    this.addElementHandler(myRequirementIdXmlHandler);

    myPrepareXmlHandler =
        new TestStepSequenceXmlHandler(
            anXmlReader,
            PREPARE_ELEMENT,
            //    	                                                      prepRestAllowedTypes,
            anInterfaceList,
            aCheckStepParameter);
    this.addElementHandler(myPrepareXmlHandler);

    myRestoreXmlHandler =
        new TestStepSequenceXmlHandler(
            anXmlReader,
            RESTORE_ELEMENT,
            //		                                                      prepRestAllowedTypes,
            anInterfaceList,
            aCheckStepParameter);
    this.addElementHandler(myRestoreXmlHandler);

    this.resetExecItemHandler();
  }
  public final void resetExecItemHandler() {
    Trace.println(Trace.SUITE);
    myRequirementIds = new ArrayList<String>();
    myPrepareSteps = new TestStepSequence();
    myRestoreSteps = new TestStepSequence();

    super.resetGroupEntryHandler();
  }
Example #8
0
  /**
   * @param testium
   * @param rtData
   * @throws Error
   */
  private static void doExecution(Testium aTestium, RunTimeData anRtData) throws Error {
    Trace.println(Trace.EXEC, "doExecution( Testium, runTimeData )", true);
    TestGroup testGroup = readTestGroup(aTestium, anRtData);
    File testSuiteDir = anRtData.getValueAsFile(Testium.PROJECTDIR);
    if (testSuiteDir == null) {
      throw new Error("Test Suite Directory is not defined");
    }
    if (!testSuiteDir.isDirectory()) {
      throw new Error("Test Suite Directory is not found: " + testSuiteDir.getPath());
    }

    try {
      aTestium.execute(testGroup, testSuiteDir, anRtData);
    } catch (TestExecutionException e) {
      Trace.print(Trace.EXEC, e);
      throw new Error("Execution failed.", e);
    }
  }
Example #9
0
  private static void readGlobalConfigFile(RunTimeData anRtData) {
    Trace.println(Trace.UTIL, "readConfigFile( runTimeData )", true);

    File globalConfigFile = anRtData.getValueAsFile(Testium.GLOBALCONFIGFILE);
    if (globalConfigFile == null) {
      File configDir = anRtData.getValueAsFile(Testium.CONFIGDIR);
      if (configDir == null) {
        throw new Error(Testium.CONFIGDIR + " is not defined in RunTimeData");
      }

      globalConfigFile = new File(configDir, "global.xml");
      RunTimeVariable globalConfigDirVar =
          new RunTimeVariable(Testium.GLOBALCONFIGFILE, globalConfigFile);
      anRtData.add(globalConfigDirVar);
    }

    // Default projectdir is {basedir}/suite
    File baseDir = anRtData.getValueAsFile(Testium.BASEDIR);
    File projectDir = new File(baseDir, "suite");
    RunTimeVariable rtVarProjectDir = new RunTimeVariable(Testium.PROJECTDIR, projectDir);
    anRtData.add(rtVarProjectDir);

    // create a parser
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(false);

    try {
      SAXParser saxParser = spf.newSAXParser();
      XMLReader xmlReader = saxParser.getXMLReader();

      // create a handler
      GlobalConfigurationXmlHandler handler =
          new GlobalConfigurationXmlHandler(xmlReader, anRtData);

      // assign the handler to the parser
      xmlReader.setContentHandler(handler);

      // parse the document
      xmlReader.parse(globalConfigFile.getAbsolutePath());
    } catch (Exception e) {
      Trace.print(Trace.UTIL, e);
      throw new Error(APPLICATIONNAME + " is not correctly setup.", e);
    }
  }
Example #10
0
  /** @param aPlugins */
  private static void showInterfaces(PluginCollection aPlugins) {
    Trace.println(Trace.EXEC, "showInterfaces( aPlugins )", true);

    System.out.println("Supported interfaces:");
    SupportedInterfaceList interfaceList = aPlugins.getInterfaces();
    for (Enumeration<String> keys = interfaceList.getInterfaceNames(); keys.hasMoreElements(); ) {
      String ifaceName = keys.nextElement();
      System.out.println("  " + ifaceName);
    }
  }
Example #11
0
  /** @param rtData */
  private static void defineBaseDir(RunTimeData anRtData) {
    Trace.println(Trace.UTIL, "defineBaseDir(  runTimeData )", true);

    File applicationBaseDir = new File("");
    try {
      File jarFile =
          new File(
              org.testium.Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
      applicationBaseDir =
          jarFile
              .getParentFile()
              .getParentFile(); // Assuming testium is in {basedir}/src/Testium.jar
    } catch (URISyntaxException exc) {
      Trace.print(Trace.UTIL, exc);
      throw new Error("Cannot determine " + APPLICATIONNAME + "'s basedir: ", exc);
    }
    RunTimeVariable applBaseDirVar = new RunTimeVariable(Testium.BASEDIR, applicationBaseDir);
    anRtData.add(applBaseDirVar);
  }
Example #12
0
  /**
   * @param rtData
   * @param testium
   * @param tgFile
   * @param testGroup
   * @throws Error
   */
  private static void doPreparations(Testium aTestium, RunTimeData anRtData) throws Error {
    Trace.println(Trace.EXEC, "doPreparations( Testium, runTimeData )", true);

    TestGroup testGroup = readTestGroup(aTestium, anRtData);
    File testSuiteDir = anRtData.getValueAs(File.class, Testium.PROJECTDIR);

    String groupId = anRtData.getValueAs(String.class, Testium.TESTGROUP);
    String caseId = anRtData.getValueAs(String.class, Testium.TESTCASE);

    if (groupId == null && caseId == null) {
      throw new Error("Preparation failed: Must specify a testgroup or testcase to prepare for.");
    }

    try {
      aTestium.prepare(testGroup, testSuiteDir, anRtData);
    } catch (TestExecutionException e) {
      Trace.print(Trace.EXEC, e);
      throw new Error("Preparation failed.", e);
    }
  }
Example #13
0
  /**
   * @param args
   * @return
   */
  private static void parseCommandLine(RunTimeData anRtData, String[] args) {
    Trace.println(Trace.UTIL, "parseCommandLine(  runTimeData, args )", true);

    CmdLineParser cmdLine = new CmdLineExecutionParser(APPLICATIONNAME);
    cmdLine.setDefaultCommand("execute");

    cmdLine.acceptFlag(Testium.VERSION, "Displays the versions of Testium and the plugins");

    try {
      cmdLine.parse(anRtData, args);
    } catch (ParameterException pe) {
      Trace.print(Trace.UTIL, pe);
      cmdLine.printHelpOn(System.out);
      throw new Error("Error on command line.", pe);
    }

    if (anRtData.getValueAsBoolean(Testium.HELP)) {
      cmdLine.printHelpOn(System.out);
      System.exit(0);
    }

    if (anRtData.getValueAsBoolean(Testium.VERSION)) {
      System.out.println("The version of Testium");
      Package[] packages = Package.getPackages();
      for (Package pkg : packages) {
        String pkgName = pkg.getName();
        if (!pkgName.startsWith("java")
            && !pkgName.startsWith("sun")
            && !pkgName.startsWith("joptsimple")
            && !pkgName.startsWith("org.xml")) {
          System.out.println(pkgName + ":\t" + pkg.getImplementationVersion());
        }
      }

      System.exit(0);
    }
  }
Example #14
0
  /**
   * @param aTestium
   * @param anRtData
   * @throws Error
   */
  private static void showKeywords(PluginCollection aPlugins) {
    Trace.println(Trace.EXEC, "showKeywords( aPlugins )", true);

    System.out.println("Supported keywords:");
    SupportedInterfaceList interfaceList = aPlugins.getInterfaces();
    for (Enumeration<String> keys = interfaceList.getInterfaceNames(); keys.hasMoreElements(); ) {
      String ifaceName = keys.nextElement();
      System.out.println("  " + ifaceName);

      ArrayList<String> commandList = interfaceList.getInterface(ifaceName).getCommands();
      for (String command : commandList) {
        System.out.println("    " + command);
      }

      System.out.println();
    }
  }
 @Override
 public void handleReturnFromChildElement(String aQualifiedName, XmlHandler aChildXmlHandler)
     throws TestSuiteException {
   Trace.println(Trace.SUITE);
   if (aQualifiedName.equalsIgnoreCase(REQUIREMENT_ELEMENT)) {
     myRequirementIds.add(myRequirementIdXmlHandler.getValue());
     myRequirementIdXmlHandler.reset();
   } else if (aQualifiedName.equalsIgnoreCase(PREPARE_ELEMENT)) {
     myPrepareSteps = myPrepareXmlHandler.getSteps();
     myPrepareXmlHandler.reset();
   } else if (aQualifiedName.equalsIgnoreCase(RESTORE_ELEMENT)) {
     myRestoreSteps = myRestoreXmlHandler.getSteps();
     myRestoreXmlHandler.reset();
   } else {
     super.handleReturnFromChildElement(aQualifiedName, aChildXmlHandler);
   }
 }
Example #16
0
  /** @param rtData */
  private static void defineStartTime(RunTimeData anRtData) {
    Trace.println(Trace.UTIL, "defineStartTime(  runTimeData )", true);

    Date now = new Date();

    RunTimeVariable startTimeVar = new RunTimeVariable(Testium.START, now);
    anRtData.add(startTimeVar);

    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
    RunTimeVariable startDateFormattedVar =
        new RunTimeVariable(Testium.STARTDATE, dateFormatter.format(now));
    anRtData.add(startDateFormattedVar);

    SimpleDateFormat timeFormatter = new SimpleDateFormat("HHmmss");
    RunTimeVariable startTimeFormattedVar =
        new RunTimeVariable(Testium.STARTTIME, timeFormatter.format(now));
    anRtData.add(startTimeFormattedVar);
  }
Example #17
0
 private static void doValidation(Testium aTestium, RunTimeData anRtData) {
   Trace.println(Trace.EXEC, "doValidation( Testium, runTimeData )", true);
   readTestGroup(aTestium, anRtData);
 }
Example #18
0
  private static void readPersonalConfigFile(RunTimeData anRtData) {
    Trace.println(Trace.UTIL, "readPersonalConfigFile(  runTimeData )", true);

    File configFile = anRtData.getValueAsFile(Testium.CONFIGFILE);
    if (configFile == null) {
      File userHome = anRtData.getValueAsFile(Testium.USERHOME);
      if (userHome == null) {
        throw new Error(Testium.USERHOME + " is not defined in RunTimeData");
      }

      File userConfigDir = anRtData.getValueAsFile(Testium.USERCONFIGDIR);
      if (userConfigDir == null) {
        userConfigDir = new File(userHome, "." + APPLICATIONNAME.toLowerCase(Locale.ENGLISH));
      }
      RunTimeVariable userConfigDirVar = new RunTimeVariable(Testium.USERCONFIGDIR, userConfigDir);
      anRtData.add(userConfigDirVar);

      File defaultConfigFile = anRtData.getValueAsFile(Testium.DEFAULTCONFIGFILE);
      if (defaultConfigFile == null) {
        configFile = new File(userConfigDir, "general.xml");
      } else {
        if (!defaultConfigFile.isAbsolute()) {
          configFile = new File(userConfigDir, defaultConfigFile.getPath());
          if (!configFile.exists()) {
            configFile = new File(userHome, defaultConfigFile.getPath());
          }
        } else {
          configFile = defaultConfigFile;
        }
      }

      RunTimeVariable configFileVar = new RunTimeVariable(Testium.CONFIGFILE, configFile);
      anRtData.add(configFileVar);
    } else {
      File userConfigDir = configFile.getParentFile();
      RunTimeVariable userConfigDirVar = new RunTimeVariable(Testium.USERCONFIGDIR, userConfigDir);
      anRtData.add(userConfigDirVar);
    }

    // create a parser
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(false);

    try {
      SAXParser saxParser = spf.newSAXParser();
      XMLReader xmlReader = saxParser.getXMLReader();
      // create a handler
      PersonalConfigurationXmlHandler handler =
          new PersonalConfigurationXmlHandler(xmlReader, anRtData);

      // assign the handler to the parser
      xmlReader.setContentHandler(handler);

      // parse the document
      xmlReader.parse(configFile.getAbsolutePath());
    } catch (FileNotFoundException fnfe) {
      Trace.print(Trace.UTIL, fnfe);
    } catch (Exception e) {
      Trace.print(Trace.UTIL, e);
      throw new Error(APPLICATIONNAME + " could not be configured.", e);
    }
  }