Search in sources :

Example 6 with Person

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

the class TestPeople method createTestUpdatePerson.

// Create a person for use in the testing of updating custom aspects/props
private Person createTestUpdatePerson() throws PublicApiException {
    Person person = new Person();
    String personId = UUID.randomUUID().toString() + "@" + account1.getId();
    person.setUserName(personId);
    person.setFirstName("Joe");
    person.setEmail(personId);
    person.setEnabled(true);
    person.setPassword("password123");
    person.setDescription("This is a very short bio.");
    person.setProperties(Collections.singletonMap("papi:jabber", "jbloggs@example.com"));
    person.setAspectNames(Collections.singletonList("papi:dessertable"));
    person = people.create(person);
    AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
    NodeRef nodeRef = personService.getPerson(person.getId());
    // Add some non-custom aspects, these should be untouched by the people API.
    nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUDITABLE, null);
    nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "This is a title");
    assertEquals("jbloggs@example.com", person.getProperties().get("papi:jabber"));
    assertEquals(2, person.getAspectNames().size());
    assertTrue(person.getAspectNames().contains("papi:comms"));
    assertTrue(person.getAspectNames().contains("papi:dessertable"));
    return person;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Person(org.alfresco.rest.api.tests.client.data.Person)

Example 7 with Person

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

the class TestPeople method testPagingAndSortingByLastName.

/**
 * Tests the capability to sort and paginate the list of people orderBy =
 * lastName ASC skip = 2, count = 3
 *
 * @throws Exception
 */
@Test
public void testPagingAndSortingByLastName() throws Exception {
    publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
    // paging
    int skipCount = 2;
    int maxItems = 3;
    int totalResults = 5;
    PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
    // orderBy=lastName ASC
    PublicApiClient.ListResponse<Person> resp = listPeople(paging, "lastName", true, 200);
    List<Person> expectedList = new LinkedList<>();
    expectedList.add((Person) personBen);
    expectedList.add((Person) personAliceD);
    expectedList.add((Person) personAlice);
    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 8 with Person

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

the class TestPeople method testUpdatePersonPasswordByThemself.

@Test
public void testUpdatePersonPasswordByThemself() throws PublicApiException {
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
    Person me = new Person();
    me.setId(UUID.randomUUID().toString() + "@" + account1.getId());
    me.setUserName(me.getId());
    me.setFirstName("Jo");
    me.setEmail(me.getId());
    me.setEnabled(true);
    me.setPassword("password123");
    me = people.create(me);
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), me.getId(), "password123"));
    // update with correct oldPassword
    people.update(me.getId(), qjson("{ `oldPassword`:`password123`, `password`:`newpassword456` }"), 200);
    // The old password should no longer work - therefore they are "unauthorized".
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), me.getId(), "password123"));
    people.getPerson(me.getId(), 401);
    // The new password should work.
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), me.getId(), "newpassword456"));
    people.getPerson(me.getId());
    // update with wrong oldPassword
    people.update(me.getId(), qjson("{ `oldPassword`:`password123`, `password`:`newpassword456` }"), 403);
    // update with no oldPassword
    people.update(me.getId(), qjson("{ `password`:`newpassword456` }"), 400);
    people.update(me.getId(), qjson("{ `oldPassword`:``, `password`:`newpassword456` }"), 400);
    people.update(me.getId(), qjson("{ `oldPassword`:null, `password`:`newpassword456` }"), 400);
    // update with no new password
    people.update(me.getId(), qjson("{ `oldPassword`:`newpassword456` }"), 400);
    people.update(me.getId(), qjson("{ `oldPassword`:`newpassword456`, `password`:`` }"), 400);
    people.update(me.getId(), qjson("{ `oldPassword`:`newpassword456`, `password`:null }"), 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 9 with Person

use of org.alfresco.rest.api.tests.client.data.Person 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 10 with Person

use of org.alfresco.rest.api.tests.client.data.Person 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)

Aggregations

Person (org.alfresco.rest.api.tests.client.data.Person)30 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)25 Test (org.junit.Test)24 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)10 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)8 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 ArrayList (java.util.ArrayList)6 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)6 JSONObject (org.json.simple.JSONObject)6 Map (java.util.Map)5 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)5 Serializable (java.io.Serializable)4 List (java.util.List)4 Company (org.alfresco.rest.api.tests.client.data.Company)4 QName (org.alfresco.service.namespace.QName)4 Date (java.util.Date)3 Iterator (java.util.Iterator)3 MimeMessage (javax.mail.internet.MimeMessage)3