Person Service - now all Web Script Unit Tests pass

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9558 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Glen Johnson
2008-06-24 23:20:13 +00:00
parent 6234679ccb
commit 57f8a813c1
6 changed files with 64 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
<webscript>
<shortname>People</shortname>
<shortname>Get People</shortname>
<description>
Get collection of people stored in the repository. This can optionally be
filtered according to some given filter query string

View File

@@ -1,8 +1,8 @@
<webscript>
<shortname>People</shortname>
<shortname>Add Person</shortname>
<description>Adds a new person based on the details provided.</description>
<url>/api/people</url>
<format default="json" />
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -8,25 +8,23 @@ function main()
return;
}
var title = json.get("title");
var firstName = json.get("firstName");
var lastName = json.get("lastName");
var organisation = json.get("organisation");
var jobTitle = json.get("jobTitle");
var email = json.get("email");
var bio = json.get("bio");
var avatarUrl = json.get("avatarUrl");
// Create the person
// Create the person with the supplied user name
var person = people.createPerson(userName);
person.properties.title = title;
person.properties.firstName = firstName;
person.properties.lastName = lastName;
person.properties.organisation = organisation;
person.properties.jobTitle = jobTitle;
person.properties.email = email;
person.properties.bio = bio;
person.properties.avatarUrl = avatarUrl;
// return error message if a person with that user name could not be created
if (person === null)
{
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Person could not be created with user name: " + userName);
return;
}
// assign values to the person's properties
person.properties.title = json.get("title");
person.properties.firstName = json.get("firstName");
person.properties.lastName = json.get("lastName");
person.properties.organization = json.get("organisation");
person.properties.jobTitle = json.get("jobTitle");
person.properties.email = json.get("email");
person.save();
// Put the created person into the model

View File

@@ -1,7 +1,7 @@
<webscript>
<shortname>Person</shortname>
<shortname>Get Person</shortname>
<description>Get the details of a person.</description>
<url>/api/person/{userName}</url>
<url>/api/people/{userName}</url>
<format default="json" />
<authentication>guest</authentication>
<transaction>required</transaction>

View File

@@ -1,23 +1,37 @@
<#macro personJSON person>
{
"url" : "${url.serviceContext}/api/person/${person.userName}",
"userName" : "${person.userName}",
"title" : "${person.title}",
"firstName" : "${person.firstName}",
"lastName" : "${person.lastName}",
"organisation" : "${person.organisation}",
"jobTitle" : "${person.jobTitle}",
"email" : "${person.email}",
"bio" : "${person.bio}",
"avatarUrl" : "${person.avatarUrl}",
"url" : "${url.serviceContext}/api/person/${person.properties.userName}",
"userName" : "${person.properties.userName}",
<#if person.properties.title??>
"title" : "${person.properties.title}",
<#else>
"title" : undefined,
</#if>
"firstName" : "${person.properties.firstName}",
"lastName" : "${person.properties.lastName}",
<#if person.properties.organization??>
"organisation" : "${person.properties.organization}",
<#else>
"organisation" : undefined,
</#if>
<#if person.properties.jobtitle??>
"jobTitle" : "${person.properties.jobtitle}",
<#else>
"jobTitle" : undefined,
</#if>
<#if person.properties.email??>
"email" : "${person.properties.email}"
<#else>
"email" : undefined
</#if>
}
</#macro>
<#macro personSummaryJSON person>
{
"url" : "${url.serviceContext}/api/person/${person.userName}",
"userName" : "${person.userName}",
"firstName" : "${person.firstName}",
"lastName" : "${person.lastName}"
"url" : "${url.serviceContext}/api/person/${person.properties.userName}",
"userName" : "${person.properties.userName}",
"firstName" : "${person.properties.firstName}",
"lastName" : "${person.properties.lastName}"
}
</#macro>

View File

@@ -101,18 +101,20 @@ public class PersonServiceTest extends BaseWebScriptTest
protected void tearDown() throws Exception
{
super.tearDown();
this.authenticationComponent.setCurrentUser("admin");
String adminUser = this.authenticationComponent.getSystemUserName();
this.authenticationComponent.setCurrentUser(adminUser);
/*
* TODO: glen.johnson at alfresco dot com -
* When DELETE /people/{userid} becomes a requirement and is subsequently implemented,
* include this section to tidy-up people's resources created during the execution of the test
*
*/
for (String userName : this.createdPeople)
{
deleteRequest(URL_PEOPLE + "/" + userName, 0);
// deleteRequest(URL_PEOPLE + "/" + userName, 0);
personService.deletePerson(userName);
}
*/
// Clear the list
this.createdPeople.clear();
@@ -123,7 +125,7 @@ public class PersonServiceTest extends BaseWebScriptTest
String userName = RandomStringUtils.randomNumeric(6);
// Create a new site
JSONObject result = createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation",
JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", 200);
assertEquals(userName, result.get("userName"));
assertEquals("myTitle", result.get("title"));
@@ -132,8 +134,6 @@ public class PersonServiceTest extends BaseWebScriptTest
assertEquals("myOrganisation", result.get("organisation"));
assertEquals("myJobTitle", result.get("jobTitle"));
assertEquals("firstName.lastName@email.com", result.get("email"));
assertEquals("myBio", result.get("bio"));
assertEquals("images/avatar.jpg", result.get("avatarUrl"));
// Check for duplicate names
createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation",
@@ -144,6 +144,11 @@ public class PersonServiceTest extends BaseWebScriptTest
String organisation, String jobTitle, String email, String bio, String avatarUrl, int expectedStatus)
throws Exception
{
// switch to admin user to create a person
String currentUser = this.authenticationComponent.getCurrentUserName();
String adminUser = this.authenticationComponent.getSystemUserName();
this.authenticationComponent.setCurrentUser(adminUser);
JSONObject person = new JSONObject();
person.put("userName", userName);
person.put("title", title);
@@ -152,11 +157,13 @@ public class PersonServiceTest extends BaseWebScriptTest
person.put("organisation", organisation);
person.put("jobTitle", jobTitle);
person.put("email", email);
person.put("bio", bio);
person.put("avatarUrl", avatarUrl);
MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json");
this.createdPeople.add(userName);
// switch back to non-admin user
this.authenticationComponent.setCurrentUser(currentUser);
return new JSONObject(response.getContentAsString());
}