protected boolean isBeforeExample(CommandCall element) { return element.getExpression().equals("before"); }
protected boolean isBeforeExample(CommandCall element) { return element.getExpression().equals("before"); }
@Override public void setUp(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) { verificationMethod = commandCall.getExpression(); expectation = parseExpectedResponse(commandCall.getElement(), evaluator, resultRecorder); }
@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); }
@SuppressWarnings("unchecked") @Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Pattern pattern = Pattern.compile("(#.+?) *: *(.+)"); Matcher matcher = pattern.matcher(commandCall.getExpression()); if (!matcher.matches()) { throw new RuntimeException("The expression for a \"verifyRows\" should be of the form: #var : collectionExpr"); } String loopVariableName = matcher.group(1); String iterableExpression = matcher.group(2); Object obj = evaluator.evaluate(iterableExpression); Check.notNull(obj, "Expression returned null (should be an Iterable)."); Check.isTrue(obj instanceof Iterable, obj.getClass().getCanonicalName() + " is not Iterable"); Check.isTrue(!(obj instanceof HashSet) || (obj instanceof LinkedHashSet), obj.getClass().getCanonicalName() + " does not have a predictable iteration order"); Iterable<Object> iterable = (Iterable<Object>) obj; newStrategyInstance(detectStrategyClass(commandCall), commandCall, evaluator, resultRecorder, loopVariableName, iterable).verify(fixture); }
@SuppressWarnings("unchecked") @Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Pattern pattern = Pattern.compile("(#.+?) *: *(.+)"); Matcher matcher = pattern.matcher(commandCall.getExpression()); if (!matcher.matches()) { throw new RuntimeException("The expression for a \"verifyRows\" should be of the form: #var : collectionExpr"); } String loopVariableName = matcher.group(1); String iterableExpression = matcher.group(2); Object obj = evaluator.evaluate(iterableExpression); Check.notNull(obj, "Expression returned null (should be an Iterable)."); Check.isTrue(obj instanceof Iterable, obj.getClass().getCanonicalName() + " is not Iterable"); Check.isTrue(!(obj instanceof HashSet) || (obj instanceof LinkedHashSet), obj.getClass().getCanonicalName() + " does not have a predictable iteration order"); Iterable<Object> iterable = (Iterable<Object>) obj; newStrategyInstance(detectStrategyClass(commandCall), commandCall, evaluator, resultRecorder, loopVariableName, iterable).verify(fixture); }
private String getExampleName(CommandCall node) { String exampleName = node.getExpression(); // use the contents of the example if there is no name. if ("".equals(exampleName) && node.getElement().isNamed("td")) { exampleName = node.getElement().getText(); } return exampleName; }
protected CommandCall duplicateCommandForDifferentElement(CommandCall commandCall, Element element) { return new CommandCall( null, commandCall.getCommand(), element, commandCall.getExpression(), commandCall.getResource()); }
protected CommandCall duplicateCommandForDifferentElement(CommandCall commandCall, Element element) { return new CommandCall( null, commandCall.getCommand(), element, commandCall.getExpression(), commandCall.getResource()); }
private String getExampleName(CommandCall node) { String exampleName = node.getExpression(); // use the contents of the example if there is no name. if ("".equals(exampleName) && node.getElement().isNamed("td")) { exampleName = node.getElement().getText(); } return exampleName; }
@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, 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 protected void process(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Runnable runnable) { try { runnable.run(); } catch (FailFastException ffe) { // We get here if a sub-fixture has thrown an exception and we want the fail fast exception to percolate up. rethrowFailFastException(resultRecorder, ffe.getCause()); } catch (Throwable t) { resultRecorder.record(Result.EXCEPTION); announceThrowableCaught(commandCall.getElement(), t, commandCall.getExpression()); rethrowFailFastException(resultRecorder, t); } }
@Override protected void process(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Runnable runnable) { try { runnable.run(); } catch (FailFastException ffe) { // We get here if a sub-fixture has thrown an exception and we want the fail fast exception to percolate up. rethrowFailFastException(resultRecorder, ffe.getCause()); } catch (Throwable t) { resultRecorder.record(Result.EXCEPTION); announceThrowableCaught(commandCall.getElement(), t, commandCall.getExpression()); rethrowFailFastException(resultRecorder, t); } }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'echo' is not supported"); Object result = evaluator.evaluate(commandCall.getExpression()); Element element = commandCall.getElement(); if (result != null) { element.appendText(result.toString()); } else { Element child = new Element("em"); child.appendText("null"); element.appendChild(child); } } }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'echo' is not supported"); Object result = evaluator.evaluate(commandCall.getExpression()); Element element = commandCall.getElement(); if (result != null) { element.appendText(result.toString()); } else { Element child = new Element("em"); child.appendText("null"); element.appendChild(child); } } }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'assertEquals' is not supported"); Element element = commandCall.getElement(); Object actual = evaluator.evaluate(commandCall.getExpression()); String expected = element.getText(); if (comparator.compare(actual, expected) == 0) { resultRecorder.record(Result.SUCCESS); announceSuccess(element); } else { resultRecorder.record(Result.FAILURE); announceFailure(element, expected, actual); } }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'assertEquals' is not supported"); Element element = commandCall.getElement(); Object actual = evaluator.evaluate(commandCall.getExpression()); String expected = element.getText(); if (comparator.compare(actual, expected) == 0) { resultRecorder.record(Result.SUCCESS); announceSuccess(element); } else { resultRecorder.record(Result.FAILURE); announceFailure(element, expected, actual); } }
private void normalExecution(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { CommandCallList childCommands = commandCall.getChildren(); childCommands.setUp(evaluator, resultRecorder, fixture); evaluator.evaluate(commandCall.getExpression()); childCommands.execute(evaluator, resultRecorder, fixture); announceExecuteCompleted(commandCall.getElement()); childCommands.verify(evaluator, resultRecorder, fixture); }
private void normalExecution(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { CommandCallList childCommands = commandCall.getChildren(); childCommands.setUp(evaluator, resultRecorder, fixture); evaluator.evaluate(commandCall.getExpression()); childCommands.execute(evaluator, resultRecorder, fixture); announceExecuteCompleted(commandCall.getElement()); childCommands.verify(evaluator, resultRecorder, fixture); }