コード例 #1
0
  @Test
  public void testAddManyDocsToNewCollectionAndRemove() throws ClientException {
    DocumentModel testWorkspace =
        session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace");
    testWorkspace = session.createDocument(testWorkspace);

    List<DocumentModel> files = createTestFiles(session, 3);

    collectionManager.addToNewCollection(COLLECTION_NAME, COLLECTION_DESCRIPTION, files, session);

    assertTrue(session.exists(new PathRef(COLLECTION_FOLDER_PATH)));

    final String newlyCreatedCollectionPath = COLLECTION_FOLDER_PATH + "/" + COLLECTION_NAME;

    DocumentRef newCollectionRef = new PathRef(newlyCreatedCollectionPath);
    assertTrue(session.exists(newCollectionRef));

    DocumentModel newlyCreatedCollection = session.getDocument(newCollectionRef);
    final String newlyCreatedCollectionId = newlyCreatedCollection.getId();

    assertEquals(COLLECTION_NAME, newlyCreatedCollection.getTitle());

    assertEquals(
        COLLECTION_DESCRIPTION, newlyCreatedCollection.getProperty("dc:description").getValue());

    for (DocumentModel file : files) {
      file = session.getDocument(file.getRef());

      Collection collectionAdapter = newlyCreatedCollection.getAdapter(Collection.class);

      assertTrue(collectionAdapter.getCollectedDocumentIds().contains(file.getId()));

      CollectionMember collectionMemberAdapter = file.getAdapter(CollectionMember.class);

      assertTrue(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));
    }

    collectionManager.removeAllFromCollection(newlyCreatedCollection, files, session);

    for (DocumentModel file : files) {
      Collection collectionAdapter = newlyCreatedCollection.getAdapter(Collection.class);

      assertFalse(collectionAdapter.getCollectedDocumentIds().contains(file.getId()));

      CollectionMember collectionMemberAdapter = file.getAdapter(CollectionMember.class);

      assertFalse(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));
    }
  }
コード例 #2
0
  @Test
  public void testAddOneDocToNewCollectionAndRemove() throws Exception {
    DocumentModel testWorkspace =
        session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace");
    testWorkspace = session.createDocument(testWorkspace);
    DocumentModel testFile =
        session.createDocumentModel(testWorkspace.getPathAsString(), TEST_FILE_NAME, "File");
    testFile = session.createDocument(testFile);
    collectionManager.addToNewCollection(
        COLLECTION_NAME, COLLECTION_DESCRIPTION, testFile, session);

    assertTrue(session.exists(new PathRef(COLLECTION_FOLDER_PATH)));

    final String newlyCreatedCollectionPath = COLLECTION_FOLDER_PATH + "/" + COLLECTION_NAME;

    DocumentRef newCollectionRef = new PathRef(newlyCreatedCollectionPath);
    assertTrue(session.exists(newCollectionRef));

    DocumentModel newlyCreatedCollection = session.getDocument(newCollectionRef);
    final String newlyCreatedCollectionId = newlyCreatedCollection.getId();

    assertEquals(COLLECTION_NAME, newlyCreatedCollection.getTitle());

    assertEquals(
        COLLECTION_DESCRIPTION, newlyCreatedCollection.getProperty("dc:description").getValue());

    Collection collectionAdapter = newlyCreatedCollection.getAdapter(Collection.class);

    assertTrue(collectionAdapter.getCollectedDocumentIds().contains(testFile.getId()));

    testFile = session.getDocument(testFile.getRef());

    CollectionMember collectionMemberAdapter = testFile.getAdapter(CollectionMember.class);

    assertTrue(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));

    collectionManager.removeFromCollection(newlyCreatedCollection, testFile, session);

    assertFalse(collectionAdapter.getCollectedDocumentIds().contains(testFile.getId()));
    assertFalse(collectionMemberAdapter.getCollectionIds().contains(newlyCreatedCollectionId));
  }