public MetaDataIntrospector(Session session) {
   if (session != null) {
     fetcher = new TypeDefinitionFecther((HttpAutomationClient) session.getClient());
   } else {
     // XXX tests !
     fetcher = new TypeDefinitionFecther(null);
   }
 }
示例#2
0
文件: BlobRef.java 项目: mindis/nuxeo
 @Override
 public InputStream getStream() throws IOException {
   if (blob == null) {
     synchronized (this) {
       if (blob == null) {
         blob = session.getFile(ref);
       }
     }
   }
   return blob.getStream();
 }
示例#3
0
 public static void main(String[] args) throws Exception {
   try {
     HttpAutomationClient client =
         new HttpAutomationClient("http://localhost:8080/nuxeo/site/automation");
     Session session = client.getSession("Administrator", "Administrator");
     DocumentService rs = session.getAdapter(DocumentService.class);
     Documents docs = rs.query("SELECT * from Workspace");
     System.out.println(docs);
     for (Document d : docs) {
       System.out.println(
           d.getTitle()
               + " at "
               + d.getLastModified()
               + " facets :"
               + d.getFacets()
               + " token:"
               + d.getChangeToken());
     }
     client.shutdown();
   } catch (RemoteException e) {
     e.printStackTrace();
     System.out.println(e.getRemoteStackTrace());
   }
 }
  @Test
  public void testClientSideUser1() throws Exception {

    // ---------------------------------------------
    // Check active factories
    // ---------------------------------------------
    TopLevelFolderItemFactory topLevelFolderItemFactory =
        fileSystemItemAdapterService.getTopLevelFolderItemFactory();
    assertEquals(
        "org.nuxeo.drive.hierarchy.permission.factory.PermissionTopLevelFactory",
        topLevelFolderItemFactory.getName());

    Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
    assertEquals(5, activeFactories.size());
    assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
    assertTrue(activeFactories.contains("userSyncRootParentFactory"));
    assertTrue(activeFactories.contains("permissionSyncRootFactory"));
    assertTrue(activeFactories.contains("sharedSyncRootParentFactory"));

    // ---------------------------------------------
    // Check top level folder: "Nuxeo Drive"
    // ---------------------------------------------
    Blob topLevelFolderJSON =
        (Blob) clientSession1.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
    assertNotNull(topLevelFolderJSON);

    PermissionTopLevelFolderItem topLevelFolder =
        mapper.readValue(topLevelFolderJSON.getStream(), PermissionTopLevelFolderItem.class);

    assertNotNull(topLevelFolder);
    assertEquals(TOP_LEVEL_ID, topLevelFolder.getId());
    assertNull(topLevelFolder.getParentId());
    assertEquals("/" + TOP_LEVEL_ID, topLevelFolder.getPath());
    assertEquals("Nuxeo Drive", topLevelFolder.getName());
    assertTrue(topLevelFolder.isFolder());
    assertEquals("system", topLevelFolder.getCreator());
    assertEquals("system", topLevelFolder.getLastContributor());
    assertFalse(topLevelFolder.getCanRename());
    assertFalse(topLevelFolder.getCanDelete());
    assertFalse(topLevelFolder.getCanCreateChild());

    /**
     *
     *
     * <pre>
     * ===================================================
     * User workspace registered as a synchronization root
     * ===================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs
     *   |     |-- user1File2
     *   |     |-- user1Folder1
     *   |     |     |-- user1File1
     *   |     |     |-- user1Folder2
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs
     *   |     |-- user2Folder1
     *   |     |     |-- user2File1
     *   |     |     |-- user2Folder2
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     *
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.registerSynchronizationRoot(
        session1.getPrincipal(), userWorkspace1, session1);

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    // ---------------------------------------------
    // Check top level folder children
    // ---------------------------------------------
    Blob topLevelChildrenJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", topLevelFolder.getId())
                .execute();

    ArrayNode topLevelChildren =
        mapper.readValue(topLevelChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(topLevelChildren);
    assertEquals(2, topLevelChildren.size());

    // Check "My Docs"
    UserSyncRootParentFolderItem userSyncRootParent =
        mapper.readValue(topLevelChildren.get(0), UserSyncRootParentFolderItem.class);
    assertEquals(userWorkspace1ItemId, userSyncRootParent.getId());
    assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId());
    assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath());
    assertEquals("My Docs", userSyncRootParent.getName());
    assertTrue(userSyncRootParent.isFolder());
    assertEquals("user1", userSyncRootParent.getCreator());
    assertEquals("user1", userSyncRootParent.getLastContributor());
    assertFalse(userSyncRootParent.getCanRename());
    assertFalse(userSyncRootParent.getCanDelete());
    // Can create a child since "My Docs" is the user workspace
    assertTrue(userSyncRootParent.getCanCreateChild());

    // Check "Other Docs"
    SharedSyncRootParentFolderItem sharedSyncRootParent =
        mapper.readValue(topLevelChildren.get(1), SharedSyncRootParentFolderItem.class);
    assertEquals(SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getId());
    assertEquals(TOP_LEVEL_ID, sharedSyncRootParent.getParentId());
    assertEquals(
        "/" + TOP_LEVEL_ID + "/" + SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getPath());
    assertEquals("Other Docs", sharedSyncRootParent.getName());
    assertTrue(sharedSyncRootParent.isFolder());
    assertEquals("system", sharedSyncRootParent.getCreator());
    assertEquals("system", sharedSyncRootParent.getLastContributor());
    assertFalse(sharedSyncRootParent.getCanRename());
    assertFalse(sharedSyncRootParent.getCanDelete());
    assertFalse(sharedSyncRootParent.getCanCreateChild());

    // --------------------------------------------
    // Check user synchronization roots
    // --------------------------------------------
    Blob userSyncRootsJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", userSyncRootParent.getId())
                .execute();

    ArrayNode userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
    assertNotNull(userSyncRoots);
    assertEquals(4, userSyncRoots.size());

    DocumentBackedFolderItem folderItem;
    DocumentBackedFileItem childFileItem;
    DocumentBackedFileItem fileItem;
    DocumentBackedFolderItem childFolderItem;

    JsonNode[] rootNodes = sortNodeByName(userSyncRoots);

    // user1File2
    fileItem = mapper.readValue(rootNodes[0], DocumentBackedFileItem.class);
    checkFileItem(
        fileItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        user1File2,
        userWorkspace1ItemId,
        userWorkspace1ItemPath,
        "user1File2.txt",
        "user1",
        "user1");

    // user1Folder1
    folderItem = mapper.readValue(rootNodes[1], DocumentBackedFolderItem.class);
    checkFolderItem(
        folderItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        user1Folder1,
        userWorkspace1ItemId,
        userWorkspace1ItemPath,
        "user1Folder1",
        "user1",
        "user1");
    Blob folderItemChildrenJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", folderItem.getId())
                .execute();
    ArrayNode folderItemChildren =
        mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(folderItemChildren);
    assertEquals(2, folderItemChildren.size());
    {
      JsonNode[] nodes = sortNodeByName(folderItemChildren);

      // user1File1
      childFileItem = mapper.readValue(nodes[0], DocumentBackedFileItem.class);
      checkFileItem(
          childFileItem,
          DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
          user1File1,
          folderItem.getId(),
          folderItem.getPath(),
          "user1File1.txt",
          "user1",
          "user1");

      // user1Folder2
      childFolderItem = mapper.readValue(nodes[1], DocumentBackedFolderItem.class);
      checkFolderItem(
          childFolderItem,
          DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
          user1Folder2,
          folderItem.getId(),
          folderItem.getPath(),
          "user1Folder2",
          "user1",
          "user1");
    }

    // user1Folder3
    folderItem = mapper.readValue(rootNodes[2], DocumentBackedFolderItem.class);
    checkFolderItem(
        folderItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        user1Folder3,
        userWorkspace1ItemId,
        userWorkspace1ItemPath,
        "user1Folder3",
        "user1",
        "user1");
    {
      folderItemChildrenJSON =
          (Blob)
              clientSession1
                  .newRequest(NuxeoDriveGetChildren.ID)
                  .set("id", folderItem.getId())
                  .execute();
      folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
      assertNotNull(folderItemChildren);
      assertEquals(1, folderItemChildren.size());
      // user1File3
      childFileItem = mapper.readValue(folderItemChildren.get(0), DocumentBackedFileItem.class);
      checkFileItem(
          childFileItem,
          DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
          user1File3,
          folderItem.getId(),
          folderItem.getPath(),
          "user1File3.txt",
          "user1",
          "user1");
    }

    // user1Folder4
    folderItem = mapper.readValue(rootNodes[3], DocumentBackedFolderItem.class);
    checkFolderItem(
        folderItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        user1Folder4,
        userWorkspace1ItemId,
        userWorkspace1ItemPath,
        "user1Folder4",
        "user1",
        "user1");

    // ---------------------------------------------
    // Check shared synchronization roots
    // ---------------------------------------------
    Blob sharedSyncRootsJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", sharedSyncRootParent.getId())
                .execute();

    List<DefaultSyncRootFolderItem> sharedSyncRoots =
        mapper.readValue(
            sharedSyncRootsJSON.getStream(),
            new TypeReference<List<DefaultSyncRootFolderItem>>() {});
    Collections.sort(sharedSyncRoots);

    assertNotNull(sharedSyncRoots);
    assertEquals(2, sharedSyncRoots.size());

    // user2Folder1
    DefaultSyncRootFolderItem sharedSyncRoot = sharedSyncRoots.get(0);
    checkFolderItem(
        sharedSyncRoot,
        SYNC_ROOT_ID_PREFIX,
        session1.getDocument(user2Folder1.getRef()),
        sharedSyncRootParent.getId(),
        sharedSyncRootParent.getPath(),
        "user2Folder1",
        "user2",
        "user1");
    Blob sharedSyncRootChildrenJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", sharedSyncRoot.getId())
                .execute();
    ArrayNode sharedSyncRootChildren =
        mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(sharedSyncRootChildren);
    assertEquals(2, sharedSyncRootChildren.size());
    DocumentBackedFolderItem sharedSyncRootChildFolderItem;
    DocumentBackedFileItem sharedSyncRootChildFileItem;
    {
      JsonNode[] nodes = sortNodeByName(sharedSyncRootChildren);
      // user2File1
      sharedSyncRootChildFileItem = mapper.readValue(nodes[0], DocumentBackedFileItem.class);
      checkFileItem(
          sharedSyncRootChildFileItem,
          DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
          session1.getDocument(user2File1.getRef()),
          sharedSyncRoot.getId(),
          sharedSyncRoot.getPath(),
          "user2File1.txt",
          "user2",
          "user2");
      // user2Folder2
      sharedSyncRootChildFolderItem = mapper.readValue(nodes[1], DocumentBackedFolderItem.class);
      checkFolderItem(
          sharedSyncRootChildFolderItem,
          DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
          session1.getDocument(user2Folder2.getRef()),
          sharedSyncRoot.getId(),
          sharedSyncRoot.getPath(),
          "user2Folder2",
          "user2",
          "user2");
    }
    // user2Folder3
    sharedSyncRoot = sharedSyncRoots.get(1);
    checkFolderItem(
        sharedSyncRoot,
        SYNC_ROOT_ID_PREFIX,
        session1.getDocument(user2Folder3.getRef()),
        sharedSyncRootParent.getId(),
        sharedSyncRootParent.getPath(),
        "user2Folder3",
        "user2",
        "user1");
    sharedSyncRootChildrenJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", sharedSyncRoot.getId())
                .execute();
    sharedSyncRootChildren =
        mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(sharedSyncRootChildren);
    assertEquals(1, sharedSyncRootChildren.size());
    // user2File3
    sharedSyncRootChildFileItem =
        mapper.readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class);
    checkFileItem(
        sharedSyncRootChildFileItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        session1.getDocument(user2File3.getRef()),
        sharedSyncRoot.getId(),
        sharedSyncRoot.getPath(),
        "user2File3.txt",
        "user2",
        "user2");

    /**
     *
     *
     * <pre>
     * =======================================================
     * User workspace NOT registered as a synchronization root
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs
     *   |
     *   |-- Other Docs (unchanged)
     *   |     |-- user2Folder1
     *   |     |     |-- user2File1
     *   |     |     |-- user2Folder2
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     *
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.unregisterSynchronizationRoot(
        session1.getPrincipal(), userWorkspace1, session1);

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ---------------------------------------------
    // Check "My Docs"
    // ---------------------------------------------
    Blob userSyncRootParentJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetFileSystemItem.ID)
                .set("id", userWorkspace1ItemId)
                .execute();
    assertNotNull(userSyncRootParentJSON);

    userSyncRootParent =
        mapper.readValue(userSyncRootParentJSON.getStream(), UserSyncRootParentFolderItem.class);
    assertEquals(userWorkspace1ItemId, userSyncRootParent.getId());
    assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId());
    assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath());
    assertEquals("My Docs", userSyncRootParent.getName());
    assertTrue(userSyncRootParent.isFolder());
    assertEquals("user1", userSyncRootParent.getCreator());
    assertEquals("user1", userSyncRootParent.getLastContributor());
    assertFalse(userSyncRootParent.getCanRename());
    assertFalse(userSyncRootParent.getCanDelete());
    // Cannot create a child since "My Docs" is only the parent of the
    // synchronization roots, not the user workspace
    assertFalse(userSyncRootParent.getCanCreateChild());

    // --------------------------------------------
    // Check user synchronization roots
    // --------------------------------------------
    userSyncRootsJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", userSyncRootParent.getId())
                .execute();

    userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
    assertNotNull(userSyncRoots);
    assertEquals(0, userSyncRoots.size());

    /**
     *
     *
     * <pre>
     * =======================================================
     * User workspace NOT registered as a synchronization root
     * but specific folders yes: user1Folder3, user1Folder4
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs (unchanged)
     *   |     |-- user2Folder1
     *   |     |     |-- user2File1
     *   |     |     |-- user2Folder2
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     *
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder3, session1);
    nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder4, session1);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    // --------------------------------------------
    // Check user synchronization roots
    // --------------------------------------------
    userSyncRootsJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", userSyncRootParent.getId())
                .execute();

    userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
    assertNotNull(userSyncRoots);
    assertEquals(2, userSyncRoots.size());

    // user1Folder3
    folderItem = mapper.readValue(userSyncRoots.get(0), DocumentBackedFolderItem.class);
    checkFolderItem(
        folderItem,
        SYNC_ROOT_ID_PREFIX,
        user1Folder3,
        userWorkspace1ItemId,
        userWorkspace1ItemPath,
        "user1Folder3",
        "user1",
        "user1");
    folderItemChildrenJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", folderItem.getId())
                .execute();
    folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(folderItemChildren);
    assertEquals(1, folderItemChildren.size());
    // user1File3
    childFileItem = mapper.readValue(folderItemChildren.get(0), DocumentBackedFileItem.class);
    checkFileItem(
        childFileItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        user1File3,
        folderItem.getId(),
        folderItem.getPath(),
        "user1File3.txt",
        "user1",
        "user1");
    // user1Folder4
    folderItem = mapper.readValue(userSyncRoots.get(1), DocumentBackedFolderItem.class);
    checkFolderItem(
        folderItem,
        SYNC_ROOT_ID_PREFIX,
        user1Folder4,
        userWorkspace1ItemId,
        userWorkspace1ItemPath,
        "user1Folder4",
        "user1",
        "user1");

    /**
     *
     *
     * <pre>
     * =======================================================
     * Unregister a shared folder: user2Folder1
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs (unchanged)
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     *
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.unregisterSynchronizationRoot(
        session1.getPrincipal(), session1.getDocument(user2Folder1.getRef()), session1);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    // ---------------------------------------------
    // Check shared synchronization roots
    // ---------------------------------------------
    sharedSyncRootsJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", sharedSyncRootParent.getId())
                .execute();

    sharedSyncRoots =
        mapper.readValue(
            sharedSyncRootsJSON.getStream(),
            new TypeReference<List<DefaultSyncRootFolderItem>>() {});
    assertNotNull(sharedSyncRoots);
    assertEquals(1, sharedSyncRoots.size());

    // user2Folder3
    sharedSyncRoot = sharedSyncRoots.get(0);
    checkFolderItem(
        sharedSyncRoot,
        SYNC_ROOT_ID_PREFIX,
        session1.getDocument(user2Folder3.getRef()),
        sharedSyncRootParent.getId(),
        sharedSyncRootParent.getPath(),
        "user2Folder3",
        "user2",
        "user1");
    sharedSyncRootChildrenJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", sharedSyncRoot.getId())
                .execute();
    sharedSyncRootChildren =
        mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(sharedSyncRootChildren);
    assertEquals(1, sharedSyncRootChildren.size());
    // user2File3
    sharedSyncRootChildFileItem =
        mapper.readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class);
    checkFileItem(
        sharedSyncRootChildFileItem,
        DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX,
        session1.getDocument(user2File3.getRef()),
        sharedSyncRoot.getId(),
        sharedSyncRoot.getPath(),
        "user2File3.txt",
        "user2",
        "user2");

    /**
     *
     *
     * <pre>
     * =======================================================
     * Remove permission on a shared folder: user2Folder3
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs (unchanged)
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs
     *
     * </pre>
     */
    resetPermissions(user2Folder3.getRef(), "user1");

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ---------------------------------------------
    // Check shared synchronization roots
    // ---------------------------------------------
    sharedSyncRootsJSON =
        (Blob)
            clientSession1
                .newRequest(NuxeoDriveGetChildren.ID)
                .set("id", sharedSyncRootParent.getId())
                .execute();

    sharedSyncRoots =
        mapper.readValue(
            sharedSyncRootsJSON.getStream(),
            new TypeReference<List<DefaultSyncRootFolderItem>>() {});
    assertNotNull(sharedSyncRoots);
    assertEquals(0, sharedSyncRoots.size());
  }
  @Test
  public void testIntegrationTestsSetupAndTearDown() throws Exception {

    // ---------------------------------------------------------
    // Setup the integration tests environment as Administrator
    // ---------------------------------------------------------
    Blob testUserCredentialsBlob =
        (Blob)
            clientSession
                .newRequest(NuxeoDriveSetupIntegrationTests.ID)
                .set("userNames", "joe,jack")
                .execute();
    assertNotNull(testUserCredentialsBlob);

    // Check test users
    String testUserCredentials = IOUtils.toString(testUserCredentialsBlob.getStream(), "UTF-8");
    assertNotNull(testUserCredentials);
    String[] testUserCrendentialsArray = StringUtils.split(testUserCredentials, ",");
    assertEquals(2, testUserCrendentialsArray.length);
    assertTrue(testUserCrendentialsArray[0].startsWith("nuxeoDriveTestUser_joe:"));
    assertTrue(testUserCrendentialsArray[1].startsWith("nuxeoDriveTestUser_jack:"));

    // useMembersGroup is false by default
    NuxeoPrincipal joePrincipal = userManager.getPrincipal("nuxeoDriveTestUser_joe");
    assertNotNull(joePrincipal);
    assertFalse(joePrincipal.getGroups().contains("members"));
    NuxeoPrincipal jackPrincipal = userManager.getPrincipal("nuxeoDriveTestUser_jack");
    assertNotNull(jackPrincipal);
    assertFalse(jackPrincipal.getGroups().contains("members"));

    // Check test workspace
    DocumentRef testWorkspaceRef = new PathRef(TEST_WORKSPACE_PATH);
    DocumentModel testWorkspace = session.getDocument(testWorkspaceRef);
    assertEquals("Workspace", testWorkspace.getType());
    assertEquals("Nuxeo Drive Test Workspace", testWorkspace.getTitle());
    assertTrue(session.hasPermission(joePrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    assertTrue(session.hasPermission(jackPrincipal, testWorkspaceRef, SecurityConstants.WRITE));

    // Create test users' personal workspaces for cleanup check
    userWorkspaceService.getUserPersonalWorkspace(
        "nuxeoDriveTestUser_joe", session.getRootDocument());
    userWorkspaceService.getUserPersonalWorkspace(
        "nuxeoDriveTestUser_jack", session.getRootDocument());
    assertNotNull(
        session.getDocument(new PathRef(USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-joe")));
    assertNotNull(
        session.getDocument(new PathRef(USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-jack")));

    // ----------------------------------------------------------------------
    // Setup the integration tests environment with other user names without
    // having teared it down previously => should start by cleaning it up
    // ----------------------------------------------------------------------
    testUserCredentialsBlob =
        (Blob)
            clientSession
                .newRequest(NuxeoDriveSetupIntegrationTests.ID)
                .set("userNames", "sarah")
                .set("useMembersGroup", true)
                .execute();
    assertNotNull(testUserCredentialsBlob);

    // Check cleanup
    assertNull(userManager.getPrincipal("nuxeoDriveTestUser_joe"));
    assertNull(userManager.getPrincipal("nuxeoDriveTestUser_jack"));
    // Invalid VCS cache
    session.save();
    try {
      session.getDocument(new PathRef(USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-joe"));
      fail("User workspace should not exist.");
    } catch (ClientException e) {
      assertEquals(
          "Failed to get document " + USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-joe",
          e.getMessage());
    }
    try {
      session.getDocument(new PathRef(USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-jack"));
      fail("User workspace should not exist.");
    } catch (ClientException e) {
      assertEquals(
          "Failed to get document " + USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-jack",
          e.getMessage());
    }

    // Check test users
    testUserCredentials = IOUtils.toString(testUserCredentialsBlob.getStream(), "UTF-8");
    assertNotNull(testUserCredentials);
    testUserCrendentialsArray = StringUtils.split(testUserCredentials, ",");
    assertEquals(1, testUserCrendentialsArray.length);
    assertTrue(testUserCrendentialsArray[0].startsWith("nuxeoDriveTestUser_sarah:"));

    NuxeoPrincipal sarahPrincipal = userManager.getPrincipal("nuxeoDriveTestUser_sarah");
    assertNotNull(sarahPrincipal);
    assertTrue(sarahPrincipal.getGroups().contains("members"));

    // Check test workspace
    testWorkspace = session.getDocument(testWorkspaceRef);
    assertEquals("Nuxeo Drive Test Workspace", testWorkspace.getTitle());
    assertTrue(session.hasPermission(sarahPrincipal, testWorkspaceRef, SecurityConstants.WRITE));

    // Create test users' personal workspaces for cleanup check
    userWorkspaceService.getUserPersonalWorkspace(
        "nuxeoDriveTestUser_sarah", session.getRootDocument());
    assertNotNull(
        session.getDocument(new PathRef(USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-sarah")));

    // ----------------------------------------------------------------------
    // Try to setup the integration tests environment as an unauthorized
    // user => should fail
    // ----------------------------------------------------------------------
    Session unauthorizedSession =
        automationClient.getSession("nuxeoDriveTestUser_sarah", testUserCrendentialsArray[0]);
    try {
      unauthorizedSession
          .newRequest(NuxeoDriveSetupIntegrationTests.ID)
          .set("userNames", "john,bob")
          .execute();
      fail(
          "NuxeoDrive.SetupIntegrationTests operation should not be callable by a non administrator.");
    } catch (Exception e) {
      // Expected
    }

    // ----------------------------------------------------------------------
    // Try to tear down the integration tests environment as an unauthorized
    // user => should fail
    // ----------------------------------------------------------------------
    try {
      unauthorizedSession.newRequest(NuxeoDriveTearDownIntegrationTests.ID).execute();
      fail(
          "NuxeoDrive.TearDownIntegrationTests operation should not be callable by a non administrator.");
    } catch (Exception e) {
      // Expected
    }

    // ----------------------------------------------------------------------
    // Tear down the integration tests environment as Administrator
    // ----------------------------------------------------------------------
    clientSession.newRequest(NuxeoDriveTearDownIntegrationTests.ID).execute();
    assertTrue(userManager.searchUsers("nuxeoDriveTestUser_").isEmpty());
    // Invalid VCS cache
    session.save();
    try {
      session.getDocument(new PathRef(USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-sarah"));
      fail("User workspace should not exist.");
    } catch (ClientException e) {
      assertEquals(
          "Failed to get document " + USER_WORKSPACE_PARENT_PATH + "/nuxeoDriveTestUser-sarah",
          e.getMessage());
    }
    assertFalse(session.exists(testWorkspaceRef));
  }