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;
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations