Search in sources :

Example 11 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestFavouriteSites method testFavouriteSites.

@Test
public void testFavouriteSites() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
    assertTrue(networksIt.hasNext());
    final TestNetwork network1 = networksIt.next();
    assertTrue(networksIt.hasNext());
    final TestNetwork network2 = networksIt.next();
    // Create some users and sites
    final List<TestPerson> people = new ArrayList<TestPerson>();
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network1.createUser();
            people.add(person);
            person = network1.createUser();
            people.add(person);
            person = network1.createUser();
            people.add(person);
            return null;
        }
    }, network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network2.createUser();
            people.add(person);
            person = network2.createUser();
            people.add(person);
            return null;
        }
    }, network2.getId());
    final TestPerson person1 = people.get(0);
    final TestPerson person2 = people.get(1);
    final TestPerson person3 = people.get(2);
    final TestPerson person4 = people.get(3);
    final TestPerson person5 = people.get(3);
    TestSite testSite = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {

        @SuppressWarnings("synthetic-access")
        public TestSite execute() throws Throwable {
            return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

                public TestSite doWork() throws Exception {
                    SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
                    return network1.createSite(siteInfo);
                }
            }, person1.getId(), network1.getId());
        }
    }, false, true);
    TestSite testSite1 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {

        @SuppressWarnings("synthetic-access")
        public TestSite execute() throws Throwable {
            return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

                public TestSite doWork() throws Exception {
                    SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
                    return network1.createSite(siteInfo);
                }
            }, person1.getId(), network1.getId());
        }
    }, false, true);
    TestSite testSite3 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {

        @SuppressWarnings("synthetic-access")
        public TestSite execute() throws Throwable {
            return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

                public TestSite doWork() throws Exception {
                    SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
                    return network1.createSite(siteInfo);
                }
            }, person1.getId(), network1.getId());
        }
    }, false, true);
    TestSite testSite4 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {

        @SuppressWarnings("synthetic-access")
        public TestSite execute() throws Throwable {
            return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

                public TestSite doWork() throws Exception {
                    SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
                    return network1.createSite(siteInfo);
                }
            }, person5.getId(), network2.getId());
        }
    }, false, true);
    Sites sitesProxy = publicApiClient.sites();
    // invalid methods
    try {
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        sitesProxy.create("people", person1.getId(), "favorite-sites", testSite.getSiteId(), fs.toJSON().toString(), "Unable to POST to a favorite-site");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        sitesProxy.update("people", person1.getId(), "favorite-sites", null, fs.toJSON().toString(), "Unable to PUT favorite-sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        sitesProxy.update("people", person1.getId(), "favorite-sites", testSite.getSiteId(), fs.toJSON().toString(), "Unable to PUT a favorite-site");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        sitesProxy.remove("people", person1.getId(), "favorite-sites", null, "Unable to DELETE favorite-sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // unknown user - 404
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        sitesProxy.createFavouriteSite("invalid.user", fs);
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // user from another network - 401 (not able to auth against tenant)
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        sitesProxy.createFavouriteSite(person1.getId(), fs);
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // another user from the same network
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        sitesProxy.createFavouriteSite(person2.getId(), fs);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
    }
    // a member of this site
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        FavouriteSite resp = sitesProxy.createFavouriteSite(person1.getId(), fs);
        fs.expected(resp);
    }
    // add same favourite site
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        sitesProxy.createFavouriteSite(person1.getId(), new FavouriteSite(testSite.getSiteId()));
        fail();
    } catch (PublicApiException e) {
        assertEquals(409, e.getHttpResponse().getStatusCode());
    }
    // "-me" user
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
        FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
        FavouriteSite resp = sitesProxy.createFavouriteSite(org.alfresco.rest.api.People.DEFAULT_USER, fs);
        fs.expected(resp);
        final List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {

            @Override
            public List<FavouriteSite> doWork() throws Exception {
                return repoService.getFavouriteSites(person2);
            }
        }, person2.getId(), network1.getId());
        // check it's there
        int skipCount = 0;
        int maxItems = Integer.MAX_VALUE;
        Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
        sitesProxy.getFavouriteSites(person2.getId(), createParams(paging, null));
    }
    // not a member of this site
    {
        FavouriteSite fs = new FavouriteSite(testSite1.getSiteId());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        FavouriteSite ret = sitesProxy.createFavouriteSite(person1.getId(), fs);
        fs.expected(ret);
    }
    // GET favourite sites
    {
        final List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {

            @Override
            public List<FavouriteSite> doWork() throws Exception {
                return repoService.getFavouriteSites(person1);
            }
        }, person1.getId(), network1.getId());
        // unknown user
        try {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            sitesProxy.getFavouriteSites(GUID.generate(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // authentication: unknown user
        try {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), GUID.generate(), "password"));
            sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        // another user from the same network - 403
        try {
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
            checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
        }
        // another user from another network - 401
        try {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
            sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        // successful GET
        {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
            checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
        }
        // skipCount is greater than the number of favourite sites
        {
            int skipCount = expectedFavouriteSites.size() + 100;
            Paging paging = getPaging(skipCount, null, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            List<FavouriteSite> expected = Collections.emptyList();
            ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
            checkList(expected, paging.getExpectedPaging(), response);
        }
        // "-me-" user
        {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
            checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
        }
    }
    // user is a member of the site which he has favourited
    {
        publicApiClient.setRequestContext(new RequestContext(network2.getId(), person5.getId()));
        List<FavouriteSite> expectedFavouriteSites = new ArrayList<FavouriteSite>(1);
        FavouriteSite fs = new FavouriteSite(testSite4.getSiteId());
        expectedFavouriteSites.add(fs);
        FavouriteSite ret = sitesProxy.createFavouriteSite(person5.getId(), fs);
        fs.expected(ret);
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
        ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person5.getId(), createParams(paging, null));
        checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
    }
    // remove
    {
        // create some favourite sites
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
            FavouriteSite fs = new FavouriteSite(testSite);
            sitesProxy.createFavouriteSite(person3.getId(), fs);
            fs = new FavouriteSite(testSite1);
            sitesProxy.createFavouriteSite(person3.getId(), fs);
        }
        // known user
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            FavouriteSite fs = new FavouriteSite(testSite);
            sitesProxy.removeFavouriteSite(person1.getId(), fs);
            List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {

                @Override
                public List<FavouriteSite> doWork() throws Exception {
                    return repoService.getFavouriteSites(person1);
                }
            }, person1.getId(), network1.getId());
            // check removed
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
            assertFalse(response.getList().contains(fs));
        }
        // unknown user
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            FavouriteSite fs = new FavouriteSite(testSite);
            sitesProxy.removeFavouriteSite(GUID.generate(), fs);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // unknown site
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            FavouriteSite fs = new FavouriteSite(GUID.generate());
            sitesProxy.removeFavouriteSite(person1.getId(), fs);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // try to remove a favourite site that is not a favourite site
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            FavouriteSite fs = new FavouriteSite(testSite3);
            sitesProxy.removeFavouriteSite(person1.getId(), fs);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // "-me-" user
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
            FavouriteSite fs = new FavouriteSite(testSite1);
            sitesProxy.removeFavouriteSite(org.alfresco.rest.api.People.DEFAULT_USER, fs);
            List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {

                @Override
                public List<FavouriteSite> doWork() throws Exception {
                    return repoService.getFavouriteSites(person3);
                }
            }, person3.getId(), network1.getId());
            // check removed
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
            ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person3.getId(), createParams(paging, null));
            assertFalse(response.getList().contains(fs));
        }
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ArrayList(java.util.ArrayList) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FavouriteSite(org.alfresco.rest.api.tests.client.data.FavouriteSite) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Test(org.junit.Test)

