java: Get most of the JNI internal tests to pass again
As expected, the blessing enforcement that was added by v.io/c/22770
and v.io/c/22771 broke the existing JNI tests. This fixes most of them
by using the '...' as a blessing.
The two current failing tests are:
- UserBlessingFromContext
- AppBlessingFromContext
Both are failing with a v.io/v23/syncbase/util.FoundNoConventionalBlessings
error.
Change-Id: If48f3382a84a554ef6700a2de9af40445cf5641b
diff --git a/syncbase/src/test/java/io/v/syncbase/internal/CollectionTest.java b/syncbase/src/test/java/io/v/syncbase/internal/CollectionTest.java
index a5fb7b5..06f31d2 100644
--- a/syncbase/src/test/java/io/v/syncbase/internal/CollectionTest.java
+++ b/syncbase/src/test/java/io/v/syncbase/internal/CollectionTest.java
@@ -10,9 +10,11 @@
import java.util.Arrays;
import java.util.List;
+import static io.v.syncbase.internal.TestConstants.anyCollectionPermissions;
+import static io.v.syncbase.internal.TestConstants.anyDbPermissions;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -25,17 +27,17 @@
@Test
public void createCollection() {
Id dbId = new Id("idp:a:angrybirds", "create_collection");
- Id collectionId1 = new Id("idp:u:alice", "collection1");
- Id collectionId2 = new Id("idp:u:alice", "collection2");
+ Id collectionId1 = new Id("...", "collection1");
+ Id collectionId2 = new Id("...", "collection2");
try {
- Database.Create(dbId.encode(), null);
+ Database.Create(dbId.encode(), anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
String name1 = Util.NamingJoin(Arrays.asList(dbId.encode(), collectionId1.encode()));
- Collection.Create(name1, batchHandle, null);
+ Collection.Create(name1, batchHandle, anyCollectionPermissions());
String name2 = Util.NamingJoin(Arrays.asList(dbId.encode(), collectionId2.encode()));
- Collection.Create(name2, batchHandle, null);
+ Collection.Create(name2, batchHandle, anyCollectionPermissions());
List<Id> collections = Database.ListCollections(dbId.encode(), batchHandle);
assertNotNull(collections);
@@ -52,12 +54,12 @@
public void destroyCollection() {
Id dbId = new Id("idp:a:angrybirds", "destroy_collection");
String dbName = dbId.encode();
- Id collectionId = new Id("idp:u:alice", "collection");
+ Id collectionId = new Id("...", "collection");
String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Database.Commit(dbName, batchHandle);
batchHandle = Database.BeginBatch(dbName, null);
Collection.Destroy(collectionName, batchHandle);
@@ -71,14 +73,14 @@
public void existsCollection() {
Id dbId = new Id("idp:a:angrybirds", "exists_collection");
String dbName = dbId.encode();
- Id collectionId1 = new Id("idp:u:alice", "collection1");
+ Id collectionId1 = new Id("...", "collection1");
String collectionName1 = Util.NamingJoin(Arrays.asList(dbName, collectionId1.encode()));
- Id collectionId2 = new Id("idp:u:alice", "collection2");
+ Id collectionId2 = new Id("...", "collection2");
String collectionName2 = Util.NamingJoin(Arrays.asList(dbName, collectionId2.encode()));
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
- Collection.Create(collectionName1, batchHandle, null);
+ Collection.Create(collectionName1, batchHandle, anyCollectionPermissions());
// We have not committed the batch yet so Exists should fail.
assertFalse(Collection.Exists(collectionName1, batchHandle));
Database.Commit(dbName, batchHandle);
@@ -95,12 +97,12 @@
public void permissions() {
Id dbId = new Id("idp:a:angrybirds", "permissions_collection");
String dbName = dbId.encode();
- Id collectionId = new Id("idp:u:alice", "collection");
+ Id collectionId = new Id("...", "collection");
String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Permissions permissions = Collection.GetPermissions(collectionName, batchHandle);
assertNotNull(permissions);
String json = new String(permissions.json);
@@ -120,15 +122,15 @@
public void deleteRangeCollection() {
Id dbId = new Id("idp:a:angrybirds", "delete_range_collection");
String dbName = dbId.encode();
- Id collectionId = new Id("idp:u:alice", "collection");
+ Id collectionId = new Id("...", "collection");
String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
String keyName = Util.NamingJoin(Arrays.asList(collectionName, "key"));
// Reference: release/go/src/v.io/v23/vom/testdata/data81/vomdata.vdl
byte[] vomValue = {(byte)0x81, 0x06, 0x03, 'a', 'b', 'c'};
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Row.Put(keyName, batchHandle, vomValue);
Database.Commit(dbName, batchHandle);
diff --git a/syncbase/src/test/java/io/v/syncbase/internal/DatabaseTest.java b/syncbase/src/test/java/io/v/syncbase/internal/DatabaseTest.java
index aa97ff2..9827359 100644
--- a/syncbase/src/test/java/io/v/syncbase/internal/DatabaseTest.java
+++ b/syncbase/src/test/java/io/v/syncbase/internal/DatabaseTest.java
@@ -12,6 +12,9 @@
import java.util.List;
import java.util.Map;
+import static io.v.syncbase.internal.TestConstants.anyCollectionPermissions;
+import static io.v.syncbase.internal.TestConstants.anyDbPermissions;
+import static io.v.syncbase.internal.TestConstants.anySyncgroupPermissions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -32,7 +35,7 @@
// The instance is empty so creating of a database should succeed.
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
} catch (VError vError) {
vError.printStackTrace();
fail(vError.toString());
@@ -41,7 +44,7 @@
// Creating the same database should raise an exception.
boolean exceptionThrown = false;
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
} catch (VError vError) {
assertEquals("v.io/v23/verror.Exist", vError.id);
assertNotNull(vError.message);
@@ -58,7 +61,7 @@
String dbName = dbId.encode();
try {
// The instance is empty so creating of a database should succeed.
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
Database.Destroy(dbName);
} catch (VError vError) {
vError.printStackTrace();
@@ -74,7 +77,7 @@
// We have not created the database yet so Exists should fail.
assertFalse(Database.Exists(dbName));
// The instance is empty so creating of a database should succeed.
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
// Exists should succeed now.
assertTrue(Database.Exists(dbName));
} catch (VError vError) {
@@ -88,7 +91,7 @@
Id dbId = new Id("idp:a:angrybirds", "permissions_db");
String dbName = dbId.encode();
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
VersionedPermissions versionedPermissions1 = Database.GetPermissions(dbName);
assertNotNull(versionedPermissions1);
assertTrue(versionedPermissions1.version.length() > 0);
@@ -109,16 +112,16 @@
public void abortDatabase() {
Id dbId = new Id("idp:a:angrybirds", "abort_db");
String dbName = dbId.encode();
- Id collectionId = new Id("idp:u:alice", "collection");
+ Id collectionId = new Id("...", "collection");
String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbName, null);
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Database.Abort(dbName, batchHandle);
batchHandle = Database.BeginBatch(dbName, null);
// This should work because we Abort the previous batch.
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Database.Commit(dbName, batchHandle);
} catch (VError vError) {
vError.printStackTrace();
@@ -131,7 +134,7 @@
Id dbId = new Id("idp:a:angrybirds", "list_db");
String dbName = dbId.encode();
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbName, null);
assertNotNull(batchHandle);
List<Id> collections = Database.ListCollections(dbName, batchHandle);
@@ -148,7 +151,7 @@
Id dbId = new Id("idp:a:angrybirds", "get_resume_marker");
String dbName = dbId.encode();
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbName, null);
byte[] marker = Database.GetResumeMarker(dbName, batchHandle);
assertNotNull(marker);
@@ -163,16 +166,17 @@
public void createSyncgroup() {
Id dbId = new Id("idp:a:angrybirds", "create_syncgroups");
String dbName = dbId.encode();
- Id sgId = new Id("idp:u:alice", "syncgroup");
- Id collectionId = new Id("idp:u:alice", "collection");
+ Id sgId = new Id("...", "syncgroup");
+ Id collectionId = new Id("...", "collection");
String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Database.Commit(dbName, batchHandle);
Database.SyncgroupSpec spec = new Database.SyncgroupSpec();
spec.collections = Arrays.asList(collectionId);
+ spec.permissions = anySyncgroupPermissions();
Database.SyncgroupMemberInfo info = new Database.SyncgroupMemberInfo();
// TODO(razvanm): Pick some meaningful values.
info.syncPriority = 1;
@@ -189,6 +193,10 @@
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);
@@ -214,7 +222,7 @@
Id dbId = new Id("idp:a:angrybirds", "list_syncgroups");
String dbName = dbId.encode();
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
List<Id> syncgroups = Database.ListSyncgroups(dbName);
assertNotNull(syncgroups);
assertEquals(0, syncgroups.size());
@@ -232,7 +240,7 @@
// TODO(razvanm): We'll have to update this after the destroy lands.
boolean exceptionThrown = false;
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
Database.DestroySyncgroup(dbName, sgId);
} catch (VError vError) {
assertEquals("v.io/v23/verror.NotImplemented", vError.id);
@@ -267,7 +275,7 @@
Id sgId = new Id("idp:u:alice", "syncgroup");
boolean exceptionThrown = false;
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
Database.LeaveSyncgroup(dbName, sgId);
} catch (VError vError) {
assertEquals("v.io/v23/verror.NotImplemented", vError.id);
@@ -283,7 +291,7 @@
Id sgId = new Id("idp:u:alice", "syncgroup");
boolean exceptionThrown = false;
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
Database.EjectFromSyncgroup(dbName, sgId, "");
} catch (VError vError) {
assertEquals("v.io/v23/verror.NotImplemented", vError.id);
diff --git a/syncbase/src/test/java/io/v/syncbase/internal/RowTest.java b/syncbase/src/test/java/io/v/syncbase/internal/RowTest.java
index 03adeac..aaca664 100644
--- a/syncbase/src/test/java/io/v/syncbase/internal/RowTest.java
+++ b/syncbase/src/test/java/io/v/syncbase/internal/RowTest.java
@@ -9,6 +9,8 @@
import java.util.Arrays;
+import static io.v.syncbase.internal.TestConstants.anyCollectionPermissions;
+import static io.v.syncbase.internal.TestConstants.anyDbPermissions;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -24,15 +26,15 @@
public void allTest() {
Id dbId = new Id("idp:a:angrybirds", "collection");
String dbName = dbId.encode();
- Id collectionId = new Id("idp:u:alice", "collection");
+ Id collectionId = new Id("...", "collection");
String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode()));
String keyName = Util.NamingJoin(Arrays.asList(collectionName, "key"));
// Reference: release/go/src/v.io/v23/vom/testdata/data81/vomdata.vdl
byte[] vomValue = {(byte)0x81, 0x06, 0x03, 'a', 'b', 'c'};
try {
- Database.Create(dbName, null);
+ Database.Create(dbName, anyDbPermissions());
String batchHandle = Database.BeginBatch(dbId.encode(), null);
- Collection.Create(collectionName, batchHandle, null);
+ Collection.Create(collectionName, batchHandle, anyCollectionPermissions());
Row.Put(keyName, batchHandle, vomValue);
byte[] r = Row.Get(keyName, batchHandle);
assertArrayEquals(vomValue, r);
diff --git a/syncbase/src/test/java/io/v/syncbase/internal/TestConstants.java b/syncbase/src/test/java/io/v/syncbase/internal/TestConstants.java
new file mode 100644
index 0000000..a0b7615
--- /dev/null
+++ b/syncbase/src/test/java/io/v/syncbase/internal/TestConstants.java
@@ -0,0 +1,26 @@
+// Copyright 2016 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package io.v.syncbase.internal;
+
+public class TestConstants {
+ public static Permissions anyDbPermissions() {
+ Permissions permissions = new Permissions();
+ permissions.json = "{\"Admin\":{\"In\":[\"...\"]},\"Write\":{\"In\":[\"...\"]},\"Read\":{\"In\":[\"...\"]},\"Resolve\":{\"In\":[\"...\"]}}".getBytes();
+ return permissions;
+ }
+
+ public static Permissions anyCollectionPermissions() {
+ Permissions permissions = new Permissions();
+ permissions.json = "{\"Admin\":{\"In\":[\"...\"]},\"Write\":{\"In\":[\"...\"]},\"Read\":{\"In\":[\"...\"]}}".getBytes();
+ return permissions;
+ }
+
+ public static Permissions anySyncgroupPermissions() {
+ Permissions permissions = new Permissions();
+ // The '"NotIn":null' are present to make easier the comparison with what Syncbase returns.
+ permissions.json = "{\"Admin\":{\"In\":[\"...\"],\"NotIn\":null},\"Read\":{\"In\":[\"...\"],\"NotIn\":null}}".getBytes();
+ return permissions;
+ }
+}