public void testTotalsInPageReport() throws Exception { MockMartusApp app = MockMartusApp.create(); app.loadSampleData(); ReportFormat rf = new ReportFormat(); rf.setBulletinPerPage(true); rf.setTotalSection("Totals"); RunReportOptions detailOnly = new RunReportOptions(); detailOnly.hideDetail = false; detailOnly.printBreaks = false; ReportOutput details = runReportOnAppData(rf, app, detailOnly); assertEquals("", details.getPrintableDocument()); RunReportOptions detailAndSummary = new RunReportOptions(); detailAndSummary.hideDetail = false; detailAndSummary.printBreaks = true; ReportOutput both = runReportOnAppData(rf, app, detailAndSummary); assertEquals("Totals", both.getPrintableDocument()); RunReportOptions summaryOnly = new RunReportOptions(); summaryOnly.hideDetail = true; summaryOnly.printBreaks = true; ReportOutput summary = runReportOnAppData(rf, app, summaryOnly); assertEquals("Totals", summary.getPrintableDocument()); }
private void createAndSaveSampleBulletin( MockMartusApp app, String author, String summary, String entryDate) throws Exception { BulletinFolder outbox = app.getFolderDraftOutbox(); Bulletin b = app.createBulletin(); b.set(Bulletin.TAGAUTHOR, author); b.set(Bulletin.TAGSUMMARY, summary); b.set(Bulletin.TAGENTRYDATE, entryDate); app.saveBulletin(b, outbox); }
private MockMartusApp createAppWithBulletinsForBreaks(String sampleDate) throws Exception { MockMartusApp app = MockMartusApp.create(); createAndSaveSampleBulletin(app, "a", "1", sampleDate); createAndSaveSampleBulletin(app, "a", "1", sampleDate); createAndSaveSampleBulletin(app, "a", "2", sampleDate); createAndSaveSampleBulletin(app, "b", "2", sampleDate); return app; }
public void testRunReport() throws Exception { MockMartusApp app = MockMartusApp.create(); app.getLocalization().setCurrentLanguageCode(MiniLocalization.ENGLISH); app.loadSampleData(); BulletinStore store = app.getStore(); ReportFormat rf = new ReportFormat(); rf.setDetailSection("$i. $bulletin.localId\n"); ReportOutput result = new ReportOutput(); Set leafUids = store.getAllBulletinLeafUids(); SortableBulletinList list = new SortableBulletinList(app.getLocalization(), new MiniFieldSpec[0]); Iterator it = leafUids.iterator(); while (it.hasNext()) { DatabaseKey key = DatabaseKey.createLegacyKey((UniversalId) it.next()); list.add(BulletinLoader.loadFromDatabase(store.getDatabase(), key, app.getSecurity())); } RunReportOptions options = new RunReportOptions(); rr.runReport( rf, store.getDatabase(), list, result, options, PoolOfReusableChoicesLists.EMPTY_POOL); result.close(); StringBuffer expected = new StringBuffer(); UniversalId[] uids = list.getSortedUniversalIds(); for (int i = 0; i < uids.length; ++i) { expected.append(Integer.toString(i + 1)); expected.append(". "); expected.append(uids[i].getLocalId()); expected.append("\n"); } assertEquals(new String(expected), result.getPageText(0)); }
private ReportOutput runReportOnAppData( ReportFormat rf, MockMartusApp app, RunReportOptions options, MiniFieldSpec[] sortSpecs) throws IOException, DamagedBulletinException, NoKeyPairException, Exception { BulletinStore store = app.getStore(); MartusCrypto security = app.getSecurity(); ReadableDatabase db = store.getDatabase(); Set leafUids = store.getAllBulletinLeafUids(); MiniLocalization localization = new MiniLocalization(); localization.setCurrentLanguageCode(MiniLocalization.ENGLISH); SortableBulletinList list = new SortableBulletinList(localization, sortSpecs); Iterator it = leafUids.iterator(); while (it.hasNext()) { DatabaseKey key = DatabaseKey.createLegacyKey((UniversalId) it.next()); Bulletin b = BulletinLoader.loadFromDatabase(db, key, security); list.add(b); } ReportOutput result = new ReportOutput(); rr.runReport( rf, store.getDatabase(), list, result, options, PoolOfReusableChoicesLists.EMPTY_POOL); result.close(); return result; }
public void testCustomField() throws Exception { FieldSpec[] specs = new FieldSpec[] { FieldSpec.createStandardField("date", new FieldTypeDate()), FieldSpec.createStandardField("text", new FieldTypeNormal()), FieldSpec.createStandardField("multi", new FieldTypeMultiline()), FieldSpec.createStandardField("range", new FieldTypeDateRange()), FieldSpec.createStandardField("bool", new FieldTypeBoolean()), FieldSpec.createStandardField("language", new FieldTypeLanguage()), LegacyCustomFields.createFromLegacy("custom,Custom <label>"), }; MockMartusApp app = MockMartusApp.create(); app.getLocalization().setCurrentLanguageCode(MiniLocalization.ENGLISH); Bulletin b = new Bulletin(app.getSecurity(), new FieldSpecCollection(specs), new FieldSpecCollection()); String sampleCustomData = "Robert Plant"; b.set("custom", sampleCustomData); b.setAllPrivate(false); app.saveBulletin(b, app.getFolderDraftOutbox()); SortableBulletinList list = new SortableBulletinList(app.getLocalization(), new MiniFieldSpec[0]); list.add(b); ReportFormat rf = new ReportFormat(); rf.setDetailSection("$bulletin.field('custom')"); ReportOutput result = new ReportOutput(); RunReportOptions options = new RunReportOptions(); rr.runReport( rf, app.getStore().getDatabase(), list, result, options, PoolOfReusableChoicesLists.EMPTY_POOL); result.close(); assertEquals(sampleCustomData, result.getPageText(0)); }
private ReportOutput runReportOnSampleData(ReportFormat rf) throws Exception { MockMartusApp app = MockMartusApp.create(); app.loadSampleData(); return runReportOnAppData(rf, app); }
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()); }
private void verifySummaryBreaksOnReusableDropdowns(boolean withDetail) throws Exception, IOException { ReusableChoices choices = new ReusableChoices("choicescode", "Choices Label"); String aLabel = "Fabulous A"; choices.add(new ChoiceItem("a", aLabel)); String bLabel = "Excellent B"; choices.add(new ChoiceItem("b", bLabel)); MockMartusApp app = MockMartusApp.create(); FieldSpecCollection defaultSpecs = app.getStore().getTopSectionFieldSpecs(); FieldSpecCollection specs = new FieldSpecCollection(); for (int i = 0; i < defaultSpecs.size(); ++i) specs.add(defaultSpecs.get(i)); specs.addReusableChoiceList(choices); CustomDropDownFieldSpec dropdown = new CustomDropDownFieldSpec(); dropdown.setTag("dd"); dropdown.setLabel("Dropdown"); dropdown.addReusableChoicesCode(choices.getCode()); specs.add(dropdown); app.getStore().setTopSectionFieldSpecs(specs); Bulletin b1 = app.createBulletin(); b1.set(dropdown.getTag(), "a"); app.saveBulletin(b1, app.getStore().getFolderSaved()); Bulletin b2 = app.createBulletin(); b2.set(dropdown.getTag(), "b"); app.saveBulletin(b2, app.getStore().getFolderSaved()); MiniLocalization localization = new MiniLocalization(); MiniFieldSpec[] sortSpecs = new MiniFieldSpec[] {new MiniFieldSpec(dropdown)}; localization.setCurrentLanguageCode("en"); ReportFormat report = new TabularReportBuilder(localization).createTabular(sortSpecs); ReportOutput destination = new ReportOutput(); RunReportOptions options = new RunReportOptions(); options.hideDetail = withDetail; options.printBreaks = true; options.includePrivate = true; ReportRunner runner = new ReportRunner(app.getSecurity(), new MiniLocalization()); SortableBulletinList bulletins = new SortableBulletinList(localization, sortSpecs); bulletins.add(b1); bulletins.add(b2); runner.runReport( report, app.getStore().getDatabase(), bulletins, destination, options, specs.getAllReusableChoiceLists()); destination.close(); String result = destination.getPrintableDocument(); assertContains(withDetail + " Wrote code instead of label a?", aLabel, result); assertContains(withDetail + " Wrote code instead of label b?", bLabel, result); }