Example 12 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite 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)

Example 13 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestFavourites method testPUBLICAPI156.

@Test
public void testPUBLICAPI156() throws Exception {
    // person1's public site
    final TestSite publicSite = person1PublicSites.get(0);
    // person1's public site
    final TestSite publicSite1 = person1PublicSites.get(1);
    // person1's folder
    final NodeRef folderNodeRef = person1PublicFolders.get(0);
    // a file in the folder
    final NodeRef nodeRef = person1PublicDocs.get(1);
    final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
        // invite to another user's public site
        SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
        siteMembershipRequest.setId(publicSite.getSiteId());
        siteMembershipRequest.setMessage("Please can I join your site?");
        siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
        // favourite other users site, folder and file
        Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
        favouritesProxy.createFavourite(person14Id, folderFavourite);
        expectedFavourites.add(folderFavourite);
        Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
        favouritesProxy.createFavourite(person14Id, fileFavourite);
        expectedFavourites.add(fileFavourite);
        final Favourite siteFavourite = makeSiteFavourite(publicSite);
        favouritesProxy.createFavourite(person14Id, siteFavourite);
        expectedFavourites.add(siteFavourite);
        final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
        favouritesProxy.createFavourite(person14Id, siteFavourite1);
        expectedFavourites.add(siteFavourite1);
        sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
        // remove the folder and file
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                repoService.deleteNode(nodeRef);
                repoService.deleteNode(folderNodeRef);
                return null;
            }
        }, person11Id, network1.getId());
        expectedFavourites.remove(folderFavourite);
        expectedFavourites.remove(fileFavourite);
        sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
        // GETs should not return the favourites nor error
        {
            try {
                favouritesProxy.getFavourite(person14Id, folderFavourite.getTargetGuid());
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            try {
                favouritesProxy.getFavourite(person14Id, fileFavourite.getTargetGuid());
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person14Id, createParams(paging, null));
            checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) SiteMembershipRequest(org.alfresco.rest.api.tests.client.data.SiteMembershipRequest) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Test(org.junit.Test)

Example 14 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite 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 15 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestFavourites method testPUBLICAPI141.

@Test
public void testPUBLICAPI141() throws Exception {
    // person1's public site
    final TestSite publicSite = person1PublicSites.get(0);
    // person1's public site
    final TestSite publicSite1 = person1PublicSites.get(1);
    // person1's private site
    final TestSite privateSite = person1PrivateSites.get(0);
    // person1's folder
    final NodeRef folderNodeRef = person1PublicFolders.get(0);
    // a file in the folder
    final NodeRef nodeRef = person1PublicDocs.get(1);
    final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
        // invite to another user's public site
        SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
        siteMembershipRequest.setId(publicSite.getSiteId());
        siteMembershipRequest.setMessage("Please can I join your site?");
        siteMembershipRequestsProxy.createSiteMembershipRequest(person12Id, siteMembershipRequest);
        // favourite other users site, folder and file
        Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
        favouritesProxy.createFavourite(person12Id, folderFavourite);
        Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
        favouritesProxy.createFavourite(person12Id, fileFavourite);
        final Favourite siteFavourite = makeSiteFavourite(publicSite);
        favouritesProxy.createFavourite(person12Id, siteFavourite);
        expectedFavourites.add(siteFavourite);
        final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
        favouritesProxy.createFavourite(person12Id, siteFavourite1);
        expectedFavourites.add(siteFavourite1);
        sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
        // move the folder and file to person1's private site
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                NodeRef documentLibraryNodeRef = privateSite.getContainerNodeRef("documentLibrary");
                repoService.moveNode(folderNodeRef, documentLibraryNodeRef);
                return null;
            }
        }, person11Id, network1.getId());
        try {
            favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid());
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        try {
            favouritesProxy.getFavourite(person12Id, fileFavourite.getTargetGuid());
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
            checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // make the public sites private
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                publicSite.setSiteVisibility(SiteVisibility.PRIVATE);
                publicSite1.setSiteVisibility(SiteVisibility.PRIVATE);
                return null;
            }
        }, person11Id, network1.getId());
        expectedFavourites.remove(siteFavourite1);
        // Given that person2Id is still a member of 'publicSite', they should still have access and therefore
        // it should show up in their favourites. But person2Id is not a member of 'publicSite1', they should
        // not have access and therefore it should not show up in their favourites.
        {
            Favourite actual = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid());
            siteFavourite.expected(actual);
            try {
                favouritesProxy.getFavourite(person12Id, siteFavourite1.getTargetGuid());
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
            checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) SiteMembershipRequest(org.alfresco.rest.api.tests.client.data.SiteMembershipRequest) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Test(org.junit.Test)

Aggregations

TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)47 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)42 Test (org.junit.Test)39 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)35 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)33 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)31 NodeRef (org.alfresco.service.cmr.repository.NodeRef)29 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)27 ArrayList (java.util.ArrayList)23 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)19 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)19 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)19 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)19 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)19 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)19 HashMap (java.util.HashMap)18 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)18 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)17 List (java.util.List)15 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)15