use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.
the class TestPeople method testGetPerson_withCustomProps.
@Test
public void testGetPerson_withCustomProps() throws PublicApiException {
// Create the person directly using the Java services - we don't want to test
// the REST API's "create person" function here, so we're isolating this test from it.
MutableAuthenticationService authService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
PreferenceService prefService = applicationContext.getBean("PreferenceService", PreferenceService.class);
Map<QName, Serializable> nodeProps = new HashMap<>();
// The papi:lunchable aspect should be auto-added for the papi:lunch property
nodeProps.put(PROP_LUNCH, "Falafel wrap");
nodeProps.put(PROP_LUNCH_COMMENTS, "");
// These properties should not be present when a person is retrieved
// since they are present as top-level fields.
String userName = "docbrown@" + account1.getId();
nodeProps.put(ContentModel.PROP_USERNAME, userName);
nodeProps.put(ContentModel.PROP_FIRSTNAME, "Doc");
nodeProps.put(ContentModel.PROP_LASTNAME, "Brown");
nodeProps.put(ContentModel.PROP_JOBTITLE, "Inventor");
nodeProps.put(ContentModel.PROP_LOCATION, "Location");
nodeProps.put(ContentModel.PROP_TELEPHONE, "123345");
nodeProps.put(ContentModel.PROP_MOBILE, "456456");
nodeProps.put(ContentModel.PROP_EMAIL, "doc.brown@example.com");
nodeProps.put(ContentModel.PROP_ORGANIZATION, "Acme");
nodeProps.put(ContentModel.PROP_COMPANYADDRESS1, "123 Acme Crescent");
nodeProps.put(ContentModel.PROP_COMPANYADDRESS2, "Cholsey");
nodeProps.put(ContentModel.PROP_COMPANYADDRESS3, "Oxfordshire");
nodeProps.put(ContentModel.PROP_COMPANYPOSTCODE, "OX10 1AB");
nodeProps.put(ContentModel.PROP_COMPANYTELEPHONE, "098876234");
nodeProps.put(ContentModel.PROP_COMPANYFAX, "098234876");
nodeProps.put(ContentModel.PROP_COMPANYEMAIL, "info@example.com");
nodeProps.put(ContentModel.PROP_SKYPE, "doc.brown");
nodeProps.put(ContentModel.PROP_INSTANTMSG, "doc.brown.instmsg");
nodeProps.put(ContentModel.PROP_USER_STATUS, "status");
nodeProps.put(ContentModel.PROP_USER_STATUS_TIME, new Date());
nodeProps.put(ContentModel.PROP_GOOGLEUSERNAME, "doc.brown.google");
nodeProps.put(ContentModel.PROP_SIZE_QUOTA, 12345000);
nodeProps.put(ContentModel.PROP_SIZE_CURRENT, 1230);
nodeProps.put(ContentModel.PROP_EMAIL_FEED_DISABLED, false);
// TODO: PROP_PERSON_DESCRIPTION?
// Namespaces that should be filtered
nodeProps.put(ContentModel.PROP_ENABLED, true);
nodeProps.put(ContentModel.PROP_SYS_NAME, "name-value");
// Create a password and enable the user so that we can check the usr:* props aren't present later.
AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
authService.createAuthentication(userName, "password".toCharArray());
authService.setAuthenticationEnabled(userName, true);
personService.createPerson(nodeProps);
// Set a preference, so that we can test that we're filtering this property correctly.
prefService.setPreferences(userName, Collections.singletonMap("olives", "green"));
// Get the person using the REST API
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
Person person = people.getPerson(userName);
// Did we get the correct aspects/properties?
assertEquals(userName, person.getId());
assertEquals("Doc", person.getFirstName());
assertEquals("Falafel wrap", person.getProperties().get("papi:lunch"));
assertTrue(person.getAspectNames().contains("papi:lunchable"));
// Empty (zero length) string values are considered to be
// null values, and will be represented the same as null
// values (i.e. by non-existence of the property).
assertNull(person.getProperties().get("papi:lunchcomments"));
// Check that no properties are present that should have been filtered by namespace.
for (String key : person.getProperties().keySet()) {
if (key.startsWith("cm:") || key.startsWith("sys:") || key.startsWith("usr:")) {
Object value = person.getProperties().get(key);
String keyValueStr = String.format("(key=%s, value=%s)", key, value);
fail("Property " + keyValueStr + " found with namespace that should have been excluded.");
}
}
}
use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.
the class TestPeople method testGetPerson.
@Test
public void testGetPerson() throws Exception {
final String person1 = account1PersonIt.next();
final String person2 = account1PersonIt.next();
final String person3 = account2PersonIt.next();
// Test Case cloud-2192
// should be able to see oneself
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
Person resp = people.getPerson(person1);
Person person1Entity = repoService.getPerson(person1);
check(person1Entity, resp);
}
// should be able to see another user in the same domain, and be able to see full profile
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person2));
Person resp = people.getPerson(person1);
Person person1Entity = repoService.getPerson(person1);
Map<String, Boolean> respCapabilities = resp.getCapabilities();
assertNotNull("Check if capabilities are present", respCapabilities);
check(person1Entity, resp);
}
// "-me-" user
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
Person resp = people.getPerson(org.alfresco.rest.api.People.DEFAULT_USER);
Person person1Entity = repoService.getPerson(person1);
Map<String, Boolean> respCapabilities = resp.getCapabilities();
assertNotNull("Check if capabilities are present", respCapabilities);
assertTrue("Check if -me- user is mutable", respCapabilities.get("isMutable"));
check(person1Entity, resp);
}
// shouldn't be able to see another user in another domain
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person3));
try {
people.getPerson(person1);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
RepoService.TestPerson testP = account1.createUser();
String personId = testP.getId();
String desc = "<B>Nice person</B>";
account1.addUserDescription(personId, desc);
publicApiClient.setRequestContext(new RequestContext(account1.getId(), personId));
Person resp = publicApiClient.people().getPerson(personId);
assertEquals(resp.getId(), personId);
assertEquals(resp.getDescription(), desc);
}
use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.
the class TestPeople method testListPeopleWithAspectNamesAndProperties.
@Test
public void testListPeopleWithAspectNamesAndProperties() throws PublicApiException {
publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
personBob = new Person();
personBob.setId("bob@" + account3.getId());
personBob.setUserName(personBob.getId());
personBob.setFirstName("Bob");
personBob.setLastName("Cratchit");
personBob.setEmail("bob.cratchit@example.com");
personBob.setPassword("password");
personBob.setEnabled(true);
personBob.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich"));
people.create(personBob);
// Are aspectNames and properties left absent when not required?
{
PublicApiClient.ListResponse<Person> resp = listPeople(Collections.emptyMap(), 200);
assertNull(resp.getList().get(0).getAspectNames());
assertNull(resp.getList().get(0).getProperties());
}
// Are aspectNames and properties populated when requested?
{
Map<String, String> parameters = Collections.singletonMap("include", "aspectNames,properties");
PublicApiClient.ListResponse<Person> resp = listPeople(parameters, 200);
Person bob = resp.getList().stream().filter(p -> p.getUserName().equals(personBob.getId())).findFirst().get();
assertNotNull(bob.getAspectNames());
assertTrue(bob.getAspectNames().contains("papi:lunchable"));
assertNotNull(bob.getProperties());
assertEquals("Magical sandwich", bob.getProperties().get("papi:lunch"));
}
}
use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.
the class TestPeople method testCreatePerson_withCustomProps.
@Test
public void testCreatePerson_withCustomProps() throws Exception {
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
Person person = new Person();
person.setUserName("jbloggs@" + account1.getId());
person.setFirstName("Joe");
person.setEmail("jbloggs@" + account1.getId());
person.setEnabled(true);
person.setPassword("password123");
Map<String, Object> props = new HashMap<>();
props.put("papi:telehash", "724332b5796a8");
person.setProperties(props);
// Explicitly add an aspect
List<String> aspectNames = new ArrayList<>();
aspectNames.add("papi:lunchable");
person.setAspectNames(aspectNames);
// REST API call to create person
Person retPerson = people.create(person);
// Check that the response contains the expected aspects and properties
assertEquals(2, retPerson.getAspectNames().size());
assertTrue(retPerson.getAspectNames().contains("papi:comms"));
assertEquals(1, retPerson.getProperties().size());
assertEquals("724332b5796a8", retPerson.getProperties().get("papi:telehash"));
// Get the NodeRef
AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
NodeRef nodeRef = personService.getPerson("jbloggs@" + account1.getId(), false);
// Check the node has the properties and aspects we expect
assertTrue(nodeService.hasAspect(nodeRef, ASPECT_COMMS));
assertTrue(nodeService.hasAspect(nodeRef, ASPECT_LUNCHABLE));
Map<QName, Serializable> retProps = nodeService.getProperties(nodeRef);
assertEquals("724332b5796a8", retProps.get(PROP_TELEHASH));
assertEquals(null, retProps.get(PROP_LUNCH));
}
use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.
the class TestPeople method setUp.
@Before
public void setUp() throws Exception {
people = publicApiClient.people();
accountsIt = getTestFixture().getNetworksIt();
account1 = accountsIt.next();
account2 = accountsIt.next();
// Networks are very expensive to create, so do this once only and store statically.
if (account3 == null) {
account3 = createNetwork("account3");
}
if (account4 == null) {
// Use account 4 only for the sorting and paging tests, so that the data doesn't change between tests.
account4 = createNetwork("account4");
account4Admin = "admin@" + account4.getId();
publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
personAlice = new Person();
personAlice.setUserName("alice@" + account4.getId());
personAlice.setId("alice@" + account4.getId());
personAlice.setFirstName("Alice");
personAlice.setLastName("Smith");
personAlice.setEmail("alison.smith@example.com");
personAlice.setPassword("password");
personAlice.setEnabled(true);
personAlice.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich"));
people.create(personAlice);
personAliceD = new Person();
personAliceD.setUserName("aliced@" + account4.getId());
personAliceD.setId("aliced@" + account4.getId());
personAliceD.setFirstName("Alice");
personAliceD.setLastName("Davis");
personAliceD.setEmail("alison.davis@example.com");
personAliceD.setPassword("password");
personAliceD.setEnabled(true);
people.create(personAliceD);
personBen = new Person();
personBen.setUserName("ben@" + account4.getId());
personBen.setId("ben@" + account4.getId());
personBen.setFirstName("Ben");
personBen.setLastName("Carson");
personBen.setEmail("ben.smythe@example.com");
personBen.setPassword("password");
personBen.setEnabled(true);
people.create(personBen);
}
account1Admin = "admin@" + account1.getId();
account2Admin = "admin@" + account2.getId();
account3Admin = "admin@" + account3.getId();
account1PersonIt = account1.getPersonIds().iterator();
account2PersonIt = account2.getPersonIds().iterator();
nodeService = applicationContext.getBean("NodeService", NodeService.class);
personService = applicationContext.getBean("PersonService", PersonService.class);
// Capture authentication pre-test, so we can restore it again afterwards.
AuthenticationUtil.pushAuthentication();
}
Aggregations