- * 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