private boolean isExpressionSupportedBy(Evaluator evaluator, String expression) { try { evaluator.evaluate(expression); return true; } catch (RuntimeException e) { return false; } }
@Override public String lookup(String name) { try { Object value = evaluator.evaluate(name); if (value == null) { return ""; } else { return value.toString(); } } catch (Exception e) { resultRecorder.record(Result.FAILURE); return "<span class=\"failure\">" + e.toString() + "</span>"; } } }, "$(", ")", '\\');
@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); }
url = httpRequest.getRequestLine().getUri(); if (url.startsWith("#")) { url = "" + evaluator.evaluate(url);
@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); } } }
if (methodName.startsWith("set") && methodName.length() > 3 && method.getParameterTypes().length == 1) { String variableName = methodName.substring(3, 4).toLowerCase() + method.getName().substring(4); Object variableValue = evaluator.evaluate(variableName); if (variableValue == null) { try {
if (methodName.startsWith("set") && methodName.length() > 3 && method.getParameterTypes().length == 1) { String variableName = methodName.substring(3, 4).toLowerCase() + method.getName().substring(4); Object variableValue = evaluator.evaluate(variableName); if (variableValue == null) { try {
@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); }
@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); }
@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)."); } }
@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)."); } }
evaluator.setVariable("#nl_knaw_huygens_httpcommand_result", requestCommand.getActualResult()); evaluator.setVariable("#nl_knaw_huygens_httpcommand_expectation", expectation); validationResult = (ValidationResult) evaluator.evaluate( verificationMethod + "(#nl_knaw_huygens_httpcommand_expectation, #nl_knaw_huygens_httpcommand_result)" );