From fb8ea2a971c42ae10825cb66199bad1fb52464ee Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Tue, 22 Nov 2016 10:28:43 +0000 Subject: [PATCH] Merged mward/5.2.n-repo1544-update-self (5.2.1) to 5.2.N (5.2.1) 132960 mward: REPO-1544: reindent with spaces (review: CR-620) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132999 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/rest/api/tests/TestPeople.java | 1380 ++++++++--------- 1 file changed, 690 insertions(+), 690 deletions(-) diff --git a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java index fd5c2a1ffe..1369c47c92 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -93,24 +93,24 @@ public class TestPeople extends EnterpriseTestApi account3.createUser(); account3PersonIt = account3.getPersonIds().iterator(); - - // Capture authentication pre-test, so we can restore it again afterwards. - AuthenticationUtil.pushAuthentication(); + + // Capture authentication pre-test, so we can restore it again afterwards. + AuthenticationUtil.pushAuthentication(); } @After - public void tearDown() - { - // Restore authentication to pre-test state. - try - { - AuthenticationUtil.popAuthentication(); - } - catch(EmptyStackException e) - { - // Nothing to do. - } - } + public void tearDown() + { + // Restore authentication to pre-test state. + try + { + AuthenticationUtil.popAuthentication(); + } + catch(EmptyStackException e) + { + // Nothing to do. + } + } private TestNetwork createNetwork(String networkPrefix) { @@ -127,644 +127,644 @@ public class TestPeople extends EnterpriseTestApi 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); - 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); - check(person1Entity, resp); - } + // 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); + 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); + 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()); - } + // 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 = "Nice person"; - 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); - } + RepoService.TestPerson testP = account1.createUser(); + String personId = testP.getId(); + String desc = "Nice person"; + 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); + } - @Test - public void testCreatePerson() throws Exception - { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + @Test + public void testCreatePerson() throws Exception + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - Person person = new Person(); - person.setUserName("myUserName00@"+account1.getId()); - person.setFirstName("Firstname"); - person.setLastName("Lastname"); - person.setDescription("my description"); - person.setEmail("email@example.com"); - person.setSkypeId("my.skype.id"); - person.setGoogleId("google"); - person.setInstantMessageId("jabber@im.example.com"); - person.setJobTitle("International Man of Mystery"); - person.setLocation("location"); - person.setCompany(new Company("Org", "addr1", "addr2", "addr3", "AB1 1BA", "111 12312123", "222 345345345", "company.email@example.com")); - person.setMobile("5657 567567 34543"); - person.setTelephone("1234 5678 9012"); - person.setUserStatus("userStatus"); - person.setEnabled(true); - person.setEmailNotificationsEnabled(true); - person.setPassword("password"); + Person person = new Person(); + person.setUserName("myUserName00@"+account1.getId()); + person.setFirstName("Firstname"); + person.setLastName("Lastname"); + person.setDescription("my description"); + person.setEmail("email@example.com"); + person.setSkypeId("my.skype.id"); + person.setGoogleId("google"); + person.setInstantMessageId("jabber@im.example.com"); + person.setJobTitle("International Man of Mystery"); + person.setLocation("location"); + person.setCompany(new Company("Org", "addr1", "addr2", "addr3", "AB1 1BA", "111 12312123", "222 345345345", "company.email@example.com")); + person.setMobile("5657 567567 34543"); + person.setTelephone("1234 5678 9012"); + person.setUserStatus("userStatus"); + person.setEnabled(true); + person.setEmailNotificationsEnabled(true); + person.setPassword("password"); - Person p = people.create(person); + Person p = people.create(person); - assertEquals("myUserName00@"+account1.getId(), p.getId()); - assertEquals("Firstname", p.getFirstName()); - assertEquals("Lastname", p.getLastName()); - assertEquals("my description", p.getDescription()); - assertEquals("email@example.com", p.getEmail()); - assertEquals("my.skype.id", p.getSkypeId()); - assertEquals("google", p.getGoogleId()); - assertEquals("jabber@im.example.com", p.getInstantMessageId()); - assertEquals("International Man of Mystery", p.getJobTitle()); - assertEquals("location", p.getLocation()); + assertEquals("myUserName00@"+account1.getId(), p.getId()); + assertEquals("Firstname", p.getFirstName()); + assertEquals("Lastname", p.getLastName()); + assertEquals("my description", p.getDescription()); + assertEquals("email@example.com", p.getEmail()); + assertEquals("my.skype.id", p.getSkypeId()); + assertEquals("google", p.getGoogleId()); + assertEquals("jabber@im.example.com", p.getInstantMessageId()); + assertEquals("International Man of Mystery", p.getJobTitle()); + assertEquals("location", p.getLocation()); - // Check embedded "company" document - org.alfresco.rest.api.model.Company co = p.getCompany(); - assertEquals("Org", co.getOrganization()); - assertEquals("addr1", co.getAddress1()); - assertEquals("addr2", co.getAddress2()); - assertEquals("addr3", co.getAddress3()); - assertEquals("AB1 1BA", co.getPostcode()); - assertEquals("111 12312123", co.getTelephone()); - assertEquals("222 345345345", co.getFax()); - assertEquals("company.email@example.com", co.getEmail()); + // Check embedded "company" document + org.alfresco.rest.api.model.Company co = p.getCompany(); + assertEquals("Org", co.getOrganization()); + assertEquals("addr1", co.getAddress1()); + assertEquals("addr2", co.getAddress2()); + assertEquals("addr3", co.getAddress3()); + assertEquals("AB1 1BA", co.getPostcode()); + assertEquals("111 12312123", co.getTelephone()); + assertEquals("222 345345345", co.getFax()); + assertEquals("company.email@example.com", co.getEmail()); - assertEquals("5657 567567 34543", p.getMobile()); - assertEquals("1234 5678 9012", p.getTelephone()); - assertEquals("userStatus", p.getUserStatus()); - assertEquals(true, p.isEnabled()); - assertEquals(true, p.isEmailNotificationsEnabled()); - } - - @Test - public void testCreatePerson_canCreateDisabledPerson() throws PublicApiException - { - // Person disabled - { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - - Person person = new Person(); - person.setUserName("myUserName04@"+account1.getId()); - person.setFirstName("Firstname"); - person.setEmail("myUserName04@"+account1.getId()); - person.setEnabled(false); - person.setPassword("hello"); + assertEquals("5657 567567 34543", p.getMobile()); + assertEquals("1234 5678 9012", p.getTelephone()); + assertEquals("userStatus", p.getUserStatus()); + assertEquals(true, p.isEnabled()); + assertEquals(true, p.isEmailNotificationsEnabled()); + } + + @Test + public void testCreatePerson_canCreateDisabledPerson() throws PublicApiException + { + // Person disabled + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + + Person person = new Person(); + person.setUserName("myUserName04@"+account1.getId()); + person.setFirstName("Firstname"); + person.setEmail("myUserName04@"+account1.getId()); + person.setEnabled(false); + person.setPassword("hello"); - Person p = people.create(person); - assertEquals(false, p.isEnabled()); - // It's very important that the password isn't exposed over the REST API. - assertNull(p.getPassword()); - // Check that a freshly retrieved person exhibits the same result - p = people.getPerson(person.getUserName()); - assertEquals(false, p.isEnabled()); - assertNull(p.getPassword()); - - // Can the new user account be used? - publicApiClient.setRequestContext(new RequestContext(account1.getId(), person.getUserName(), "hello")); - try - { - people.getPerson(person.getUserName()); - fail("It should not be possible to use a disabled account."); - } - catch (PublicApiException e) - { - assertEquals(401, e.getHttpResponse().getStatusCode()); - } - } + Person p = people.create(person); + assertEquals(false, p.isEnabled()); + // It's very important that the password isn't exposed over the REST API. + assertNull(p.getPassword()); + // Check that a freshly retrieved person exhibits the same result + p = people.getPerson(person.getUserName()); + assertEquals(false, p.isEnabled()); + assertNull(p.getPassword()); + + // Can the new user account be used? + publicApiClient.setRequestContext(new RequestContext(account1.getId(), person.getUserName(), "hello")); + try + { + people.getPerson(person.getUserName()); + fail("It should not be possible to use a disabled account."); + } + catch (PublicApiException e) + { + assertEquals(401, e.getHttpResponse().getStatusCode()); + } + } - // Person enabled - { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - - Person person = new Person(); - person.setUserName("myUserName05@"+account1.getId()); - person.setFirstName("Firstname"); - person.setEmail("myUserName05@"+account1.getId()); - person.setEnabled(true); - person.setPassword("banana"); + // Person enabled + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + + Person person = new Person(); + person.setUserName("myUserName05@"+account1.getId()); + person.setFirstName("Firstname"); + person.setEmail("myUserName05@"+account1.getId()); + person.setEnabled(true); + person.setPassword("banana"); - Person p = people.create(person); - assertEquals(true, p.isEnabled()); - // It's very important that the password isn't exposed over the REST API. - assertNull(p.getPassword()); - // Check that a freshly retrieved person exhibits the same result - p = people.getPerson(person.getUserName()); - assertEquals(true, p.isEnabled()); - assertNull(p.getPassword()); + Person p = people.create(person); + assertEquals(true, p.isEnabled()); + // It's very important that the password isn't exposed over the REST API. + assertNull(p.getPassword()); + // Check that a freshly retrieved person exhibits the same result + p = people.getPerson(person.getUserName()); + assertEquals(true, p.isEnabled()); + assertNull(p.getPassword()); - // Can the new user account be used? - publicApiClient.setRequestContext(new RequestContext(account1.getId(), person.getUserName(), "banana")); - p = people.getPerson(person.getUserName()); - assertNotNull(p); - assertNull(p.getPassword()); - } - } - - @Test - public void testCreatePerson_notAllFieldsRequired() throws Exception - { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + // Can the new user account be used? + publicApiClient.setRequestContext(new RequestContext(account1.getId(), person.getUserName(), "banana")); + p = people.getPerson(person.getUserName()); + assertNotNull(p); + assertNull(p.getPassword()); + } + } + + @Test + public void testCreatePerson_notAllFieldsRequired() throws Exception + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - // +ve: a random subset of fields should succeed. - { - Person person = new Person(); - person.setUserName("joe.bloggs@" + account1.getId()); - person.setFirstName("Joe"); - person.setLastName("Bloggs"); - person.setEmail("joe.bloggs@example.com"); - person.setSkypeId("jb.skype.id"); - person.setTelephone("1234 5678 9012"); - person.setEnabled(false); - person.setEmailNotificationsEnabled(false); - person.setPassword("password123"); + // +ve: a random subset of fields should succeed. + { + Person person = new Person(); + person.setUserName("joe.bloggs@" + account1.getId()); + person.setFirstName("Joe"); + person.setLastName("Bloggs"); + person.setEmail("joe.bloggs@example.com"); + person.setSkypeId("jb.skype.id"); + person.setTelephone("1234 5678 9012"); + person.setEnabled(false); + person.setEmailNotificationsEnabled(false); + person.setPassword("password123"); - Person p = people.create(person); + Person p = people.create(person); - assertEquals("joe.bloggs@" + account1.getId(), p.getId()); - assertEquals("Joe", p.getFirstName()); - assertEquals("Bloggs", p.getLastName()); - assertEquals(null, p.getDescription()); - assertEquals("joe.bloggs@example.com", p.getEmail()); - assertEquals("jb.skype.id", p.getSkypeId()); - assertEquals(null, p.getGoogleId()); - assertEquals(null, p.getInstantMessageId()); - assertEquals(null, p.getJobTitle()); - assertEquals(null, p.getLocation()); - assertEquals(null, p.getCompany()); - assertEquals(null, p.getMobile()); - assertEquals("1234 5678 9012", p.getTelephone()); - assertEquals(null, p.getUserStatus()); - assertEquals(false, p.isEnabled()); - assertEquals(false, p.isEmailNotificationsEnabled()); - } + assertEquals("joe.bloggs@" + account1.getId(), p.getId()); + assertEquals("Joe", p.getFirstName()); + assertEquals("Bloggs", p.getLastName()); + assertEquals(null, p.getDescription()); + assertEquals("joe.bloggs@example.com", p.getEmail()); + assertEquals("jb.skype.id", p.getSkypeId()); + assertEquals(null, p.getGoogleId()); + assertEquals(null, p.getInstantMessageId()); + assertEquals(null, p.getJobTitle()); + assertEquals(null, p.getLocation()); + assertEquals(null, p.getCompany()); + assertEquals(null, p.getMobile()); + assertEquals("1234 5678 9012", p.getTelephone()); + assertEquals(null, p.getUserStatus()); + assertEquals(false, p.isEnabled()); + assertEquals(false, p.isEmailNotificationsEnabled()); + } - // +ve: absolute minimum - { - Person person = new Person(); - person.setUserName("joe.bloggs.2@"+account1.getId()); - person.setFirstName("Joe"); - person.setEmail("joe.bloggs.2@example.com"); - person.setPassword("password-is-secret"); + // +ve: absolute minimum + { + Person person = new Person(); + person.setUserName("joe.bloggs.2@"+account1.getId()); + person.setFirstName("Joe"); + person.setEmail("joe.bloggs.2@example.com"); + person.setPassword("password-is-secret"); - Person p = people.create(person); + Person p = people.create(person); - assertEquals("joe.bloggs.2@" + account1.getId(), p.getId()); - assertEquals("Joe", p.getFirstName()); - assertEquals(null, p.getLastName()); - assertEquals(null, p.getDescription()); - assertEquals("joe.bloggs.2@example.com", p.getEmail()); - assertEquals(null, p.getSkypeId()); - assertEquals(null, p.getGoogleId()); - assertEquals(null, p.getInstantMessageId()); - assertEquals(null, p.getJobTitle()); - assertEquals(null, p.getLocation()); - assertEquals(null, p.getCompany()); - assertEquals(null, p.getMobile()); - assertEquals(null, p.getTelephone()); - assertEquals(null, p.getUserStatus()); - assertEquals(true, p.isEnabled()); - assertEquals(true, p.isEmailNotificationsEnabled()); - } + assertEquals("joe.bloggs.2@" + account1.getId(), p.getId()); + assertEquals("Joe", p.getFirstName()); + assertEquals(null, p.getLastName()); + assertEquals(null, p.getDescription()); + assertEquals("joe.bloggs.2@example.com", p.getEmail()); + assertEquals(null, p.getSkypeId()); + assertEquals(null, p.getGoogleId()); + assertEquals(null, p.getInstantMessageId()); + assertEquals(null, p.getJobTitle()); + assertEquals(null, p.getLocation()); + assertEquals(null, p.getCompany()); + assertEquals(null, p.getMobile()); + assertEquals(null, p.getTelephone()); + assertEquals(null, p.getUserStatus()); + assertEquals(true, p.isEnabled()); + assertEquals(true, p.isEmailNotificationsEnabled()); + } - // -ve: not enough fields! - { - // Create a person with no fields set. - Person person = new Person(); - person.setUserName("joe.bloggs.2@"+account1.getId()); - people.create(person, 400); - } - } + // -ve: not enough fields! + { + // Create a person with no fields set. + Person person = new Person(); + person.setUserName("joe.bloggs.2@"+account1.getId()); + people.create(person, 400); + } + } - @Test - public void testCreatePerson_extraFieldsCauseError() throws Exception { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + @Test + public void testCreatePerson_extraFieldsCauseError() throws Exception { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - String username = "joe.bloggs@"+account1.getId(); + String username = "joe.bloggs@"+account1.getId(); - String[] illegalFields = new String[] { - "\"avatarId\": \"workspace://SpacesStore/\"", - "\"statusUpdatedAt\": \"2016-10-25T09:12:58.621Z\"", - "\"quota\": \"123\"", - "\"quotaUsed\": \"80\"" - }; + String[] illegalFields = new String[] { + "\"avatarId\": \"workspace://SpacesStore/\"", + "\"statusUpdatedAt\": \"2016-10-25T09:12:58.621Z\"", + "\"quota\": \"123\"", + "\"quotaUsed\": \"80\"" + }; - for (String badField : illegalFields) - { - String json = - "{\n" + - " \"id\": \"" + username + "\",\n" + - " \"firstName\": \"Joe\",\n" + - " \"lastName\": \"Bloggs\",\n" + - badField + - "}"; - people.create("people", null, null, null, json, "Illegal field test:"+badField, 400); - } - } + for (String badField : illegalFields) + { + String json = + "{\n" + + " \"id\": \"" + username + "\",\n" + + " \"firstName\": \"Joe\",\n" + + " \"lastName\": \"Bloggs\",\n" + + badField + + "}"; + people.create("people", null, null, null, json, "Illegal field test:"+badField, 400); + } + } - /** - * General error conditions not covered by other "create person" tests. - */ - @Test - public void testCreatePerson_errorResponses() throws Exception { - // -ve: authorisation required - { - // Invalid auth details - publicApiClient.setRequestContext(new RequestContext(account1.getId(), GUID.generate(), "password")); - Person person = new Person(); - person.setUserName("myUserName01@"+account1.getId()); - person.setFirstName("Caroline"); - person.setEmail("caroline.smithson@example.com"); - person.setEnabled(true); - people.create(person, 401); - } + /** + * General error conditions not covered by other "create person" tests. + */ + @Test + public void testCreatePerson_errorResponses() throws Exception { + // -ve: authorisation required + { + // Invalid auth details + publicApiClient.setRequestContext(new RequestContext(account1.getId(), GUID.generate(), "password")); + Person person = new Person(); + person.setUserName("myUserName01@"+account1.getId()); + person.setFirstName("Caroline"); + person.setEmail("caroline.smithson@example.com"); + person.setEnabled(true); + people.create(person, 401); + } - // -ve: API user does not have permission to create user. - { - String apiUser = account2PersonIt.next(); - publicApiClient.setRequestContext(new RequestContext(account2.getId(), apiUser)); - Person person = new Person(); - person.setUserName("myUserName02@"+account2.getId()); - person.setFirstName("Kieth"); - person.setEmail("keith.smith@example.com"); - person.setEnabled(true); - person.setPassword("password"); - people.create(person, 403); + // -ve: API user does not have permission to create user. + { + String apiUser = account2PersonIt.next(); + publicApiClient.setRequestContext(new RequestContext(account2.getId(), apiUser)); + Person person = new Person(); + person.setUserName("myUserName02@"+account2.getId()); + person.setFirstName("Kieth"); + person.setEmail("keith.smith@example.com"); + person.setEnabled(true); + person.setPassword("password"); + people.create(person, 403); - publicApiClient.setRequestContext(new RequestContext(account2.getId(), account2Admin, "admin")); - // Should succeed this time. - people.create(person, 201); - } + publicApiClient.setRequestContext(new RequestContext(account2.getId(), account2Admin, "admin")); + // Should succeed this time. + people.create(person, 201); + } - // -ve: person already exists - { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - Person person = new Person(); - person.setUserName("myUserName03@"+account1.getId()); - person.setFirstName("Alison"); - person.setEmail("alison.smythe@example.com"); - person.setEnabled(true); - person.setPassword("secret"); - people.create(person); + // -ve: person already exists + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + Person person = new Person(); + person.setUserName("myUserName03@"+account1.getId()); + person.setFirstName("Alison"); + person.setEmail("alison.smythe@example.com"); + person.setEnabled(true); + person.setPassword("secret"); + people.create(person); - // Attempt to create the person a second time. - people.create(person, 409); - } - } - - @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. - PersonService personService = applicationContext.getBean("PersonService", PersonService.class); - NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); - Map nodeProps = new HashMap<>(); - // The cm:titled aspect should be auto-added for the cm:title property - nodeProps.put(ContentModel.PROP_TITLE, "A title"); - - // These properties should not be present when a person is retrieved - // since they are present as top-level fields. - nodeProps.put(ContentModel.PROP_USERNAME, "docbrown@"+account1.getId()); - 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? - - // Namespace that should be filtered - nodeProps.put(ContentModel.PROP_SYS_NAME, "name-value"); - - AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); - personService.createPerson(nodeProps); - - // Get the person using the REST API - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - Person person = people.getPerson("docbrown@"+account1.getId()); - - // Did we get the correct aspects/properties? - assertEquals("docbrown@"+account1.getId(), person.getId()); - assertEquals("Doc", person.getFirstName()); - assertEquals("A title", person.getProperties().get("cm:title")); - assertTrue(person.getAspectNames().contains("cm:titled")); - - // Properties that are already represented as specific fields in the API response (e.g. firstName, lastName...) - // must be filtered from the generic properties datastructure. - assertFalse(person.getProperties().containsKey("cm:userName")); - assertFalse(person.getProperties().containsKey("cm:firstName")); - assertFalse(person.getProperties().containsKey("cm:lastName")); - assertFalse(person.getProperties().containsKey("cm:jobtitle")); - assertFalse(person.getProperties().containsKey("cm:location")); - assertFalse(person.getProperties().containsKey("cm:telephone")); - assertFalse(person.getProperties().containsKey("cm:mobile")); - assertFalse(person.getProperties().containsKey("cm:email")); - assertFalse(person.getProperties().containsKey("cm:organization")); - assertFalse(person.getProperties().containsKey("cm:companyaddress1")); - assertFalse(person.getProperties().containsKey("cm:companyaddress2")); - assertFalse(person.getProperties().containsKey("cm:companyaddress3")); - assertFalse(person.getProperties().containsKey("cm:companypostcode")); - assertFalse(person.getProperties().containsKey("cm:companytelephone")); - assertFalse(person.getProperties().containsKey("cm:companyfax")); - assertFalse(person.getProperties().containsKey("cm:companyemail")); - assertFalse(person.getProperties().containsKey("cm:skype")); - assertFalse(person.getProperties().containsKey("cm:instantmsg")); - assertFalse(person.getProperties().containsKey("cm:userStatus")); - assertFalse(person.getProperties().containsKey("cm:userStatusTime")); - assertFalse(person.getProperties().containsKey("cm:googleusername")); - assertFalse(person.getProperties().containsKey("cm:sizeQuota")); - assertFalse(person.getProperties().containsKey("cm:sizeCurrent")); - assertFalse(person.getProperties().containsKey("cm:emailFeedDisabled")); - assertFalse(person.getProperties().containsKey("cm:persondescription")); - - // Check that no properties are present that should have been filtered. - for (String key : person.getProperties().keySet()) - { - if (key.startsWith("sys:")) - { - 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."); - } - } - } - - @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 props = new HashMap<>(); - props.put("cm:title", "This is a title"); - person.setProperties(props); + // Attempt to create the person a second time. + people.create(person, 409); + } + } + + @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. + PersonService personService = applicationContext.getBean("PersonService", PersonService.class); + NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); + Map nodeProps = new HashMap<>(); + // The cm:titled aspect should be auto-added for the cm:title property + nodeProps.put(ContentModel.PROP_TITLE, "A title"); + + // These properties should not be present when a person is retrieved + // since they are present as top-level fields. + nodeProps.put(ContentModel.PROP_USERNAME, "docbrown@"+account1.getId()); + 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? + + // Namespace that should be filtered + nodeProps.put(ContentModel.PROP_SYS_NAME, "name-value"); + + AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); + personService.createPerson(nodeProps); + + // Get the person using the REST API + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + Person person = people.getPerson("docbrown@"+account1.getId()); + + // Did we get the correct aspects/properties? + assertEquals("docbrown@"+account1.getId(), person.getId()); + assertEquals("Doc", person.getFirstName()); + assertEquals("A title", person.getProperties().get("cm:title")); + assertTrue(person.getAspectNames().contains("cm:titled")); + + // Properties that are already represented as specific fields in the API response (e.g. firstName, lastName...) + // must be filtered from the generic properties datastructure. + assertFalse(person.getProperties().containsKey("cm:userName")); + assertFalse(person.getProperties().containsKey("cm:firstName")); + assertFalse(person.getProperties().containsKey("cm:lastName")); + assertFalse(person.getProperties().containsKey("cm:jobtitle")); + assertFalse(person.getProperties().containsKey("cm:location")); + assertFalse(person.getProperties().containsKey("cm:telephone")); + assertFalse(person.getProperties().containsKey("cm:mobile")); + assertFalse(person.getProperties().containsKey("cm:email")); + assertFalse(person.getProperties().containsKey("cm:organization")); + assertFalse(person.getProperties().containsKey("cm:companyaddress1")); + assertFalse(person.getProperties().containsKey("cm:companyaddress2")); + assertFalse(person.getProperties().containsKey("cm:companyaddress3")); + assertFalse(person.getProperties().containsKey("cm:companypostcode")); + assertFalse(person.getProperties().containsKey("cm:companytelephone")); + assertFalse(person.getProperties().containsKey("cm:companyfax")); + assertFalse(person.getProperties().containsKey("cm:companyemail")); + assertFalse(person.getProperties().containsKey("cm:skype")); + assertFalse(person.getProperties().containsKey("cm:instantmsg")); + assertFalse(person.getProperties().containsKey("cm:userStatus")); + assertFalse(person.getProperties().containsKey("cm:userStatusTime")); + assertFalse(person.getProperties().containsKey("cm:googleusername")); + assertFalse(person.getProperties().containsKey("cm:sizeQuota")); + assertFalse(person.getProperties().containsKey("cm:sizeCurrent")); + assertFalse(person.getProperties().containsKey("cm:emailFeedDisabled")); + assertFalse(person.getProperties().containsKey("cm:persondescription")); + + // Check that no properties are present that should have been filtered. + for (String key : person.getProperties().keySet()) + { + if (key.startsWith("sys:")) + { + 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."); + } + } + } + + @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 props = new HashMap<>(); + props.put("cm:title", "This is a title"); + person.setProperties(props); - // Explicitly add an aspect - List aspectNames = new ArrayList<>(); - aspectNames.add("cm:classifiable"); - person.setAspectNames(aspectNames); - - // REST API call to create person - Person retPerson = people.create(person); - - // Check that the response contains the expected aspects and properties - assertTrue(retPerson.getAspectNames().contains("cm:titled")); - assertTrue(retPerson.getAspectNames().contains("cm:classifiable")); - assertEquals("This is a title", retPerson.getProperties().get("cm:title")); - - // Get the NodeRef - AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); - PersonService personService = applicationContext.getBean("PersonService", PersonService.class); - NodeRef nodeRef = personService.getPerson("jbloggs@"+account1.getId(), false); + // Explicitly add an aspect + List aspectNames = new ArrayList<>(); + aspectNames.add("cm:classifiable"); + person.setAspectNames(aspectNames); + + // REST API call to create person + Person retPerson = people.create(person); + + // Check that the response contains the expected aspects and properties + assertTrue(retPerson.getAspectNames().contains("cm:titled")); + assertTrue(retPerson.getAspectNames().contains("cm:classifiable")); + assertEquals("This is a title", retPerson.getProperties().get("cm:title")); + + // Get the NodeRef + AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); + PersonService personService = applicationContext.getBean("PersonService", PersonService.class); + NodeRef nodeRef = personService.getPerson("jbloggs@"+account1.getId(), false); - // Check the node has the properties and aspects we expect - NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); - assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED)); - assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CLASSIFIABLE)); - - Map retProps = nodeService.getProperties(nodeRef); - assertEquals("This is a title", retProps.get(ContentModel.PROP_TITLE)); - } + // Check the node has the properties and aspects we expect + NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); + assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED)); + assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CLASSIFIABLE)); + + Map retProps = nodeService.getProperties(nodeRef); + assertEquals("This is a title", retProps.get(ContentModel.PROP_TITLE)); + } - // 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("cm:title", "Initial title")); - person.setAspectNames(Collections.singletonList("cm:projectsummary")); + // 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("cm:title", "Initial title")); + person.setAspectNames(Collections.singletonList("cm:projectsummary")); - person = people.create(person); + person = people.create(person); - AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); - NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); - PersonService personService = applicationContext.getBean("PersonService", PersonService.class); - NodeRef nodeRef = personService.getPerson(person.getId()); - nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUDITABLE, null); - - assertEquals("Initial title", person.getProperties().get("cm:title")); - assertTrue(person.getAspectNames().contains("cm:titled")); - assertTrue(person.getAspectNames().contains("cm:projectsummary")); - assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUDITABLE)); - return person; - } - - @Test - public void testUpdatePerson_withCustomProps() throws Exception - { - publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - - // Add a property - { - Person person = createTestUpdatePerson(); - assertNull(person.getProperties().get("cm:middleName")); - String json = qjson( - "{" + - " `properties`: {" + - " `cm:middleName`: `Bertrand`" + - " }" + - "}" - ); - person = people.update(person.getId(), json, 200); + AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); + NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); + PersonService personService = applicationContext.getBean("PersonService", PersonService.class); + NodeRef nodeRef = personService.getPerson(person.getId()); + nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUDITABLE, null); + + assertEquals("Initial title", person.getProperties().get("cm:title")); + assertTrue(person.getAspectNames().contains("cm:titled")); + assertTrue(person.getAspectNames().contains("cm:projectsummary")); + assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUDITABLE)); + return person; + } + + @Test + public void testUpdatePerson_withCustomProps() throws Exception + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + + // Add a property + { + Person person = createTestUpdatePerson(); + assertNull(person.getProperties().get("cm:middleName")); + String json = qjson( + "{" + + " `properties`: {" + + " `cm:middleName`: `Bertrand`" + + " }" + + "}" + ); + person = people.update(person.getId(), json, 200); - // Property added - assertEquals("Bertrand", person.getProperties().get("cm:middleName")); - assertEquals("Initial title", person.getProperties().get("cm:title")); - // Aspect untouched - assertTrue(person.getAspectNames().contains("cm:titled")); - } - - // Simple update of properties - { - Person person = createTestUpdatePerson(); - person = people.update(person.getId(), qjson("{`properties`: {`cm:title`: `Updated title`}}"), 200); - - // Property updated - assertEquals("Updated title", person.getProperties().get("cm:title")); - // Aspect untouched - assertTrue(person.getAspectNames().contains("cm:titled")); - } - - // Update with zero aspects - clear them all, except for protected items. - { - Person person = createTestUpdatePerson(); - person = people.update(person.getId(), qjson("{`aspectNames`: []}"), 200); - - // Aspect should no longer be present. - assertFalse(person.getAspectNames().contains("cm:titled")); - assertFalse(person.getProperties().containsKey("cm:title")); - // Protected aspects should still be present. - List aspectNames = person.getAspectNames(); - assertTrue(aspectNames.contains("cm:auditable")); - - // Check for the protected (but filtered) sys:* properties - NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); - PersonService personService = applicationContext.getBean("PersonService", PersonService.class); - NodeRef nodeRef = personService.getPerson(person.getId()); - Set aspects = nodeService.getAspects(nodeRef); - assertTrue(aspects.contains(ContentModel.ASPECT_REFERENCEABLE)); - assertTrue(aspects.contains(ContentModel.ASPECT_LOCALIZED)); - } - - // Set aspects - all except protected items will be replaced with those presented. - { - Person person = createTestUpdatePerson(); - String json = qjson( - "{" + - " `aspectNames`: [" + - " `cm:dublincore`," + - " `cm:summarizable`" + - " ]" + - "}" - ); - person = people.update(person.getId(), json, 200); + // Property added + assertEquals("Bertrand", person.getProperties().get("cm:middleName")); + assertEquals("Initial title", person.getProperties().get("cm:title")); + // Aspect untouched + assertTrue(person.getAspectNames().contains("cm:titled")); + } + + // Simple update of properties + { + Person person = createTestUpdatePerson(); + person = people.update(person.getId(), qjson("{`properties`: {`cm:title`: `Updated title`}}"), 200); + + // Property updated + assertEquals("Updated title", person.getProperties().get("cm:title")); + // Aspect untouched + assertTrue(person.getAspectNames().contains("cm:titled")); + } + + // Update with zero aspects - clear them all, except for protected items. + { + Person person = createTestUpdatePerson(); + person = people.update(person.getId(), qjson("{`aspectNames`: []}"), 200); + + // Aspect should no longer be present. + assertFalse(person.getAspectNames().contains("cm:titled")); + assertFalse(person.getProperties().containsKey("cm:title")); + // Protected aspects should still be present. + List aspectNames = person.getAspectNames(); + assertTrue(aspectNames.contains("cm:auditable")); + + // Check for the protected (but filtered) sys:* properties + NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); + PersonService personService = applicationContext.getBean("PersonService", PersonService.class); + NodeRef nodeRef = personService.getPerson(person.getId()); + Set aspects = nodeService.getAspects(nodeRef); + assertTrue(aspects.contains(ContentModel.ASPECT_REFERENCEABLE)); + assertTrue(aspects.contains(ContentModel.ASPECT_LOCALIZED)); + } + + // Set aspects - all except protected items will be replaced with those presented. + { + Person person = createTestUpdatePerson(); + String json = qjson( + "{" + + " `aspectNames`: [" + + " `cm:dublincore`," + + " `cm:summarizable`" + + " ]" + + "}" + ); + person = people.update(person.getId(), json, 200); - // Aspect should no longer be present. - assertFalse(person.getAspectNames().contains("cm:titled")); - assertFalse(person.getProperties().containsKey("cm:title")); - // Protected aspects should still be present. - List aspectNames = person.getAspectNames(); - assertTrue(aspectNames.contains("cm:auditable")); - - // Newly added aspects - assertTrue(aspectNames.contains("cm:dublincore")); - assertTrue(aspectNames.contains("cm:summarizable")); - } - - // Remove a property by setting it to null - { - Person person = createTestUpdatePerson(); - person = people.update(person.getId(), qjson("{`properties`: {`cm:title`: null}}"), 200); - - assertFalse(person.getProperties().containsKey("cm:title")); - // The aspect will still be there, I don't think we can easily remove the aspect automatically - // just because the associated properties have all been removed. - assertTrue(person.getAspectNames().contains("cm:titled")); - } - } + // Aspect should no longer be present. + assertFalse(person.getAspectNames().contains("cm:titled")); + assertFalse(person.getProperties().containsKey("cm:title")); + // Protected aspects should still be present. + List aspectNames = person.getAspectNames(); + assertTrue(aspectNames.contains("cm:auditable")); + + // Newly added aspects + assertTrue(aspectNames.contains("cm:dublincore")); + assertTrue(aspectNames.contains("cm:summarizable")); + } + + // Remove a property by setting it to null + { + Person person = createTestUpdatePerson(); + person = people.update(person.getId(), qjson("{`properties`: {`cm:title`: null}}"), 200); + + assertFalse(person.getProperties().containsKey("cm:title")); + // The aspect will still be there, I don't think we can easily remove the aspect automatically + // just because the associated properties have all been removed. + assertTrue(person.getAspectNames().contains("cm:titled")); + } + } - /** - * Simple helper to make JSON literals a little easier to read in test code, - * by allowing values that would normally be quoted with double quotes, to be - * quoted with backticks instead. - *

