Search in sources :

Example 56 with RequestContext

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

the class TestPeople method testUpdatePersonEnabledNonAdminNotAllowed.

@Test
public void testUpdatePersonEnabledNonAdminNotAllowed() throws PublicApiException {
    final String personId = account3.createUser().getId();
    publicApiClient.setRequestContext(new RequestContext(account3.getId(), personId));
    people.update("people", personId, null, null, "{\n" + "  \"enabled\": \"false\"\n" + "}", null, "Expected 403 response when updating " + personId, 403);
}
Also used : RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 57 with RequestContext

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

the class TestPeople method testUpdatePersonUsingPartialUpdate.

@Test
public void testUpdatePersonUsingPartialUpdate() throws PublicApiException {
    final String personId = account3.createUser().getId();
    publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
    String updatedFirstName = "Updated firstName";
    HttpResponse response = people.update("people", personId, null, null, "{\n" + "  \"firstName\": \"" + updatedFirstName + "\"\n" + "}", null, "Expected 200 response when updating " + personId, 200);
    Person updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertEquals(updatedFirstName, updatedPerson.getFirstName());
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 58 with RequestContext

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

the class TestPeople method testUpdatePersonCanUpdateThemself.

@Test
public void testUpdatePersonCanUpdateThemself() throws PublicApiException {
    final String personId = account1PersonIt.next();
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), personId));
    // Explicitly using the person's ID
    {
        Person updatedPerson = people.update(personId, qjson("{ `firstName`: `Matt` }"), 200);
        assertEquals("Matt", updatedPerson.getFirstName());
    }
    // "-me-" user
    {
        Person updatedPerson = people.update("-me-", qjson("{ `firstName`: `John` }"), 200);
        assertEquals("John", updatedPerson.getFirstName());
    }
    // TODO: temp fix, set back to orig firstName
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
    people.update(personId, qjson("{ `firstName`:`Bill` }"), 200);
    // -ve test: check that required/mandatory/non-null fields cannot be unset (or empty string)
    {
        people.update("people", personId, null, null, qjson("{ `firstName`:`` }"), null, "Expected 400 response when updating " + personId, 400);
        people.update("people", personId, null, null, qjson("{ `email`:`` }"), null, "Expected 400 response when updating " + personId, 400);
        people.update("people", personId, null, null, qjson("{ `emailNotificationsEnabled`:`` }"), null, "Expected 400 response when updating " + personId, 400);
    }
}
Also used : RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 59 with RequestContext

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

the class TestPeople method testPagingAndSortingByFirstNameAsc.

/**
 * Tests the capability to sort and paginate the list of people orderBy =
 * firstName ASC skip = 1, count = 3
 *
 * @throws Exception
 */
@Test
public void testPagingAndSortingByFirstNameAsc() 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 ASC
    PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName", true, 200);
    List<Person> expectedList = new LinkedList<>();
    expectedList.add(personAlice);
    expectedList.add(personAliceD);
    expectedList.add(personBen);
    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 60 with RequestContext

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

the class TestPeople method testPagingAndSortingByFirstNameAndLastName.

/**
 * Tests the capability to sort and paginate the list of people orderBy =
 * both firstName and lastName ASC skip = 1, count = 3
 *
 * @throws Exception
 */
@Test
public void testPagingAndSortingByFirstNameAndLastName() 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,lastName ASC
    PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName,lastName", true, 200);
    List<Person> expectedList = new LinkedList<>();
    expectedList.add((Person) personAliceD);
    expectedList.add((Person) personAlice);
    expectedList.add((Person) personBen);
    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)

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