use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestPeople method testPagingAndSortingByFirstNameDesc.
/**
* Tests the capability to sort and paginate the list of people orderBy =
* firstName DESC skip = 1, count = 3
*
* @throws Exception
*/
@Test
public void testPagingAndSortingByFirstNameDesc() throws Exception {
publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
// paging
int skipCount = 1;
int maxItems = 3;
int totalResults = 5;
PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// orderBy=firstName DESC
PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName", false, 200);
List<Person> expectedList = new LinkedList<>();
expectedList.add((Person) personBen);
expectedList.add((Person) personAlice);
expectedList.add((Person) personAliceD);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestPeople method testUpdatePersonNonSelfAndNonAdminDisallowed.
@Test
public void testUpdatePersonNonSelfAndNonAdminDisallowed() throws PublicApiException {
// TODO: this is bad, it seems that the test fixture isn't unique per test!?
final String personId = account1PersonIt.next();
final String personToUpdateId = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), personId));
people.update(personToUpdateId, qjson("{ `firstName`:`Updated firstName` }"), 403);
// TODO: temp fix, set back to orig firstName
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
people.update(personToUpdateId, qjson("{ `firstName`:`Bob` }"), 200);
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestPeople method testUpdatePersonEnabled.
@Test
public void testUpdatePersonEnabled() throws PublicApiException {
// Non-admin user ID
final String personId = account3.createUser().getId();
// Use admin user credentials
publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
// Admin can toggle enabled flag: false
{
Boolean enabled = false;
Map<String, String> params = Collections.singletonMap("fields", "enabled");
Person updatedPerson = people.update(personId, qjson("{`enabled`:" + enabled + "}"), params, 200);
assertEquals(enabled, updatedPerson.isEnabled());
}
// Admin can toggle enabled flag: true
{
Boolean enabled = true;
Map<String, String> params = Collections.singletonMap("fields", "enabled");
Person updatedPerson = people.update(personId, qjson("{`enabled`:" + enabled + "}"), params, 200);
assertEquals(enabled, updatedPerson.isEnabled());
}
// -ve test: enabled flag cannot be null/empty
people.update("people", personId, null, null, qjson("{ `enabled`: null }"), null, "Expected 400 response when updating " + personId, 400);
people.update("people", personId, null, null, qjson("{ `enabled`: `` }"), null, "Expected 400 response when updating " + personId, 400);
// Use non-admin user's own credentials
publicApiClient.setRequestContext(new RequestContext(account3.getId(), personId, "password"));
// Non-admin cannot set enabled flag
{
boolean origEnabled = people.getPerson(personId).isEnabled();
Boolean enabled = false;
// The test should change that we can't change this, otherwise it isn't effective
assertNotEquals(origEnabled, enabled);
Map<String, String> params = Collections.singletonMap("fields", "enabled");
people.update(personId, qjson("{`enabled`:" + enabled + "}"), params, 403);
Person me = people.getPerson(personId);
assertEquals("Enabled state shouldn't have changed, but did", origEnabled, me.isEnabled());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testGetSiteMembershipsWithWhereClause.
@Test
public void testGetSiteMembershipsWithWhereClause() throws Exception {
initializePersonAndNetwork4WithSites();
publicApiClient.setRequestContext(new RequestContext(network4.getId(), person41.getId()));
testGetSiteMembershipsWhereSiteVisibilityPrivate();
testGetSiteMembershipsWhereSiteVisibilityPublic();
testGetSiteMembershipsWhereSiteVisibilityPublicAndSkipCount();
testGetSiteMembershipsWhereSiteVisibilityModerated();
testGetSiteMembershipsWhereSiteVisibilityInvalid();
testGetSiteMembershipsWhereSiteVisibilityNOTIncluded();
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestSiteContainers method testSiteContainers.
@Test
public void testSiteContainers() throws Exception {
Sites sitesProxy = publicApiClient.sites();
List<SiteContainer> expectedSiteContainers = network1.getSiteContainers(site1.getSiteId(), person11);
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
skipCount = 2;
maxItems = expectedSiteContainers.size();
paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
skipCount = 2;
maxItems = expectedSiteContainers.size() + 2;
paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
SiteContainer expectedSiteContainer = new SiteContainer(site1.getSiteId(), "test2", null);
SiteContainer sc = sitesProxy.getSingleSiteContainer(site1.getSiteId(), "test2");
check(expectedSiteContainer, sc);
}
// site does not exist
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getSingleSiteContainer("gfyuosfgsf8y7s", "documentLibrary");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// container does not exist
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getSingleSiteContainer(site1.getSiteId(), "container1");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// site containers - site does not exist
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
sitesProxy.getSiteContainers(GUID.generate(), createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// a user in the same network, not invited to the site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> ret = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), ret);
}
// a user in a different network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// TODO a user in the same network, invited to the site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> ret = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), ret);
}
// person invited to site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// invalid methods
try {
sitesProxy.create("sites", site1.getSiteId(), "containers", null, null, "Unable to POST to site containers");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.create("sites", site1.getSiteId(), "containers", "documentLibrary", null, "Unable to POST to a site container");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.update("sites", site1.getSiteId(), "containers", null, null, "Unable to PUT site containers");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.update("sites", site1.getSiteId(), "containers", "documentLibrary", null, "Unable to PUT a site container");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.remove("sites", site1.getSiteId(), "containers", null, "Unable to DELETE site containers");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.remove("sites", site1.getSiteId(), "containers", "documentLibrary", "Unable to DELETE a site container");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// 1481
// user in external network, list site containers
}
Aggregations