private boolean isExpressionSupportedBy(Evaluator evaluator, String expression) { try { evaluator.evaluate(expression); return true; } catch (RuntimeException e) { return false; } }
public void execute(Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { for (Map.Entry<String, Object> entry: constantsForExecution.entrySet()) { evaluator.setVariable(entry.getKey(), entry.getValue()); } command.execute(this, evaluator, resultRecorder, fixture); }
@Override protected void process(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Runnable runnable) { Object savedTextValue = evaluator.getVariable(TEXT_VARIABLE); Object savedHrefValue = evaluator.getVariable(HREF_VARIABLE); try { evaluator.setVariable(TEXT_VARIABLE, commandCall.getElement().getText()); evaluator.setVariable(HREF_VARIABLE, getHref(commandCall.getElement())); runnable.run(); } finally { evaluator.setVariable(TEXT_VARIABLE, savedTextValue); evaluator.setVariable(HREF_VARIABLE, savedHrefValue); } }
ValidationResult validationResult; if (!StringUtils.isBlank(verificationMethod)) { 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)" ); evaluator.setVariable("#nl_knaw_huygens_httpcommand_result", null); evaluator.setVariable("#nl_knaw_huygens_httpcommand_expectation", null); } else { validationResult = defaultValidator.validate(expectation, requestCommand.getActualResult());
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 { variableValue = evaluator.getVariable(variableName); } catch (Exception e) {
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 { variableValue = evaluator.getVariable(variableName); } catch (Exception e) {
public void execute(Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { for (Map.Entry<String, Object> entry: constantsForExecution.entrySet()) { evaluator.setVariable(entry.getKey(), entry.getValue()); } command.execute(this, evaluator, resultRecorder, fixture); }
@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>"; } } }, "$(", ")", '\\');
@Override protected void process(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Runnable runnable) { Object savedTextValue = evaluator.getVariable(TEXT_VARIABLE); Object savedHrefValue = evaluator.getVariable(HREF_VARIABLE); try { evaluator.setVariable(TEXT_VARIABLE, commandCall.getElement().getText()); evaluator.setVariable(HREF_VARIABLE, getHref(commandCall.getElement())); runnable.run(); } finally { evaluator.setVariable(TEXT_VARIABLE, savedTextValue); evaluator.setVariable(HREF_VARIABLE, savedHrefValue); } }
private void initTestVariables(Evaluator evaluator) { evaluator.setVariable("#arg1", "#arg1"); evaluator.setVariable("#arg2", "#arg2"); evaluator.setVariable("#variable", "variable"); evaluator.setVariable("#arrayVariable", new String[]{"arrayVariable[0]"}); evaluator.setVariable("#mapVariable", singletonMap("key", "#mapVariable['key']")); evaluator.setVariable("#complexVariable", new Complex()); evaluator.setVariable("#chainVariable", new Chain()); }
@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); }
@Override public void execute(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) { commandCall.getChildren().execute(evaluator, resultRecorder); if (!variableName.isEmpty()) { evaluator.setVariable(variableName, requestCommand.getActualResult()); } }
@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 void reportSurplusRows(Fixture fixture) { for (Object surplusRow : actualRows) { evaluator.setVariable(loopVariableName, surplusRow); Row detailRow = tableSupport.addDetailRow(); announceSurplusRow(detailRow.getElement()); tableSupport.copyCommandCallsTo(detailRow); commandCall.getChildren().verify(evaluator, resultRecorder, fixture); } } }
url = httpRequest.getRequestLine().getUri(); if (url.startsWith("#")) { url = "" + evaluator.evaluate(url);
private void reportSurplusRows(Fixture fixture) { for (Object surplusRow : actualRows) { evaluator.setVariable(loopVariableName, surplusRow); Row detailRow = tableSupport.addDetailRow(); announceSurplusRow(detailRow.getElement()); tableSupport.copyCommandCallsTo(detailRow); commandCall.getChildren().verify(evaluator, resultRecorder, fixture); } } }
@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(Fixture fixture) { announceExpressionEvaluated(commandCall.getElement()); for (Row expectedRow : expectedRows) { Object row = findMatchingRow(expectedRow, fixture); tableSupport.copyCommandCallsTo(expectedRow); if (row != null) { evaluator.setVariable(loopVariableName, row); commandCall.getChildren().verify(evaluator, resultRecorder, fixture); actualRows.remove(row); } else { announceMissingRow(expectedRow.getElement()); } } reportSurplusRows(fixture); }
@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(Fixture fixture) { announceExpressionEvaluated(commandCall.getElement()); for (Row expectedRow : expectedRows) { Object row = findMatchingRow(expectedRow, fixture); tableSupport.copyCommandCallsTo(expectedRow); if (row != null) { evaluator.setVariable(loopVariableName, row); commandCall.getChildren().verify(evaluator, resultRecorder, fixture); actualRows.remove(row); } else { announceMissingRow(expectedRow.getElement()); } } reportSurplusRows(fixture); }