@Test
  public void testExtractToVariables() {
    String sql = "select ORDERTYPE, 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, String> extractVariables = new HashMap<String, String>();
    extractVariables.put("STATUS", "orderStatus");
    executeSQLQueryAction.setExtractVariables(extractVariables);

    executeSQLQueryAction.execute(context);

    Assert.assertNotNull(context.getVariable("${orderStatus}"));
    Assert.assertEquals(context.getVariable("${orderStatus}"), "in_progress");
    Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));
    Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");
    Assert.assertNotNull(context.getVariable("${STATUS}"));
    Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");
  }
  @Test
  public void testExtractMultipleRowValues() {
    String sql = "select distinct STATUS from orders";
    reset(jdbcTemplate);

    List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
    Map<String, Object> resultRow1 = new HashMap<String, Object>();
    Map<String, Object> resultRow2 = new HashMap<String, Object>();
    Map<String, Object> resultRow3 = new HashMap<String, Object>();

    resultRow1.put("ORDERTYPE", "small");
    resultRow1.put("STATUS", "started");
    resultList.add(resultRow1);
    resultRow2.put("ORDERTYPE", null);
    resultRow2.put("STATUS", "in_progress");
    resultList.add(resultRow2);
    resultRow3.put("ORDERTYPE", "big");
    resultRow3.put("STATUS", "finished");
    resultList.add(resultRow3);

    expect(jdbcTemplate.queryForList(sql)).andReturn(resultList);

    replay(jdbcTemplate);

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

    Map<String, String> extractVariables = new HashMap<String, String>();
    extractVariables.put("STATUS", "orderStatus");
    extractVariables.put("ORDERTYPE", "orderType");
    executeSQLQueryAction.setExtractVariables(extractVariables);

    Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();
    List<String> ordertypeValues = new ArrayList<String>();
    ordertypeValues.add("small");
    ordertypeValues.add(CitrusConstants.IGNORE_PLACEHOLDER);
    ordertypeValues.add("big");

    controlResultSet.put("ORDERTYPE", ordertypeValues);

    List<String> statusValues = new ArrayList<String>();
    statusValues.add("started");
    statusValues.add("in_progress");
    statusValues.add("finished");
    controlResultSet.put("STATUS", statusValues);

    executeSQLQueryAction.setControlResultSet(controlResultSet);

    executeSQLQueryAction.execute(context);

    Assert.assertNotNull(context.getVariable("orderType"));
    Assert.assertEquals(context.getVariable("orderType"), "small;NULL;big");
    Assert.assertNotNull(context.getVariable("orderStatus"));
    Assert.assertEquals(context.getVariable("orderStatus"), "started;in_progress;finished");
    Assert.assertNotNull(context.getVariable("ORDERTYPE"));
    Assert.assertEquals(context.getVariable("ORDERTYPE"), "small");
    Assert.assertNotNull(context.getVariable("STATUS"));
    Assert.assertEquals(context.getVariable("STATUS"), "started");
  }
  @Test(expectedExceptions = {CitrusRuntimeException.class})
  public void testExtractToVariablesUnknownColumnMapping() {
    String sql = "select ORDERTYPE, 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, String> extractVariables = new HashMap<String, String>();
    extractVariables.put("UNKNOWN_COLUMN", "orderStatus");
    executeSQLQueryAction.setExtractVariables(extractVariables);

    executeSQLQueryAction.execute(context);
  }