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; }
/** @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); }
/** @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); }
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); } }
@Override protected void doExecute( RunTimeData aVariables, ParameterArrayList parameters, TestStepCommandResult result) throws Exception { @SuppressWarnings("unchecked") List<Object> list = (List<Object>) obtainValue(aVariables, parameters, PARSPEC_LIST); String varName = (String) obtainValue(aVariables, parameters, PARSPEC_VARIABLE); int size = list.size(); RunTimeVariable rtVariable = new RunTimeVariable(varName, size); aVariables.add(rtVariable); result.setDisplayName(this.toString() + " " + varName + " = " + size); }
/** @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); }
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); } }