Search in sources :

Example 1 with FavouriteNode

use of org.alfresco.rest.api.tests.client.data.FavouriteNode in project alfresco-remote-api by Alfresco.

the class TestFavourites method testCreateAndGetFavouriteWithPath.

/**
 * Tests create and get favourite with 'include' parameter.
 *
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites?include=path}
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites/<targetId>?include=path}
 */
@Test
public void testCreateAndGetFavouriteWithPath() throws Exception {
    Map<String, String> includePath = Collections.singletonMap("include", "path");
    // As person12 user
    setRequestContext(network1.getId(), person12Id, "password");
    // person1's folder (Test Folder1)
    final NodeRef folderNodeRef = person1PublicFolders.get(0);
    // a file in the site's document library (Test Doc1)
    final NodeRef nodeRef1 = person1PublicDocs.get(0);
    // a file (Test Doc2) in the folder (Test Folder1)
    final NodeRef nodeRef2 = person1PublicDocs.get(1);
    // person1's public site
    final TestSite publicSite = person1PublicSites.get(0);
    // Favourite the doc (Test Doc1)
    Favourite file1Favourite = makeFileFavourite(nodeRef1.getId());
    file1Favourite = favouritesProxy.createFavourite(person12Id, file1Favourite, includePath);
    FavouriteNode node = ((FileFavouriteTarget) file1Favourite.getTarget()).getDocument();
    assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
    // Check the basic properties (REPO-2827)
    assertEquals("Test Doc1", node.getName());
    assertEquals("Test Doc1 Title", node.getTitle());
    assertEquals("Test Doc1 Description", node.getDescription());
    // Favourite the doc (Test Doc2)
    Favourite file2Favourite = makeFileFavourite(nodeRef2.getId());
    file2Favourite = favouritesProxy.createFavourite(person12Id, file2Favourite);
    node = ((FileFavouriteTarget) file2Favourite.getTarget()).getDocument();
    assertNull("Path info should not be returned by default", node.getPath());
    // Favourite the folder (Test Folder1)
    Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
    folderFavourite = favouritesProxy.createFavourite(person12Id, folderFavourite, includePath);
    node = ((FolderFavouriteTarget) folderFavourite.getTarget()).getFolder();
    assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
    // Favourite the public site
    Favourite siteFavourite = makeSiteFavourite(publicSite);
    siteFavourite = favouritesProxy.createFavourite(person12Id, siteFavourite);
    JSONObject siteJsonObject = siteFavourite.getTarget().toJSON();
    assertNotNull("There should be a site JSON object.", siteJsonObject);
    assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
    // Get single favourite (Test Doc2) with include path
    Favourite favouriteResp = favouritesProxy.getFavourite(person12Id, file2Favourite.getTargetGuid(), includePath);
    node = ((FileFavouriteTarget) favouriteResp.getTarget()).getDocument();
    assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary/Test Folder1", true);
    favouriteResp = favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid(), includePath);
    node = ((FolderFavouriteTarget) favouriteResp.getTarget()).getFolder();
    assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
    favouriteResp = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid(), includePath);
    siteJsonObject = favouriteResp.getTarget().toJSON();
    assertNotNull("There should be a site JSON object.", siteJsonObject);
    assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) FavouriteNode(org.alfresco.rest.api.tests.client.data.FavouriteNode) FileFavouriteTarget(org.alfresco.rest.api.tests.client.data.FileFavouriteTarget) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Test(org.junit.Test)

Example 2 with FavouriteNode

use of org.alfresco.rest.api.tests.client.data.FavouriteNode in project alfresco-remote-api by Alfresco.

the class TestFavourites method testGetFavouritesWithPath.

/**
 * Tests get favourites with 'include' parameter.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites?include=path}
 */
@Test
public void testGetFavouritesWithPath() throws Exception {
    // As person12 user
    setRequestContext(network1.getId(), person12Id, "password");
    // person1's folder (Test Folder1)
    final NodeRef folderNodeRef = person1PublicFolders.get(0);
    // a file (Test Doc2) in the folder (Test Folder1)
    final NodeRef nodeRef = person1PublicDocs.get(1);
    // person1's public site
    final TestSite publicSite = person1PublicSites.get(0);
    // Favourite the doc (Test Doc2)
    Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
    favouritesProxy.createFavourite(person12Id, fileFavourite);
    // Favourite the folder (Test Folder1)
    Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
    favouritesProxy.createFavourite(person12Id, folderFavourite);
    // Favourite the public site
    final Favourite siteFavourite = makeSiteFavourite(publicSite);
    favouritesProxy.createFavourite(person12Id, siteFavourite);
    Paging paging = getPaging(0, 100);
    Map<String, String> otherParams = Collections.singletonMap("include", "path");
    ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, otherParams));
    List<Favourite> actualFavouritesList = resp.getList();
    assertEquals("Incorrect number of entries returned", 3, actualFavouritesList.size());
    actualFavouritesList.forEach(fav -> {
        FavouriteNode node;
        switch(fav.getType()) {
            case FILE:
                {
                    node = ((FileFavouriteTarget) fav.getTarget()).getDocument();
                    assertNotNull("node is null.", node);
                    assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary/Test Folder1", true);
                    break;
                }
            case FOLDER:
                {
                    node = ((FolderFavouriteTarget) fav.getTarget()).getFolder();
                    assertNotNull("node is null.", node);
                    assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
                    break;
                }
            case SITE:
                {
                    JSONObject siteJsonObject = fav.getTarget().toJSON();
                    assertNotNull("There should be a site JSON object.", siteJsonObject);
                    assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
                    break;
                }
        }
    });
    // Get favourites without 'include' option
    resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
    actualFavouritesList = resp.getList();
    assertEquals("Incorrect number of entries returned", 3, actualFavouritesList.size());
    actualFavouritesList.forEach(fav -> {
        FavouriteNode node;
        switch(fav.getType()) {
            case FILE:
                {
                    node = ((FileFavouriteTarget) fav.getTarget()).getDocument();
                    assertNotNull("node is null.", node);
                    assertNull("Path info should not be returned by default", node.getPath());
                    break;
                }
            case FOLDER:
                {
                    node = ((FolderFavouriteTarget) fav.getTarget()).getFolder();
                    assertNotNull("node is null.", node);
                    assertNull("Path info should not be returned by default", node.getPath());
                    break;
                }
            case SITE:
                {
                    JSONObject siteJsonObject = fav.getTarget().toJSON();
                    assertNotNull("There should be a site JSON object.", siteJsonObject);
                    assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
                    break;
                }
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) FolderFavouriteTarget(org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget) FavouriteNode(org.alfresco.rest.api.tests.client.data.FavouriteNode) FileFavouriteTarget(org.alfresco.rest.api.tests.client.data.FileFavouriteTarget) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Test(org.junit.Test)

Aggregations

TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)2 Favourite (org.alfresco.rest.api.tests.client.data.Favourite)2 FavouriteNode (org.alfresco.rest.api.tests.client.data.FavouriteNode)2 FileFavouriteTarget (org.alfresco.rest.api.tests.client.data.FileFavouriteTarget)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)1 FolderFavouriteTarget (org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget)1