use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testGetSiteMembershipsWhereSiteVisibilityPrivate.
public void testGetSiteMembershipsWhereSiteVisibilityPrivate() throws Exception {
// paging
int totalResults = 1;
Paging paging = getPaging(null, null, totalResults, totalResults);
// list sites
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson41(null, SiteVisibility.PRIVATE.name());
// check results
List<MemberOfSite> expectedList = getPersonSites(person41, site41);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testGetSiteMembershipsWhereSiteVisibilityModerated.
public void testGetSiteMembershipsWhereSiteVisibilityModerated() throws Exception {
// paging
int totalResults = 1;
Paging paging = getPaging(null, null, totalResults, totalResults);
// list sites
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson41(null, SiteVisibility.MODERATED.name());
// check results
List<MemberOfSite> expectedList = getPersonSites(person41, site44);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSortingAndPagingBySiteIdAsc.
/**
* Tests the capability to sort and paginate the site memberships associated
* to a user orderBy = id ASC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingBySiteIdAsc() throws Exception {
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(paging, "id", true);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site2, site2_role));
expectedList.add(new MemberOfSite(site3, site3_role));
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testPersonSites.
@Test
public void testPersonSites() throws Exception {
Set<MemberOfSite> personSites = new TreeSet<MemberOfSite>();
// Get last site for use with personRemoveSite
TestSite personRemoveSite = sites.get(sites.size() - 1);
sites.remove(sites.size() - 1);
personSites.addAll(network1.getSiteMemberships(person11.getId()));
// Create some sites
personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {
@Override
public List<MemberOfSite> doWork() throws Exception {
List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
site = network1.createSite(SiteVisibility.PUBLIC);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
site = network1.createSite(SiteVisibility.MODERATED);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
return expectedSites;
}
}, person11.getId(), network1.getId()));
personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {
@Override
public List<MemberOfSite> doWork() throws Exception {
List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
site = network1.createSite(SiteVisibility.PUBLIC);
site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
site = network1.createSite(SiteVisibility.MODERATED);
site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
return expectedSites;
}
}, person12.getId(), network1.getId()));
final List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>(personSites);
Sites sitesProxy = publicApiClient.sites();
// unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSites(GUID.generate(), null);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-2200
// Test Case cloud-2213
// user should be able to list their sites
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 2;
int maxItems = 8;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// a user in another tenant should not be able to list a user's sites
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// Test case cloud-1488
{
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
MemberOfSite ret = sitesProxy.getPersonSite(person11.getId(), memberOfSite.getSiteId());
memberOfSite.expected(ret);
}
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(person11.getId(), GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown person id
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(person11.getId(), GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
{
// Tests removing a person from the site
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.remove("people", person11.getId(), "sites", personRemoveSite.getSiteId(), "Unable to DELETE a person site");
try {
sitesProxy.getPersonSite(person11.getId(), personRemoveSite.getSiteId());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
// Not allowed methods
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.create("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to POST to a person site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.create("people", person11.getId(), "sites", null, null, "Unable to POST to person sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.update("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to PUT a person site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.update("people", person11.getId(), "sites", null, null, "Unable to PUT person sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.remove("people", person11.getId(), "sites", null, "Unable to DELETE person sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite 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;
}
Aggregations