@Override public FeatureTokenBean marshal(FeatureToken f) throws Exception { FeatureTokenBean result = new FeatureTokenBean(); result.setTokenId(f.getTokenId()); result.setName(f.getName()); if (f.getUsesHandlers()!=null && f.getUsesHandlers().length>0) { String handlerCsv = FormattingUtils.getAsCsv(f.getUsesHandlers()); result.setUsesHandlers(handlerCsv); } result.setConfigurationName(f.getConfigurationName()); result.setDescription(f.getDescription()); result.setScenarios(f.getScenarios()); result.setEndState(f.getEndState()); return result; }
@Override public FeatureToken unmarshal(FeatureTokenBean f) throws Exception { FeatureToken featureToken = new FeatureToken(); featureToken.setName(f.getName()); featureToken.setDescription(f.getDescription()); featureToken.setConfigurationName(f.getConfigurationName()); String h = f.getUsesHandlers(); featureToken.setUsesHandlers(h == null ? null : FormattingUtils.getStringArrayFromCsv(h)); for ( ScenarioToken s : f.getScenarios()) { featureToken.addScenario(s); } return featureToken; }
private boolean replaceWithChorusProperty(String fullPropertyName, String variable, StringBuilder sb, String property) { boolean replaced = false; int start = sb.indexOf(variable); if ( CHORUS_FEATURE_DIR_VARIABLE.equals(property)) { sb.replace(start, start + variable.length(), featureToken.getFeatureDir().getPath()); log.debug("Replaced variable " + variable + " with value " + featureToken.getFeatureDir().getPath() + " for property " + fullPropertyName); replaced = true; } else if ( CHORUS_FEATURE_FILE_VARIABLE.equals(property)) { sb.replace(start, start + variable.length(), featureToken.getFeatureFile().getPath()); log.debug("Replaced variable " + variable + " with value " + featureToken.getFeatureFile().getPath() + " for property " + fullPropertyName); replaced = true; } else if ( CHORUS_FEATURE_CONFIGURATION_VARIABLE.equals(property)) { sb.replace(start, start + variable.length(), featureToken.getConfigurationName()); log.debug("Replaced variable " + variable + " with value " + featureToken.getConfigurationName() + " for property " + fullPropertyName); replaced = true; } else if ( CHORUS_FEATURE_NAME_VARIABLE.equals(property)) { sb.replace(start, start + variable.length(), featureToken.getName()); log.debug("Replaced variable " + variable + " with value " + featureToken.getConfigurationName() + " for property " + fullPropertyName); replaced = true; } return replaced; }
private FeatureToken createFeature(String line, List<String> usingDeclarations) { FeatureToken feature = new FeatureToken(); feature.setName(line.substring(8, line.length()).trim()); feature.setUsesHandlers(usingDeclarations.toArray(new String[usingDeclarations.size()])); return feature; }
private String calculateLogFileBaseName(FeatureToken featureToken, File featureFile, String processAlias) { String featureFileBaseName = getFeatureName(featureFile); //log file base name including both feature name and process alias ( + feature config ) String processFileNameBase; if (! featureToken.isConfiguration()) { processFileNameBase = String.format("%s-%s", featureFileBaseName, processAlias); } else { processFileNameBase = String.format("%s-%s-%s", featureFileBaseName, featureToken.getConfigurationName(), processAlias); } return processFileNameBase; }
log.info("Running feature from file: " + feature.getFeatureFile() + (feature.isConfiguration() ? " in config " + feature.getConfigurationName() : "")); log.warn("The following handlers were not available, failing feature " + feature.getName() + " " + unavailableHandlersMessage); feature.setUnavailableHandlersMessage(unavailableHandlersMessage.toString()); executionToken.incrementUnavailableHandlers(); } else { runScenarios(executionToken, feature, feature.getScenarios(), handlerManager, skipAllScenarios); log.error("Exception while running feature " + feature.getName(), e); String description = feature.getEndState() == EndState.PASSED ? " passed! " : feature.getEndState() == EndState.PENDING ? " pending! " : " failed! "; log.trace("The feature " + description); if ( feature.getEndState() == EndState.PASSED) { executionToken.incrementFeaturesPassed(); } else if ( feature.getEndState() == EndState.PENDING ) { executionToken.incrementFeaturesPending(); } else {
private void createFeatureFour() { ScenarioToken scenarioFour = new ScenarioToken(); scenarioFour.setName("Scenario Four"); StepToken step = scenarioFour.addStep(StepToken.createStep("If", "I add a step to scenario 3")); step.setEndState(StepEndState.SKIPPED); FeatureToken featureFour = new FeatureToken(); featureFour.setName("Feature Four Failed No Handler"); featureFour.addScenario(scenarioFour); listOfFeatures.add(featureFour); }
private void getOrCreateLogDirectory(File logDirectory) { boolean logDirExists = logDirectory.exists(); if ( ! logDirExists && processesConfig.isCreateLogDir()) { log.debug("Creating log directory at " + logDirectory.getPath() + " for feature " + featureToken.getName()); logDirExists = logDirectory.mkdirs(); if ( ! logDirExists ) { log.warn("Failed to create log directory at " + logDirectory.getPath() + " will not write logs"); } } }
private PropertyOperations mergeLoadersForDirectory(PropertyOperations props, File dir, FeatureToken featureToken) { props = props.merge(getPropertyLoader(dir, "chorus.properties")); String featureNameBase = featureToken.getFeatureFile().getName().replace(".feature", ""); props = props.merge(getPropertyLoader(dir, featureNameBase + ".properties")); props = props.merge(getPropertyLoader(dir, featureNameBase + "-" + featureToken.getConfigurationName() + ".properties")); return props; }
private List<ChorusScenario> createChildren() { List<ChorusScenario> l = new ArrayList<>(); for (ScenarioToken s : featureToken.getScenarios()) { l.add(new ChorusScenario(featureToken, s, uniqueScenarioNames)); } return l; }
private String calculateName(FeatureToken featureToken, ScenarioToken scenarioToken, Set<String> scenarioNames) { String conf = featureToken.getConfigurationName().equals(FeatureToken.BASE_CONFIGURATION) ? "" : " [" + featureToken.getConfigurationName() + "]"; String name = scenarioToken.getName() + conf; int instance = 2; while ( ! scenarioNames.add(name)) { name = scenarioToken.getName() + " (" + instance++ + ")"; } return name; }
@Before public void doBefore() { scenarioToken = new ScenarioToken(); scenarioToken.setName("Test Scenario"); stepOne = scenarioToken.addStep(StepToken.createStep("If", "I create a step")); stepTwo = scenarioToken.addStep(StepToken.createStep("If", "I create a second step")); stepThree = StepToken.createStep("If", "I create a step macro child step"); stepTwo.addChildStep(stepThree); scenarioTwo = new ScenarioToken(); stepFour = scenarioTwo.addStep(StepToken.createStep("If", "I add a step to scenario 2")); featureToken = new FeatureToken(); featureToken.addScenario(scenarioToken); featureToken.addScenario(scenarioTwo); featureTwo = new FeatureToken(); executionToken = new ExecutionToken("My test suite name"); testSuite = new TestSuite(executionToken, Arrays.asList(featureToken, featureTwo)); }
String implicitHandlerName = feature.getName(); //the handler which shares the feature name is the implicit handler Class mainHandlerClass = allHandlerClasses.get(implicitHandlerName); if (mainHandlerClass == null) { for (String usesHandler : feature.getUsesHandlers()) { Class usesHandlerClass = allHandlerClasses.get(usesHandler); if ( usesHandler.equals(implicitHandlerName)) {
public ProcessOutputConfiguration(FeatureToken featureToken, NamedProcess processesConfig) { this.featureDir = featureToken.getFeatureDir(); this.logFileBaseName = calculateLogFileBaseName(featureToken, featureToken.getFeatureFile(), processesConfig.getProcessName()); this.processesConfig = processesConfig; this.isAppendToLogs = processesConfig.isAppendToLogs(); this.featureToken = featureToken; logDirectory = calculateLogDirectory(); stdOutFileAndMode = new LogFileAndMode( new File(logDirectory, String.format("%s-out.log", logFileBaseName)), processesConfig.getStdOutMode(), "stdOut", false ); stdErrFileAndMode = new LogFileAndMode( new File(logDirectory, String.format("%s-err.log", logFileBaseName)), processesConfig.getStdErrMode(), "stdErr", true ); //let's fail the feature if we cannot create the log directory //alternative would be to log inline but this might swamp interpreter output if ( OutputMode.isWriteToLogFile(stdOutFileAndMode.getMode()) || OutputMode.isWriteToLogFile(stdErrFileAndMode.getMode()) ) { getOrCreateLogDirectory(logDirectory); ChorusAssert.assertTrue("Cannot write to the logs directory at " + logDirectory, logDirectory.canWrite()); } }
@Override public void executeAScript(String configName, String scriptPath) { //Resolve the script path relative to the feature file File script = feature.getFeatureDir().toPath().resolve(scriptPath).toFile(); String scriptContents = FileUtils.readScriptFile(log, configName, scriptPath, script); Tuple2<Connection, SqlConfig> connectionDetails = getConnectionDetails(configName); executeJdbcStatements(connectionDetails.getOne(), configName, scriptContents, "script at " + scriptPath); }
private void printFailures(List<FeatureToken> featuresList, Consumer<String> messageWriter) { featuresList.stream().filter(f-> f.getEndState() == EndState.FAILED).forEachOrdered(f -> { f.accept(new TokenVisitorAdapter() {
/** * @return a deep copy of the feature results and all its sub tokens */ public FeatureToken deepCopy() { FeatureToken copy = new FeatureToken(); super.deepCopy(copy); copy.name = this.name; copy.usesHandlers = usesHandlers.clone(); copy.configurationName = this.configurationName; copy.scenarios = new ArrayList<>(this.scenarios.size()); copy.featureFile = featureFile; for (ScenarioToken scenario : this.scenarios) { copy.scenarios.add(scenario.deepCopy()); } return copy; }
private Object getFeatureResource(String resourceName, Iterable<Object> handlerInstances) { Object o = null; if (ChorusResource.featureFile.equals(resourceName)) { o = feature.getFeatureFile(); } else if (ChorusResource.featureDir.equals(resourceName)) { o = feature.getFeatureFile().getParentFile(); } else if (ChorusResource.featureToken.equals(resourceName)) { o = feature; } else if (ChorusResource.profile.equals(resourceName)) { o = profile; } else if (resourceName.matches("subsystem.+")) { o = getSubsystemResource(resourceName); } else if ( resourceName.startsWith(ChorusResource.handlerPrefix)) { o = getHandlerResource(resourceName, handlerInstances); } return o; }
public String getNameWithConfiguration() { if (isConfiguration() && configurationName.length() > 0) { return String.format("%s [%s]", name, configurationName); } else { return name; } }
String scenarioName = line.substring(KeyWord.Scenario.stringVal().length()).trim(); currentScenario = createScenario(scenarioName, backgroundScenario, currentFeaturesTags, currentScenariosTags); currentFeature.addScenario(currentScenario); parserState = READING_SCENARIO_STEPS; directiveParser.addKeyWordDirectives(new ScenarioTokenStepConsumer(currentScenario)); currentFeature.addScenario(currentScenario); parserState = READING_SCENARIO_STEPS; directiveParser.addKeyWordDirectives(new ScenarioTokenStepConsumer(currentScenario)); resetLastTagsLine(); currentScenario = createScenario(KeyWord.FEATURE_END_SCENARIO_NAME, null, null, null); currentFeature.addScenario(currentScenario); parserState = READING_SCENARIO_STEPS; directiveParser.addKeyWordDirectives(new ScenarioTokenStepConsumer(currentScenario)); currentFeature.appendToDescription(line); break; case READING_SCENARIO_BACKGROUND_STEPS: allStepMacro ); currentFeature.addScenario(scenarioFromOutline);