Fixed check for missing user name parameter, and added checks for missing first name and missing last name parameters, to Person Service REST API method POST People.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10215 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Glen Johnson
2008-08-04 02:32:28 +00:00
parent 57668a2647
commit 0a6cccc428
2 changed files with 70 additions and 7 deletions

View File

@@ -1,14 +1,29 @@
function main()
{
//
// Get the person details
var userName = json.get("userName");
if ((userName === null) || (userName.length == 0))
//
if ((json.isNull("userName")) || (json.get("userName").length() == 0))
{
status.setCode(status.STATUS_BAD_REQUEST, "User name missing when creating person")
status.setCode(status.STATUS_BAD_REQUEST, "User name missing when creating person");
return;
}
if ((json.isNull("firstName")) || (json.get("firstName").length() == 0))
{
status.setCode(status.STATUS_BAD_REQUEST, "First name missing when creating person");
return;
}
if ((json.isNull("lastName")) || (json.get("lastName").length() == 0))
{
status.setCode(status.STATUS_BAD_REQUEST, "Last name missing when creating person");
return;
}
// Create the person with the supplied user name
var userName = json.get("userName");
var person = people.createPerson(userName);
// return error message if a person with that user name could not be created

View File

@@ -169,7 +169,11 @@ public class PersonServiceTest extends BaseWebScriptTest
person.put("email", email);
MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json");
if ((userName != null) && (userName.length() != 0))
{
this.createdPeople.add(userName);
}
// switch back to non-admin user
this.authenticationComponent.setCurrentUser(currentUser);
@@ -265,9 +269,10 @@ public class PersonServiceTest extends BaseWebScriptTest
{
String userName = RandomStringUtils.randomNumeric(6);
// Create a new site
// Create a new person
JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK);
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_OK);
assertEquals(userName, result.get("userName"));
assertEquals("myTitle", result.get("title"));
assertEquals("myFirstName", result.get("firstName"));
@@ -280,4 +285,47 @@ public class PersonServiceTest extends BaseWebScriptTest
createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation",
"myJobTitle", "myEmail", "myBio", "images/avatar.jpg", 500);
}
public void testCreatePersonMissingUserName() throws Exception
{
// Create a new person with userName == null (user name missing)
createPerson(null, "myTitle", "myFirstName", "myLastName", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_BAD_REQUEST);
// Create a new person with userName == "" (user name is blank)
createPerson("", "myTitle", "myFirstName", "myLastName", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_BAD_REQUEST);
}
public void testCreatePersonMissingFirstName() throws Exception
{
String userName = RandomStringUtils.randomNumeric(6);
// Create a new person with firstName == null (first name missing)
createPerson(userName, "myTitle", null, "myLastName", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_BAD_REQUEST);
// Create a new person with firstName == "" (first name is blank)
createPerson(userName, "myTitle", "", "myLastName", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_BAD_REQUEST);
}
public void testCreatePersonMissingLastName() throws Exception
{
String userName = RandomStringUtils.randomNumeric(6);
// Create a new person with lastName == null (last name is missing)
createPerson(userName, "myTitle", "myFirstName", null, "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_BAD_REQUEST);
// Create a new person with lastName == "" (last name is blank)
createPerson(userName, "myTitle", "myFirstName", "", "myOrganisation",
"myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg",
Status.STATUS_BAD_REQUEST);
}
}