private static void checkIndex(File oldFileAtA, File oldFileAtB, File newFileAtA, File newFileAtB)
throws GetFailedException, NoSessionException {
UserProfile userProfileA = network.get(0).getSession().getProfileManager()
.getUserProfile(UUID.randomUUID().toString(), false);
Index oldIndexAtA = userProfileA.getFileByPath(rootA.toPath().relativize(oldFileAtA.toPath()));
Index newIndexAtA = userProfileA.getFileByPath(rootA.toPath().relativize(newFileAtA.toPath()));
UserProfile userProfileB = network.get(1).getSession().getProfileManager()
.getUserProfile(UUID.randomUUID().toString(), false);
Index oldIndexAtB = userProfileB.getFileByPath(rootB.toPath().relativize(oldFileAtB.toPath()));
Index newIndexAtB = userProfileB.getFileByPath(rootB.toPath().relativize(newFileAtB.toPath()));
// check if old indexes have been removed
Assert.assertNull(oldIndexAtA);
Assert.assertNull(oldIndexAtB);
// check if content protection keys are the same
Assert.assertTrue(newIndexAtA.getProtectionKeys().getPrivate()
.equals(newIndexAtB.getProtectionKeys().getPrivate()));
Assert.assertTrue(newIndexAtA.getProtectionKeys().getPublic()
.equals(newIndexAtB.getProtectionKeys().getPublic()));
// check if isShared flag is set
Assert.assertTrue(newIndexAtA.isShared());
Assert.assertTrue(newIndexAtB.isShared());
// check write access
Assert.assertTrue(newIndexAtA.canWrite());
Assert.assertTrue(newIndexAtB.canWrite());
// check user permissions at A
Set<String> usersA = newIndexAtA.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 = newIndexAtB.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 (newFileAtA.isDirectory()) {
Assert.assertTrue(newIndexAtA.isFolder());
Set<UserPermission> permissions = ((FolderIndex) newIndexAtA).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(newIndexAtA.isFile());
}
// check user permissions in case of a folder at B
if (newFileAtB.isDirectory()) {
Assert.assertTrue(newIndexAtB.isFolder());
Set<UserPermission> permissions = ((FolderIndex) newIndexAtB).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(newIndexAtB.isFile());
}
}