@Test
  public void addRemoveToFavoritesTest() {
    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);

    favoritesManager.addToFavorites(testFile, session);

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

    assertTrue(favoritesManager.isFavorite(testFile, session));

    favoritesManager.removeFromFavorites(testFile, session);

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

    assertFalse(favoritesManager.isFavorite(testFile, session));
  }
 @Before
 public void setUp() {
   testWorkspace =
       session.createDocumentModel("/default-domain/workspaces", "testWorkspace", "Workspace");
   testWorkspace = session.createDocument(testWorkspace);
   // Create a list of test documents
   listDocuments = createTestFiles(session, 5);
   // Add them in the favorites
   for (DocumentModel doc : listDocuments) {
     favoritesManager.addToFavorites(doc, session);
   }
 }
  @Test
  public void testGetDocumentsFromCollection() throws Exception {
    chain = new OperationChain("test-chain");
    chain.add(GetDocumentsFromFavoritesOperation.ID);

    OperationContext ctx = new OperationContext(session);
    ctx.setInput(listDocuments.get(0));
    PaginableDocumentModelListImpl documentsList =
        (PaginableDocumentModelListImpl) service.run(ctx, chain);
    // Check the result of the operation
    assertNotNull(documentsList);
    assertEquals(listDocuments.size(), documentsList.size());

    // Remove a document from the favorites and check the result of the operation
    favoritesManager.removeFromFavorites(listDocuments.get(0), session);
    listDocuments.remove(0);
    chain = new OperationChain("test-chain-2");
    chain.add(GetDocumentsFromFavoritesOperation.ID);

    ctx = new OperationContext(session);
    ctx.setInput(listDocuments.get(0));
    documentsList = (PaginableDocumentModelListImpl) service.run(ctx, chain);
    // Check the result of the operation
    assertNotNull(documentsList);
    assertEquals(listDocuments.size(), documentsList.size());

    // Remove all documents from the favorites and check the result of the operation
    for (DocumentModel doc : listDocuments) {
      favoritesManager.removeFromFavorites(doc, session);
    }
    chain = new OperationChain("test-chain-3");
    chain.add(GetDocumentsFromFavoritesOperation.ID);

    ctx = new OperationContext(session);
    ctx.setInput(listDocuments.get(0));
    documentsList = (PaginableDocumentModelListImpl) service.run(ctx, chain);
    // Check the result of the operation
    assertNotNull(documentsList);
    assertEquals(0, documentsList.size());
  }
  @OperationMethod
  public DocumentModelList run(DocumentModel context) throws Exception {

    DocumentModel favorites = favoritesManager.getFavorites(context, session);

    Map<String, Object> vars = ctx.getVars();
    vars.put("searchTerm", favorites.getId());
    vars.put("providerName", CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER);

    OperationContext subctx = new OperationContext(ctx.getCoreSession(), vars);

    OperationChain chain = new OperationChain("operation");
    OperationParameters oparams = new OperationParameters(DocumentPageProviderOperation.ID, vars);
    chain.add(oparams);
    return (PaginableDocumentModelListImpl) service.run(subctx, chain);
  }