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 void internalTestFindLegacyRecords(Database db) throws Exception {
    MartusCrypto security = MockMartusSecurity.createClient();

    UniversalId uid = UniversalIdForTesting.createDummyUniversalId();
    DatabaseKey legacyKey = DatabaseKey.createLegacyKey(uid);
    db.writeRecord(legacyKey, smallString);
    InputStream inLegacy = db.openInputStream(legacyKey, security);
    assertNotNull("legacy not found?", inLegacy);
    inLegacy.close();

    InputStream inDraft = db.openInputStream(legacyKey, security);
    assertNotNull("draft not found?", inDraft);
    inDraft.close();

    DatabaseKey sealedKey = DatabaseKey.createSealedKey(uid);
    InputStream inSealed = db.openInputStream(sealedKey, security);
    assertNotNull("sealed not found?", inSealed);
    inSealed.close();

    db.deleteAllData();
  }
 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;
 }