- * Double and single quotes may still be used as normal, if required. - * - * @param raw The untreated JSON string to munge - * @return JSON String with backticks replaced with double quotes. - */ - private String qjson(String raw) - { - return raw.replace("`", "\""); - } - - public static class PersonJSONSerializer implements JSONAble - { - private final Person personUpdate; + /** + * Simple helper to make JSON literals a little easier to read in test code, + * by allowing values that would normally be quoted with double quotes, to be + * quoted with backticks instead. + *

+ * Double and single quotes may still be used as normal, if required. + * + * @param raw The untreated JSON string to munge + * @return JSON String with backticks replaced with double quotes. + */ + private String qjson(String raw) + { + return raw.replace("`", "\""); + } + + public static class PersonJSONSerializer implements JSONAble + { + private final Person personUpdate; - public PersonJSONSerializer(Person personUpdate) - { - this.personUpdate = personUpdate; - } + public PersonJSONSerializer(Person personUpdate) + { + this.personUpdate = personUpdate; + } - @Override - public JSONObject toJSON() - { - JSONObject personJson = new JSONObject(); + @Override + public JSONObject toJSON() + { + JSONObject personJson = new JSONObject(); - if (personUpdate.getUserName() != null) - { - personJson.put("id", personUpdate.getUserName()); - } - personJson.put("firstName", personUpdate.getFirstName()); - personJson.put("lastName", personUpdate.getLastName()); + if (personUpdate.getUserName() != null) + { + personJson.put("id", personUpdate.getUserName()); + } + personJson.put("firstName", personUpdate.getFirstName()); + personJson.put("lastName", personUpdate.getLastName()); - personJson.put("description", personUpdate.getDescription()); - personJson.put("email", personUpdate.getEmail()); - personJson.put("skypeId", personUpdate.getSkypeId()); - personJson.put("googleId", personUpdate.getGoogleId()); - personJson.put("instantMessageId", personUpdate.getInstantMessageId()); - personJson.put("jobTitle", personUpdate.getJobTitle()); - personJson.put("location", personUpdate.getLocation()); - org.alfresco.rest.api.model.Company co = personUpdate.getCompany(); - if (co == null) - { - co = new org.alfresco.rest.api.model.Company(); - } - personJson.put("company", new Company(co).toJSON()); - personJson.put("mobile", personUpdate.getMobile()); - personJson.put("telephone", personUpdate.getTelephone()); - personJson.put("userStatus", personUpdate.getUserStatus()); - personJson.put("enabled", personUpdate.isEnabled()); - personJson.put("emailNotificationsEnabled", personUpdate.isEmailNotificationsEnabled()); - personJson.put("password", personUpdate.getPassword()); - personJson.put("properties", personUpdate.getProperties()); - personJson.put("aspectNames", personUpdate.getAspectNames()); - return personJson; - } - } + personJson.put("description", personUpdate.getDescription()); + personJson.put("email", personUpdate.getEmail()); + personJson.put("skypeId", personUpdate.getSkypeId()); + personJson.put("googleId", personUpdate.getGoogleId()); + personJson.put("instantMessageId", personUpdate.getInstantMessageId()); + personJson.put("jobTitle", personUpdate.getJobTitle()); + personJson.put("location", personUpdate.getLocation()); + org.alfresco.rest.api.model.Company co = personUpdate.getCompany(); + if (co == null) + { + co = new org.alfresco.rest.api.model.Company(); + } + personJson.put("company", new Company(co).toJSON()); + personJson.put("mobile", personUpdate.getMobile()); + personJson.put("telephone", personUpdate.getTelephone()); + personJson.put("userStatus", personUpdate.getUserStatus()); + personJson.put("enabled", personUpdate.isEnabled()); + personJson.put("emailNotificationsEnabled", personUpdate.isEmailNotificationsEnabled()); + personJson.put("password", personUpdate.getPassword()); + personJson.put("properties", personUpdate.getProperties()); + personJson.put("aspectNames", personUpdate.getAspectNames()); + return personJson; + } + } @Test public void testUpdatePersonAuthenticationFailed() throws PublicApiException @@ -775,35 +775,35 @@ public class TestPeople extends EnterpriseTestApi people.update("people", personId, null, null, "{\n" + " \"firstName\": \"Updated firstName\"\n" + "}", null, "Expected 401 response when updating " + personId, 401); } - + @Test public void testUpdatePersonNonSelfAndNonAdminDisallowed() throws PublicApiException { - // TODO: this is bad, it seems that the test fixture isn't unique per test!? + // 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); + + 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); + // TODO: temp fix, set back to orig firstName + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + people.update(personToUpdateId, qjson("{ `firstName`:`Bob` }"), 200); } - @Test - public void testUpdatePersonCanUpdateThemself() throws PublicApiException - { - final String personId = account1PersonIt.next(); - publicApiClient.setRequestContext(new RequestContext(account1.getId(), personId)); + @Test + public void testUpdatePersonCanUpdateThemself() throws PublicApiException + { + final String personId = account1PersonIt.next(); + publicApiClient.setRequestContext(new RequestContext(account1.getId(), personId)); - Person updatedPerson = people.update(personId, qjson("{ `firstName`: `Updated firstName` }"), 200); - assertEquals("Updated firstName", updatedPerson.getFirstName()); + Person updatedPerson = people.update(personId, qjson("{ `firstName`: `Updated firstName` }"), 200); + assertEquals("Updated firstName", 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); - } + // TODO: temp fix, set back to orig firstName + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + people.update(personId, qjson("{ `firstName`:`Bill` }"), 200); + } @Test public void testUpdatePersonNonexistentPerson() throws PublicApiException @@ -948,46 +948,46 @@ public class TestPeople extends EnterpriseTestApi @Test public void testUpdatePersonEnabled() throws PublicApiException { - // Non-admin user ID + // Non-admin user ID final String personId = account3PersonIt.next(); - // Use admin user credentials - publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin")); - - // Admin can toggle enabled flag: false - { - Boolean enabled = false; - Map params = Collections.singletonMap("fields", "enabled"); - Person updatedPerson = people.update(personId, qjson("{`enabled`:"+enabled+"}"), params, 200); + // Use admin user credentials + publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin")); + + // Admin can toggle enabled flag: false + { + Boolean enabled = false; + Map params = Collections.singletonMap("fields", "enabled"); + Person updatedPerson = people.update(personId, qjson("{`enabled`:"+enabled+"}"), params, 200); - assertEquals(enabled, updatedPerson.isEnabled()); - } + assertEquals(enabled, updatedPerson.isEnabled()); + } - // Admin can toggle enabled flag: true - { - Boolean enabled = true; - Map params = Collections.singletonMap("fields", "enabled"); - Person updatedPerson = people.update(personId, qjson("{`enabled`:"+enabled+"}"), params, 200); + // Admin can toggle enabled flag: true + { + Boolean enabled = true; + Map params = Collections.singletonMap("fields", "enabled"); + Person updatedPerson = people.update(personId, qjson("{`enabled`:"+enabled+"}"), params, 200); - assertEquals(enabled, updatedPerson.isEnabled()); - } + assertEquals(enabled, updatedPerson.isEnabled()); + } - // 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 params = Collections.singletonMap("fields", "enabled"); - people.update(personId, qjson("{`enabled`:"+enabled+"}"), params, 403); + // 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 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()); - } + Person me = people.getPerson(personId); + assertEquals("Enabled state shouldn't have changed, but did", origEnabled, me.isEnabled()); + } } @Test @@ -1001,36 +1001,36 @@ public class TestPeople extends EnterpriseTestApi people.update("people", account3Admin, null, null, "{\n" + " \"enabled\": \"" + false + "\"\n" + "}", params, "Expected 403 response when updating " + account3Admin, 403); } - @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")); + @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); + // 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()); + // 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 wrong oldPassword + people.update(me.getId(), qjson("{ `oldPassword`:`password123`, `password`:`newpassword456` }"), 403); - // update with no oldPassword - people.update(me.getId(), qjson("{ `password`:`newpassword456` }"), 403); - } + // update with no oldPassword + people.update(me.getId(), qjson("{ `password`:`newpassword456` }"), 403); + } @Test public void testUpdatePersonPasswordByAdmin() throws PublicApiException