@Test
  public void testForeachGroupingBasic() throws Exception {
    Cursor cursor =
        ResultSetWrapper.wrap(
            MockResultSet.create(
                cols("A", "B", "C", "D"),
                data(row("A", 1, 3, 1), row("A", 2, 3, 2), row("B", 3, 3, 3), row("B", 4, 3, 4))));

    ForEachNode rootNode = new ForEachNode(null);
    rootNode.setGroupingColumn("a");
    rootNode.setRows(new SimpleExpression("rows"));
    rootNode.setGroupDataObject("group_A");
    ForEachNode aNode = new ForEachNode(null);
    aNode.setRows(new SimpleExpression("group_A"));

    TestingNode rootTestNode = new TestingNode("A");
    rootNode.getChildren().add(rootTestNode);
    rootNode.getChildren().add(aNode);

    TestingNode aTestNode = new TestingNode("B");
    aNode.getChildren().add(aTestNode);

    parameters.put("rows", cursor);

    rootNode.process(context);

    assertEquals(4, aTestNode.getSize());
    verifyResults(aTestNode, 1, 2, 3, 4);

    assertEquals(2, rootTestNode.getSize());
    verifyResults(rootTestNode, "A", "B");
  }
  @Test
  public void testForeachWithoutParams() throws Exception {
    Cursor cursor =
        ResultSetWrapper.wrap(
            MockResultSet.create(
                cols("A", "B", "C", "D"),
                data(
                    row(1, 11, 3, 1),
                    row(1, 11, 3, 2),
                    row(1, 22, 3, 3),
                    row(1, 22, 3, 4),
                    row(2, 33, 3, 5),
                    row(2, 33, 3, 6),
                    row(2, 44, 3, 7),
                    row(2, 44, 3, 8))));

    ForEachNode rootNode = new ForEachNode(null);
    rootNode.setRows(new SimpleExpression("rows"));
    rootNode.setGroupingColumn("A");
    rootNode.setGroupDataObject("group_A");
    ForEachNode aNode = new ForEachNode(null);
    aNode.setRows(new SimpleExpression("group_A"));
    aNode.setGroupingColumn("B");
    aNode.setGroupDataObject("group_B");
    aNode.setVar("A_row");
    ForEachNode bNode = new ForEachNode(null);
    bNode.setRows(new SimpleExpression("group_B"));
    bNode.setVar("B_row");

    rootNode.getChildren().add(aNode);

    TestingNode aTestNode = new TestingNode("group_A.first() ? A_row.B : \"\"");
    aNode.getChildren().add(aTestNode);
    aNode.getChildren().add(bNode);

    TestingNode bTestNode = new TestingNode("group_B.last() ? B_row.D : \"\"");
    bNode.getChildren().add(bTestNode);

    parameters.put("rows", cursor);

    rootNode.process(context);

    assertEquals(8, bTestNode.getSize());
    verifyResults(bTestNode, "", 2, "", 4, "", 6, "", 8);

    assertEquals(4, aTestNode.getSize());
    verifyResults(aTestNode, 11, "", 33, "");
  }