@Test
public void createSyncgroup() {

    Id dbId = new Id("idp:a:angrybirds", "create_syncgroups");
    String dbName = dbId.encode();
    Id sgId = new Id("...", "syncgroup");
    Id collectionId = new Id("...", "collection");
    String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
    try {
        Database.Create(dbName, anyDbPermissions());
        String batchHandle = Database.BeginBatch(dbId.encode(), null);
        Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
        Database.Commit(dbName, batchHandle);
        SyncgroupSpec spec = new SyncgroupSpec();
        spec.collections = singletonList(collectionId);
        spec.permissions = anySyncgroupPermissions();
        SyncgroupMemberInfo info = new SyncgroupMemberInfo();
        // TODO(razvanm): Pick some meaningful values.
        info.syncPriority = 1;
        info.blobDevType = 2;
        Database.CreateSyncgroup(dbName, sgId, spec, info);
        List<Id> syncgroups = Database.ListSyncgroups(dbName);
        assertEquals(1, syncgroups.size());
        Id actual = syncgroups.get(0);
        assertEquals(sgId.blessing, actual.blessing);
        assertEquals(sgId.name, actual.name);
        VersionedSyncgroupSpec verSpec = Database.GetSyncgroupSpec(dbName, sgId);
        assertNotNull(verSpec.version);
        assertTrue(verSpec.version.length() > 0);
        assertNotNull(verSpec.syncgroupSpec);
        assertEquals(1, verSpec.syncgroupSpec.collections.size());
        // The trim is used to remove a new line.
        assertEquals(
                new String(spec.permissions.json),
                new String(verSpec.syncgroupSpec.permissions.json).trim());
        actual = syncgroups.get(0);
        assertEquals(sgId.blessing, actual.blessing);
        assertEquals(sgId.name, actual.name);
        verSpec.syncgroupSpec.description = "Dummy description";
        Database.SetSyncgroupSpec(dbName, sgId, verSpec);
        assertEquals(verSpec.syncgroupSpec.description, Database.GetSyncgroupSpec(dbName, sgId).syncgroupSpec.description);
        Map<String, SyncgroupMemberInfo> members = Database.GetSyncgroupMembers(dbName, sgId);
        assertNotNull(members);
        assertEquals(1, members.size());
        assertTrue(members.keySet().iterator().next().length() > 0);
        assertEquals(info.syncPriority, members.values().iterator().next().syncPriority);
        assertEquals(info.blobDevType, members.values().iterator().next().blobDevType);
    } catch (VError vError) {
        vError.printStackTrace();
        fail(vError.toString());
    }
}