private Map<Integer, CommandCall> populateCommandCallByColumnMap(Table table, CommandCall tableCommandCall) { Map<Integer, CommandCall> commandCallByColumn = new HashMap<Integer, CommandCall>(); Row headerRow = table.getLastHeaderRow(); for (CommandCall childCall : tableCommandCall.getChildren().asCollection()) { int columnIndex = headerRow.getIndexOfCell(childCall.getElement()); if (columnIndex == -1) { throw new RuntimeException("Commands must be placed on <th> elements when using 'execute' or 'verifyRows' commands on a <table>."); } commandCallByColumn.put(columnIndex, childCall); } return commandCallByColumn; }
protected CommandCall duplicateCommandForDifferentElement(CommandCall commandCall, Element element) { return new CommandCall( null, commandCall.getCommand(), element, commandCall.getExpression(), commandCall.getResource()); }
public void transferToParent(CommandCall parent) { if (getParent() != null) { getParent().getChildren().remove(this); } this.parent = parent; if (parent != null) { parent.appendChild(this); } }
@Override public void setUp(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) { httpRequest = parseRequest(commandCall.getElement(), evaluator, resultRecorder); formatRequest(commandCall.getElement(), httpRequest); }
@Override public void setUp(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside a 'set' is not supported"); evaluator.setVariable(commandCall.getExpression(), commandCall.getElement().getText()); announceSetCompleted(commandCall.getElement(), commandCall.getExpression()); }
@Override public void setUp(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) { stripCommandAttribute(commandCall.getElement()); variableName = commandCall.getExpression(); if (!variableName.isEmpty() && !variableName.startsWith("#")) { throw new RuntimeException(variableName + " should start with a #, to be a valid Concordion variable."); } commandCall.getChildren().setUp(evaluator, resultRecorder); }
@Override public void setUp(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) { verificationMethod = commandCall.getExpression(); expectation = parseExpectedResponse(commandCall.getElement(), evaluator, resultRecorder); }
public void processNode(CommandCall node, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { if (!node.getChildren().isEmpty()) { for (CommandCall before: beforeExamples) { SummarizingResultRecorder beforeResultRecorder = new SummarizingResultRecorder(); beforeResultRecorder.setSpecificationDescription("Running before for example " + node.getExpression()); before.getCommand().execute(before, evaluator, beforeResultRecorder, fixture); String errorText = null; if (beforeResultRecorder.hasExceptions()) { errorText = SimpleFormatter.format("Exceptions occurred in the 'before' example in '%s'. See the output specification for details.\n", specificationDescription ); } else if (beforeResultRecorder.getTotalCount() > 0) { errorText = SimpleFormatter.format("Assertions were made in the 'before' example in '%s'.\n" + "Assertions are not supported in the 'before' example.\n", specificationDescription ); } if (errorText != null) { System.err.println(errorText); throw new ConcordionAssertionError(errorText, beforeResultRecorder); } } } node.execute(evaluator, resultRecorder, fixture); }
@Override public void execute(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'run' is not supported"); Element element = commandCall.getElement(); String runnerType = commandCall.getExpression(); ResultAnnouncer resultAnnouncer = newRunResultAnnouncer(commandCall.getResource(), element); runStrategy.call(runner, commandCall.getResource(), href, resultAnnouncer, resultRecorder);
public void execute(CommandCall node, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { String exampleName = getExampleName(node); boolean isBeforeExample = isBeforeExample(node); resultRecorder.setSpecificationDescription( specificationDescriber.getDescription(node.getResource(), exampleName)); ImplementationStatus status = getImplementationStatus(node); if (!isBeforeExample && status != ImplementationStatus.IGNORED) { announceBeforeExample(exampleName, node.getElement(), resultRecorder, fixture); } try { resultRecorder.setImplementationStatus(status); if (status == ImplementationStatus.IGNORED) { resultRecorder.record(Result.IGNORED); } else { node.getChildren().processSequentially(evaluator, resultRecorder, fixture); } } catch (FailFastException f) { // Ignore - it'll be re-thrown later by the implementation status checker if necessary. } setupCommandForExample(node, resultRecorder, exampleName); if (!isBeforeExample && status != ImplementationStatus.IGNORED) { announceAfterExample(exampleName, node.getElement(), resultRecorder, fixture); } }
public void start(CommandCall commandCall) { announceBeforeProcessingEvent(commandCall.getResource(), commandCall.getElement()); }
@Override public void performModification(CommandCall commandCall, List<ExampleCommandCall> examples, List<CommandCall> beforeExamples) { /* We set the bypass flag on the main <table> node so it's not executed anymore. We can't really remove it because if we remove it, we'll have to add all the new children to this node's parent node. However, the 'modify' method is currently processing the parent node and has made a copy of the list of children (to avoid a concurrent modification exception). This means that any children added to the parent node won't have 'modify' called on them. And if any of the children are examples, then they won't be processed properly. */ commandCall.setBypassExecution(true); ListSupport listSupport = new ListSupport(commandCall); for (ListEntry listEntry : listSupport.getListEntries()) { commandCall.setElement(listEntry.getElement()); if (listEntry.isItem()) { CommandCall itemCommand = duplicateCommandForDifferentElement(commandCall, listEntry.getElement()); itemCommand.setConstantForExecution(LEVEL_VARIABLE, getLevel(commandCall)); itemCommand.transferToParent(commandCall); } if (listEntry.isList()) { // recursive call CommandCall itemCommand = duplicateCommandForDifferentElement(commandCall, listEntry.getElement()); itemCommand.setConstantForExecution(LEVEL_VARIABLE, getLevel(commandCall) + 1); itemCommand.transferToParent(commandCall); } } }
public void modifyTree(List<ExampleCommandCall> examples, List<CommandCall> beforeExamples) { this.getCommand().modifyCommandCallTree(this, examples, beforeExamples); List<CommandCall> childrenCopy = new ArrayList(getChildren().asCollection()); for (CommandCall childCall: childrenCopy) { childCall.modifyTree(examples, beforeExamples); } }
CommandCallList childrenCalls = commandCall.getChildren(); columnCommand.verify(evaluator, backgroundResultRecorder, fixture); String matchingRole = columnCommand.getParameter("matchingRole", "matching-role"); if (matchingRole != null && matchingRole.equalsIgnoreCase("key")) { total += backgroundResultRecorder.getTotalCount();
Check.isFalse(commandIsAssigned, "Multiple commands per element is currently not supported."); String expression = attribute.getValue(); commandCall = new CommandCall(parentCommandCall, command, new Element(xomElement), expression, resource); break; parentCommandCall.appendChild(commandCall); parentCommandCall = commandCall; commandCall.setParameters(params);
private void executeTable(final CommandCall commandCall, final Evaluator evaluator, final ResultRecorder resultRecorder) { final TableSupport tableSupport = new TableSupport(commandCall); // this is the bit that's different: also execute on the header tableRow.set(TableRow.HEADER); final Row headerRow = tableSupport.getLastHeaderRow(); commandCall.setElement(headerRow.getElement()); commandCall.execute(evaluator, resultRecorder); // the rest is copied from Concordion's original implementation tableRow.set(TableRow.BODY); final Row[] detailRows = tableSupport.getDetailRows(); for (final Row detailRow : detailRows) { if (detailRow.getCells().length != tableSupport.getColumnCount()) { throw new RuntimeException("The <table> 'execute' command only supports rows with an equal number of columns."); } commandCall.setElement(detailRow.getElement()); tableSupport.copyCommandCallsTo(detailRow); commandCall.execute(evaluator, resultRecorder); } tableRow.set(null); }
public List<String> getExampleNames() { List<String> examples = new ArrayList<String>(); if (hasExampleCommandNodes()) { if (!rootCommandNode.getChildren().isEmpty()) { // Add the main spec first to increase the chance that it will be run first by jUnit. examples.add(OUTER_EXAMPLE_NAME); } for (ExampleCommandCall exampleCall : this.examples) { examples.add(exampleCall.getExampleName()); } } return examples; }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { // Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'assertTrue' is not supported"); CommandCallList childCommands = commandCall.getChildren(); childCommands.setUp(evaluator, resultRecorder, fixture); childCommands.execute(evaluator, resultRecorder, fixture); childCommands.verify(evaluator, resultRecorder, fixture); String expression = commandCall.getExpression(); Object result = evaluator.evaluate(expression); if (result != null && result instanceof Boolean) { if ((Boolean) result) { processTrueResult(commandCall, resultRecorder); } else { processFalseResult(commandCall, resultRecorder); } } else { throw new InvalidExpressionException("Expression '" + expression + "' did not produce a boolean result (needed for assertTrue)."); } }
command.setRunnerFactory(new SystemPropertiesRunnerFactory()); final CommandCall commandCall = new CommandCall(null, command, element, "concordion", resource); commandCall.execute(null, recorder, new FixtureInstance(Object.class)); } catch (FailFastException ffe) { System.out.println("Caught fail fast exception thrown by the fixture under test. Ignoring...");