private static void checkIndex(File fileAtA, File fileAtB, boolean deleted) throws GetFailedException,
NoSessionException {
UserProfile userProfileA = network.get(0).getSession().getProfileManager()
.getUserProfile(UUID.randomUUID().toString(), false);
Path relativePathA = rootA.toPath().relativize(fileAtA.toPath());
Index indexA = userProfileA.getFileByPath(relativePathA);
UserProfile userProfileB = network.get(1).getSession().getProfileManager()
.getUserProfile(UUID.randomUUID().toString(), false);
Path relativePathB = rootB.toPath().relativize(fileAtB.toPath());
Index indexB = userProfileB.getFileByPath(relativePathB);
// in case of deletion verify removed index nodes
if (deleted) {
Assert.assertNull(indexA);
Assert.assertNull(indexB);
return;
}
// check if content protection keys are the same
Assert.assertTrue(indexA.getProtectionKeys().getPrivate()
.equals(indexB.getProtectionKeys().getPrivate()));
Assert.assertTrue(indexA.getProtectionKeys().getPublic()
.equals(indexB.getProtectionKeys().getPublic()));
// check if isShared flag is set
Assert.assertTrue(indexA.isShared());
Assert.assertTrue(indexB.isShared());
// check write access
Assert.assertTrue(indexA.canWrite());
Assert.assertTrue(indexB.canWrite());
// check user permissions at A
Set<String> usersA = indexA.getCalculatedUserList();
Assert.assertEquals(2, usersA.size());
Assert.assertTrue(usersA.contains(userA.getUserId()));
Assert.assertTrue(usersA.contains(userB.getUserId()));
// check user permissions at A
Set<String> usersB = indexB.getCalculatedUserList();
Assert.assertEquals(2, usersB.size());
Assert.assertTrue(usersB.contains(userA.getUserId()));
Assert.assertTrue(usersB.contains(userB.getUserId()));
// check user permissions in case of a folder at A
if (fileAtA.isDirectory()) {
Assert.assertTrue(indexA.isFolder());
Set<UserPermission> permissions = ((FolderIndex) indexA).getCalculatedUserPermissions();
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.contains(new UserPermission(userA.getUserId(), PermissionType.WRITE)));
Assert.assertTrue(permissions.contains(new UserPermission(userB.getUserId(), PermissionType.WRITE)));
} else {
Assert.assertTrue(indexA.isFile());
}
// check user permissions in case of a folder at B
if (fileAtB.isDirectory()) {
Assert.assertTrue(indexB.isFolder());
Set<UserPermission> permissions = ((FolderIndex) indexB).getCalculatedUserPermissions();
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.contains(new UserPermission(userA.getUserId(), PermissionType.WRITE)));
Assert.assertTrue(permissions.contains(new UserPermission(userB.getUserId(), PermissionType.WRITE)));
} else {
Assert.assertTrue(indexB.isFile());
}
}