Search in sources :

Example 16 with Sites

use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.

the class TestPersonSites method getSiteMembershipsForPersonAndNetwork.

/**
 * Retrieves the site memberships associated to a user.
 *
 * @param paging
 *            The paging object
 * @param params
 *            Public api parameters map.
 * @param person
 *            The test person.
 * @param network
 *            The test network.
 * @return The site memberships associated to the give user.
 * @throws Exception
 */
private ListResponse<MemberOfSite> getSiteMembershipsForPersonAndNetwork(final Paging paging, Map<String, String> params, TestPerson person, TestNetwork network, boolean runAsUserTenant) throws Exception {
    final Sites sitesProxy = publicApiClient.sites();
    publicApiClient.setRequestContext(new RequestContext(network.getId(), person.getId()));
    ListResponse<MemberOfSite> resp;
    if (runAsUserTenant) {
        // get memberships
        resp = TenantUtil.runAsUserTenant(new TenantRunAsWork<ListResponse<MemberOfSite>>() {

            @Override
            public ListResponse<MemberOfSite> doWork() throws Exception {
                ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person.getId(), createParams(paging, params));
                return resp;
            }
        }, person.getId(), network.getId());
    } else {
        resp = sitesProxy.getPersonSites(person.getId(), createParams(paging, params));
    }
    return resp;
}
Also used : TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites)

Example 17 with Sites

use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.

the class TestSites method testGetSiteAndListSites.

@Test
public void testGetSiteAndListSites() throws Exception {
    Sites sitesProxy = publicApiClient.sites();
    // create & get sites (as person 2)
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2Id));
        String siteTitle = "site 1 " + System.currentTimeMillis();
        Site site = new SiteImpl(siteTitle, SiteVisibility.PRIVATE.toString());
        site1 = sitesProxy.createSite(site);
        Site ret = sitesProxy.getSite(site1.getSiteId());
        site1.expected(ret);
        siteTitle = "site 2 " + System.currentTimeMillis();
        site = new SiteImpl(siteTitle, SiteVisibility.PUBLIC.toString());
        site2 = sitesProxy.createSite(site);
        ret = sitesProxy.getSite(site2.getSiteId());
        site2.expected(ret);
        siteTitle = "site 3 " + System.currentTimeMillis();
        site = new SiteImpl(siteTitle, SiteVisibility.MODERATED.toString());
        site3 = sitesProxy.createSite(site);
        ret = sitesProxy.getSite(site3.getSiteId());
        site3.expected(ret);
    }
    List<TestSite> expectedSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<TestSite>>() {

        @Override
        public List<TestSite> doWork() throws Exception {
            List<TestSite> sites = network1.getSites(person1Id);
            return sites;
        }
    }, person1Id, network1.getId());
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        ListResponse<Site> resp = sitesProxy.getSites(createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
        int skipCount = 2;
        int maxItems = Integer.MAX_VALUE;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        ListResponse<Site> resp = sitesProxy.getSites(createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
}
Also used : TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) 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) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

Sites (org.alfresco.rest.api.tests.client.PublicApiClient.Sites)17 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)11 Test (org.junit.Test)11 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)10 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)10 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)6 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)5 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)5 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)5 ArrayList (java.util.ArrayList)4 SiteGroup (org.alfresco.rest.api.tests.client.data.SiteGroup)4 HashMap (java.util.HashMap)3 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)3 List (java.util.List)2 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)2 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)2 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)2 JSONObject (org.json.simple.JSONObject)2 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1