private FieldSpec[] getSampleSpecs() {
    GridFieldSpec gridSpec = new GridFieldSpec();
    gridSpec.setTag("grid");

    return 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()),
      gridSpec,
      LegacyCustomFields.createFromLegacy("custom,Custom <label>"),
    };
  }
  protected void setUp() throws Exception {
    super.setUp();
    logger = new LoggerToNull();
    MockMartusSecurity serverSecurity = MockMartusSecurity.createServer();
    coreServer = new MockMartusServer(this);
    coreServer.setSecurity(serverSecurity);
    server = new ServerForMirroring(coreServer, logger);

    clientSecurity1 = MockMartusSecurity.createClient();
    clientSecurity2 = MockMartusSecurity.createOtherClient();

    Database db = coreServer.getWriteableDatabase();

    bhp1 = new BulletinHeaderPacket(clientSecurity1);
    bhp1.setStatus(BulletinConstants.STATUSIMMUTABLE);
    DatabaseKey key1 = bhp1.createKeyWithHeaderStatus(bhp1.getUniversalId());
    bhp1.writeXmlToDatabase(db, key1, false, clientSecurity1);

    bhp2 = new BulletinHeaderPacket(clientSecurity1);
    bhp2.setStatus(BulletinConstants.STATUSIMMUTABLE);
    DatabaseKey key2 = bhp2.createKeyWithHeaderStatus(bhp2.getUniversalId());
    bhp2.writeXmlToDatabase(db, key2, false, clientSecurity1);

    bhp3 = new BulletinHeaderPacket(clientSecurity2);
    bhp3.setStatus(BulletinConstants.STATUSIMMUTABLE);
    DatabaseKey key3 = bhp3.createKeyWithHeaderStatus(bhp3.getUniversalId());
    bhp3.writeXmlToDatabase(db, key3, false, clientSecurity2);

    bhp4 = new BulletinHeaderPacket(clientSecurity2);
    bhp4.setStatus(BulletinConstants.STATUSMUTABLE);
    DatabaseKey key4 = bhp4.createKeyWithHeaderStatus(bhp4.getUniversalId());
    bhp4.writeXmlToDatabase(db, key4, false, clientSecurity2);

    UniversalId fdpUid = FieldDataPacket.createUniversalId(clientSecurity1);
    FieldSpec[] tags = {LegacyCustomFields.createFromLegacy("whatever")};
    FieldDataPacket fdp1 = new FieldDataPacket(fdpUid, new FieldSpecCollection(tags));
    fdp1.writeXmlToClientDatabase(db, false, clientSecurity1);

    UniversalId otherPacketId =
        UniversalIdForTesting.createFromAccountAndPrefix(clientSecurity2.getPublicKeyString(), "X");
    DatabaseKey key = DatabaseKey.createImmutableKey(otherPacketId);
    db.writeRecord(key, "Not a valid packet");
  }
Exemplo n.º 3
0
  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));
  }