コード例 #1
0
  public void testPageReport() throws Exception {
    MockMartusApp app = MockMartusApp.create();
    FieldSpec[] topFields = {
      FieldSpec.createStandardField(Bulletin.TAGAUTHOR, new FieldTypeNormal()),
      FieldSpec.createCustomField("tag2", "Label 2", new FieldTypeDate()),
    };
    Bulletin b =
        new Bulletin(
            app.getSecurity(),
            new FieldSpecCollection(topFields),
            StandardFieldSpecs.getDefaultBottomSectionFieldSpecs());
    b.set(topFields[0].getTag(), "First");
    b.set(topFields[1].getTag(), "2005-04-07");
    b.set(Bulletin.TAGPRIVATEINFO, "Secret");
    app.saveBulletin(b, app.getFolderDraftOutbox());

    Bulletin b2 =
        new Bulletin(
            app.getSecurity(),
            new FieldSpecCollection(topFields),
            StandardFieldSpecs.getDefaultBottomSectionFieldSpecs());
    b2.set(topFields[0].getTag(), "Second");
    b2.set(topFields[1].getTag(), "2003-03-29");
    b2.set(Bulletin.TAGPRIVATEINFO, "Another secret");
    app.saveBulletin(b2, app.getFolderDraftOutbox());

    ReportFormat rf = new ReportFormat();
    rf.setBulletinPerPage(true);
    rf.setHeaderSection("Header\n");
    rf.setFooterSection("Footer\n");
    rf.setFakePageBreakSection("----\n");
    rf.setDetailSection(
        "TOP:\n"
            + "#foreach($field in $bulletin.getTopFields())\n"
            + "$field.getLocalizedLabel($localization) $field.html($localization)\n"
            + "#end\n"
            + "BOTTOM:\n"
            + "#foreach($field in $bulletin.getBottomFields())\n"
            + "$field.getLocalizedLabel($localization) $field.html($localization)\n"
            + "#end\n"
            + "");
    String expected0 =
        "Header\n"
            + "TOP:\n"
            + "<field:author> First\n"
            + "Label 2 04/07/2005\n"
            + "BOTTOM:\n"
            + "<field:privateinfo> Secret\n"
            + "Footer\n";
    String expected1 =
        "Header\n"
            + "TOP:\n"
            + "<field:author> Second\n"
            + "Label 2 03/29/2003\n"
            + "BOTTOM:\n"
            + "<field:privateinfo> Another secret\n"
            + "Footer\n";

    RunReportOptions options = new RunReportOptions();
    options.includePrivate = true;
    ReportOutput result = runReportOnAppData(rf, app, options);
    assertEquals("Wrong page report output?", expected0, result.getPageText(0));
    assertEquals("Wrong page report output?", expected1, result.getPageText(1));
    assertEquals("Didn't set fake page break?", "----\n", result.getFakePageBreak());
  }