Syncbase { static String getPersonalBlessingString() throws SyncbaseException { try { return Blessings.UserBlessingFromContext(); } catch(VError e) { chainThrow("getting certificates from context", e); throw new AssertionError("never happens"); } } private  Syncbase(); static void init(Options opts); static void executeCallback(Runnable runnable); static Database database(); static void shutdown(); static boolean isLoggedIn(); static User getLoggedInUser(); static void login(final String authToken, final String provider, final LoginCallback cb); static void addScanForUsersInNeighborhood(final ScanNeighborhoodForUsersCallback cb); static void removeScanForUsersInNeighborhood(ScanNeighborhoodForUsersCallback cb); static void removeAllScansForUsersInNeighborhood(); static void advertiseLoggedInUserInNeighborhood(); static void advertiseLoggedInUserInNeighborhood(Iterable<User> usersWhoCanSee); static void stopAdvertisingLoggedInUserInNeighborhood(); static boolean isAdvertisingLoggedInUserInNeighborhood(); static final String USERDATA_NAME; }
@Test public void testCreateAndGetCollections() throws Exception { Database db = createDatabase(); assertNotNull(db); DatabaseHandle.CollectionOptions opts = new DatabaseHandle.CollectionOptions(). setWithoutSyncgroup(true).setPrefix("a"); Collection cxA = db.createCollection(opts); assertNotNull(cxA); assertTrue(idsMatch(getCollectionIds(db), Syncbase.getPersonalBlessingString(), ImmutableList.of("a", Syncbase.USERDATA_NAME))); db.createCollection(opts.setPrefix("b")); assertTrue(idsMatch(getCollectionIds(db), Syncbase.getPersonalBlessingString(), ImmutableList.of("a", "b", Syncbase.USERDATA_NAME))); opts = new DatabaseHandle.CollectionOptions(); db.createCollection(opts.setPrefix("c")); assertTrue(idsMatch(getCollectionIds(db), Syncbase.getPersonalBlessingString(), ImmutableList.of("a", "b", "c", Syncbase.USERDATA_NAME))); Collection secondCxA = db.createCollection(opts.setPrefix("a")); assertFalse(cxA.getId().equals(secondCxA.getId())); assertTrue(idsMatch(getCollectionIds(db), Syncbase.getPersonalBlessingString(), ImmutableList.of("a", "a", "b", "c", Syncbase.USERDATA_NAME))); }
@Test public void testCreateAndGetSyncgroups() throws Exception { Database db = createDatabase(); DatabaseHandle.CollectionOptions opts = new DatabaseHandle.CollectionOptions(); opts.withoutSyncgroup = true; Collection cxA = db.createCollection(opts.setPrefix("a")); Collection cxB = db.createCollection(opts.setPrefix("b")); Collection cxC = db.createCollection(opts.setWithoutSyncgroup(false).setPrefix("c")); assertNotNull(cxA); assertTrue(idsMatch(getSyncgroupIds(db), Syncbase.getPersonalBlessingString(), ImmutableList.of("c"))); db.syncgroup("sg1", ImmutableList.of(cxA)); db.syncgroup("sg2", ImmutableList.of(cxA, cxB, cxC)); assertThat(getSyncgroupIds(db)).containsExactly( new Id(Syncbase.getPersonalBlessingString(), cxC.getSyncgroup().getId().getName()), new Id(Syncbase.getPersonalBlessingString(), "sg1"), new Id(Syncbase.getPersonalBlessingString(), "sg2")); }