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"); }
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(); }