Search in sources :

Example 61 with RequestContext

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);
}
Also used : PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 62 with RequestContext

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);
}
Also used : RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 63 with RequestContext

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());
    }
}
Also used : RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Map(java.util.Map) HashMap(java.util.HashMap) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 64 with RequestContext

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();
}
Also used : RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 65 with RequestContext

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
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) SiteContainer(org.alfresco.rest.api.tests.client.data.SiteContainer) Test(org.junit.Test)

Aggregations

RequestContext (org.alfresco.rest.api.tests.client.RequestContext)185 Test (org.junit.Test)174 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)102 JSONObject (org.json.simple.JSONObject)67 HashMap (java.util.HashMap)58 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)52 ArrayList (java.util.ArrayList)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)45 Task (org.activiti.engine.task.Task)44 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)39 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)38 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)36 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)36 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)33 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)26 Person (org.alfresco.rest.api.tests.client.data.Person)25 JSONArray (org.json.simple.JSONArray)25 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)24 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)24 List (java.util.List)23