Search in sources :

Example 1 with SiteGroup

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

the class TestSiteGroups method shouldCrudSiteGroups.

@Test
public void shouldCrudSiteGroups() throws Exception {
    Sites sitesProxy = publicApiClient.sites();
    try {
        groupName = createAuthorityContext(user1);
        setRequestContext(networkOne.getId(), DEFAULT_ADMIN, DEFAULT_ADMIN_PWD);
        TestSite site = TenantUtil.runAsUserTenant(() -> networkOne.createSite(SiteVisibility.PRIVATE), DEFAULT_ADMIN, networkOne.getId());
        SiteGroup response = sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
        assertEquals(response.getGroup().getId(), groupName);
        assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
        response = sitesProxy.getGroup(site.getSiteId(), groupName);
        assertEquals(response.getGroup().getId(), groupName);
        assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
        assertEquals(siteMembers.getList().size(), 3);
        Map<String, String> params = new HashMap<>(1);
        params.put("where", "(isMemberOfGroup=false)");
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, params));
        assertFalse(siteMembers.getList().get(0).isMemberOfGroup());
        assertEquals(siteMembers.getList().size(), 1);
        params = new HashMap<>(1);
        params.put("where", "(isMemberOfGroup=true)");
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, params));
        assertEquals(siteMembers.getList().size(), 3);
        PublicApiClient.ListResponse<SiteGroup> groups = sitesProxy.getGroups(site.getSiteId(), createParams(paging, null));
        assertEquals(groups.getList().size(), 1);
        assertEquals(groups.getList().get(0).getRole(), SiteRole.SiteCollaborator.name());
        response = sitesProxy.updateGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteContributor.name()));
        groups = sitesProxy.getGroups(site.getSiteId(), createParams(paging, null));
        assertEquals(groups.getList().size(), 1);
        assertEquals(groups.getList().get(0).getRole(), SiteRole.SiteContributor.name());
        sitesProxy.deleteGroup(site.getSiteId(), response.getId());
        groups = sitesProxy.getGroups(site.getSiteId(), createParams(paging, null));
        assertEquals(groups.getList().size(), 0);
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
        assertEquals(siteMembers.getList().size(), 1);
    } finally {
        clearAuthorityContext(groupName);
    }
}
Also used : HashMap(java.util.HashMap) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) SiteGroup(org.alfresco.rest.api.tests.client.data.SiteGroup) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) Test(org.junit.Test)

Example 2 with SiteGroup

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

the class TestSiteGroups method shouldDeleteGroup.

@Test
public void shouldDeleteGroup() throws Exception {
    Sites sitesProxy = publicApiClient.sites();
    try {
        groupName = createAuthorityContext(user1);
        setRequestContext(networkOne.getId(), DEFAULT_ADMIN, DEFAULT_ADMIN_PWD);
        TestSite site = TenantUtil.runAsUserTenant(() -> networkOne.createSite(SiteVisibility.PRIVATE), DEFAULT_ADMIN, networkOne.getId());
        // Should throw 400 error
        try {
            sitesProxy.updateGroup(site.getSiteId(), new SiteGroup(GUID.generate(), SiteRole.SiteCollaborator.name()));
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        SiteGroup response = sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
        assertEquals(response.getGroup().getId(), groupName);
        assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
        assertEquals(siteMembers.getList().size(), 3);
        sitesProxy.deleteGroup(site.getSiteId(), response.getId());
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
        assertEquals(siteMembers.getList().size(), 1);
    } finally {
        clearAuthorityContext(groupName);
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) SiteGroup(org.alfresco.rest.api.tests.client.data.SiteGroup) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) Test(org.junit.Test)

Example 3 with SiteGroup

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

the class TestSiteGroups method shouldAddGroup.

@Test
public void shouldAddGroup() throws Exception {
    Sites sitesProxy = publicApiClient.sites();
    try {
        groupName = createAuthorityContext(user1);
        setRequestContext(networkOne.getId(), DEFAULT_ADMIN, DEFAULT_ADMIN_PWD);
        TestSite site = TenantUtil.runAsUserTenant(() -> networkOne.createSite(SiteVisibility.PRIVATE), DEFAULT_ADMIN, networkOne.getId());
        // Should throw 404 error
        try {
            sitesProxy.addGroup(site.getSiteId(), new SiteGroup(GUID.generate(), SiteRole.SiteCollaborator.name()));
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        SiteGroup response = sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
        assertEquals(response.getGroup().getId(), groupName);
        assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
        // Should throw 409 error
        try {
            sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
        assertEquals(siteMembers.getList().size(), 3);
        PublicApiClient.ListResponse<SiteGroup> groups = sitesProxy.getGroups(site.getSiteId(), createParams(paging, null));
        assertEquals(groups.getList().size(), 1);
        assertEquals(groups.getList().get(0).getRole(), SiteRole.SiteCollaborator.name());
    } finally {
        clearAuthorityContext(groupName);
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) SiteGroup(org.alfresco.rest.api.tests.client.data.SiteGroup) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) Test(org.junit.Test)

Example 4 with SiteGroup

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

the class TestSiteGroups method shouldUpdateGroup.

@Test
public void shouldUpdateGroup() throws Exception {
    Sites sitesProxy = publicApiClient.sites();
    try {
        groupName = createAuthorityContext(user1);
        setRequestContext(networkOne.getId(), DEFAULT_ADMIN, DEFAULT_ADMIN_PWD);
        TestSite site = TenantUtil.runAsUserTenant(() -> networkOne.createSite(SiteVisibility.PRIVATE), DEFAULT_ADMIN, networkOne.getId());
        // Should throw 400 error
        try {
            sitesProxy.updateGroup(site.getSiteId(), new SiteGroup(GUID.generate(), SiteRole.SiteCollaborator.name()));
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        SiteGroup response = sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
        assertEquals(response.getGroup().getId(), groupName);
        assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
        response = sitesProxy.updateGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteContributor.name()));
        assertEquals(response.getGroup().getId(), groupName);
        assertEquals(response.getRole(), SiteRole.SiteContributor.name());
        siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
        assertEquals(siteMembers.getList().size(), 3);
        assertEquals(siteMembers.getList().get(1).getRole(), SiteRole.SiteContributor.name());
        assertEquals(siteMembers.getList().get(2).getRole(), SiteRole.SiteContributor.name());
    } finally {
        clearAuthorityContext(groupName);
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) SiteGroup(org.alfresco.rest.api.tests.client.data.SiteGroup) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) Test(org.junit.Test)

Aggregations

TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)4 Sites (org.alfresco.rest.api.tests.client.PublicApiClient.Sites)4 SiteGroup (org.alfresco.rest.api.tests.client.data.SiteGroup)4 Test (org.junit.Test)4 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)3 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)2 HashMap (java.util.HashMap)1