@Test
  public void testResultSetScriptValidationWrongValue() {
    String sql = "select ORDERTYPES, STATUS from orders where ID=5";
    reset(jdbcTemplate);

    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("ORDERTYPE", "small");
    resultMap.put("STATUS", "in_progress");

    expect(jdbcTemplate.queryForList(sql)).andReturn(Collections.singletonList(resultMap));

    replay(jdbcTemplate);

    List<String> stmts = Collections.singletonList(sql);
    executeSQLQueryAction.setStatements(stmts);

    ScriptValidationContext scriptValidationContext =
        new ScriptValidationContext(
            "assert rows.size() == 1\n"
                + "assert rows[0] == [ORDERTYPE:'big', STATUS:'in_progress']",
            ScriptTypes.GROOVY);
    executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);

    try {
      executeSQLQueryAction.execute(context);
    } catch (ValidationException e) {
      Assert.assertTrue(e.getCause() instanceof AssertionError);
      return;
    }

    Assert.fail("Missing validation exception due to script validation error");
  }
  @Test
  public void testResultSetScriptValidationCombination() {
    String sql = "select ORDERTYPES, STATUS from orders where ID=5";
    reset(jdbcTemplate);

    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("ORDERTYPE", "small");
    resultMap.put("STATUS", "in_progress");

    expect(jdbcTemplate.queryForList(sql)).andReturn(Collections.singletonList(resultMap));

    replay(jdbcTemplate);

    List<String> stmts = Collections.singletonList(sql);
    executeSQLQueryAction.setStatements(stmts);

    Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();
    controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));
    controlResultSet.put("STATUS", Collections.singletonList("in_progress"));

    executeSQLQueryAction.setControlResultSet(controlResultSet);

    ScriptValidationContext scriptValidationContext =
        new ScriptValidationContext(
            "assert rows.size() == 1\n"
                + "assert rows[0].ORDERTYPE == 'small'\n"
                + "assert rows[0] == [ORDERTYPE:'small', STATUS:'in_progress']",
            ScriptTypes.GROOVY);
    executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);

    executeSQLQueryAction.execute(context);
  }
  @Test
  public void testResultSetScriptValidationMultipleStmts() {
    String sql1 = "select ORDERTYPES, STATUS from orders where ID=5";
    String sql2 = "select ERRORTYPES from types";
    reset(jdbcTemplate);

    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("ORDERTYPE", "small");
    resultMap.put("STATUS", "in_progress");

    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (int i = 1; i < 4; i++) {
      Map<String, Object> columnMap = new HashMap<String, Object>();
      columnMap.put("ID", String.valueOf(i));
      columnMap.put("NAME", "error" + i);

      results.add(columnMap);
    }

    expect(jdbcTemplate.queryForList(sql1)).andReturn(Collections.singletonList(resultMap)).once();
    expect(jdbcTemplate.queryForList(sql2)).andReturn(results).once();

    replay(jdbcTemplate);

    List<String> stmts = new ArrayList<String>();
    stmts.add(sql1);
    stmts.add(sql2);
    executeSQLQueryAction.setStatements(stmts);

    ScriptValidationContext scriptValidationContext =
        new ScriptValidationContext(
            "assert rows.size() == 4\n"
                + "assert rows[0].ORDERTYPE == 'small'\n"
                + "assert rows[0] == [ORDERTYPE:'small', STATUS:'in_progress']\n"
                + "assert rows[1].ID == '1'\n"
                + "assert rows[3].NAME == 'error3'\n",
            ScriptTypes.GROOVY);
    executeSQLQueryAction.setScriptValidationContext(scriptValidationContext);

    executeSQLQueryAction.execute(context);
  }