Esempio n. 1
0
  @Test
  public void testForeachGroupingNested() 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");
    ForEachNode bNode = new ForEachNode(null);
    bNode.setRows(new SimpleExpression("group_B"));

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

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

    TestingNode bTestNode = new TestingNode("D");
    bNode.getChildren().add(bTestNode);

    parameters.put("rows", cursor);

    rootNode.process(context);

    assertEquals(8, bTestNode.getSize());
    verifyResults(bTestNode, 1, 2, 3, 4, 5, 6, 7, 8);

    assertEquals(4, aTestNode.getSize());
    verifyResults(aTestNode, 11, 22, 33, 44);

    assertEquals(2, rootTestNode.getSize());
    verifyResults(rootTestNode, 1, 2);
  }
Esempio n. 2
0
  @Test
  public void testForeachLastOnMiddleFor() 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\") ? A_row.B : \"\"");
    aNode.getChildren().add(aTestNode);
    aNode.getChildren().add(bNode);

    TestingNode bTestNode = new TestingNode("group_B.last(\"B\") ? 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, "");
  }