Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.Index


  private static void checkIndexes(File fileAtA, File fileAtB, File movedFile, boolean userA)
      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);

    // should have been deleted
    Assert.assertNull(indexA);
    Assert.assertNull(indexB);
View Full Code Here


  }

  private static void checkMovedIndex(File movedFile, File root, UserProfile userProfile)
      throws GetFailedException, NoSessionException {
    Path relativePath = root.toPath().relativize(movedFile.toPath());
    Index index = userProfile.getFileByPath(relativePath);

    Assert.assertNotNull(index);

    // check isShared flag
    Assert.assertFalse(index.isShared());

    // check if content protection keys are the default content protection key
    Assert.assertTrue(index.getProtectionKeys().getPrivate()
        .equals(userProfile.getProtectionKeys().getPrivate()));
    Assert.assertTrue(index.getProtectionKeys().getPublic()
        .equals(userProfile.getProtectionKeys().getPublic()));

    // check write access
    Assert.assertTrue(index.canWrite());

    // check user permissions
    Set<String> users = index.getCalculatedUserList();
    Assert.assertEquals(1, users.size());
    Assert.assertTrue(users.contains(userProfile.getUserId()));

    // check user permissions in case of a folder
    if (movedFile.isDirectory()) {
      Assert.assertTrue(index.isFolder());
      Set<UserPermission> permissions = ((FolderIndex) index).getCalculatedUserPermissions();
      Assert.assertEquals(1, permissions.size());
      Assert.assertTrue(permissions.contains(new UserPermission(userProfile.getUserId(),
          PermissionType.WRITE)));
    } else {
      Assert.assertTrue(index.isFile());
    }
  }
View Full Code Here

  }

  private static void checkIndex(Path relativePath) throws GetFailedException, NoSessionException {
    UserProfile userProfileA = nodeA.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexA = userProfileA.getFileByPath(relativePath);

    UserProfile userProfileB = nodeB.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexB = userProfileB.getFileByPath(relativePath);

    // check if userA's content protection keys are other ones
    Assert.assertFalse(indexA.getProtectionKeys().getPrivate()
        .equals(userProfileA.getProtectionKeys().getPrivate()));
    Assert.assertFalse(indexA.getProtectionKeys().getPublic()
        .equals(userProfileA.getProtectionKeys().getPublic()));
    // check if user B has no content protection keys
    Assert.assertNull(indexB.getProtectionKeys());

    // check if isShared flag is set
    Assert.assertTrue(indexA.isShared());
    Assert.assertTrue(indexB.isShared());

    // check write access
    Assert.assertTrue(indexA.canWrite());
    // user B has no write access
    Assert.assertFalse(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 (indexA.isFolder()) {
      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.READ)));
    }

    // check user permissions in case of a folder at B
    if (indexB.isFolder()) {
      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.READ)));
    }
View Full Code Here

    // upload the new version
    UseCaseTestUtil.uploadNewVersion(uploader, file);

    // download the file and check if version is newer
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(downloader, userCredentials);
    Index index = userProfile.getFileByPath(file, uploaderRoot);
    File downloaded = UseCaseTestUtil.downloadFile(downloader, index.getFilePublicKey());

    // new content should be latest one
    Assert.assertEquals(newContent, FileUtils.readFileToString(downloaded));

    // check the md5 hash
View Full Code Here

    FileUtils.write(file, "bla", false);
    UseCaseTestUtil.uploadNewVersion(uploader, file);

    // verify that only one version is online
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(downloader, userCredentials);
    Index fileNode = userProfile.getFileByPath(file, uploaderRoot);
    MetaFileSmall metaFileSmall = (MetaFileSmall) UseCaseTestUtil.getMetaFile(downloader,
        fileNode.getFileKeys());
    Assert.assertEquals(1, metaFileSmall.getVersions().size());
  }
View Full Code Here

    UseCaseTestUtil.uploadNewVersion(uploader, file);

    // verify that only one version is online
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(downloader, userCredentials);
    Index fileNode = userProfile.getFileByPath(file, uploaderRoot);
    MetaFileSmall metaFileSmall = (MetaFileSmall) UseCaseTestUtil.getMetaFile(downloader,
        fileNode.getFileKeys());
    Assert.assertEquals(1, metaFileSmall.getVersions().size());
  }
View Full Code Here

  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());
    }
  }
View Full Code Here

    // assert that the file is moved
    Assert.assertTrue(destination.exists());

    // check that the user profile has a correct entry
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Index fileNode = userProfile.getFileByPath(destination, root.toPath());
    Assert.assertNotNull(fileNode);
    Assert.assertEquals(folder.getName(), fileNode.getParent().getName());
  }
View Full Code Here

    // assert that the file is moved
    Assert.assertTrue(destination.exists());

    // check that the user profile has a correct entry
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Index fileNode = userProfile.getFileByPath(destination, root.toPath());
    Assert.assertNotNull(fileNode);
    Assert.assertEquals(userProfile.getRoot(), fileNode.getParent());

    // root contains moved file and empty folder as file
    Assert.assertEquals(2, userProfile.getRoot().getChildren().size());
  }
View Full Code Here

    // assert that the file is moved
    Assert.assertTrue(destination.exists());

    // check that the user profile has a correct entry
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Index fileNode = userProfile.getFileByPath(destination, root.toPath());
    Assert.assertNotNull(fileNode);
    Assert.assertEquals(destFolder.getName(), fileNode.getParent().getName());
  }
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.