-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#12770] UpdateStudentActionTest:testExecute split up into multiple s…
…maller test cases
- Loading branch information
1 parent
c507049
commit 9c7022f
Showing
1 changed file
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,7 @@ protected String getRequestMethod() { | |
return PUT; | ||
} | ||
|
||
@Override | ||
@Test | ||
public void testExecute() throws Exception { | ||
private void testExecute_withInvalidParameters() { | ||
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1"); | ||
|
||
|
@@ -56,9 +54,13 @@ public void testExecute() throws Exception { | |
}; | ||
verifyHttpParameterFailure(invalidParams); | ||
verifyNoTasksAdded(); | ||
} | ||
|
||
private JsonResult saveAndUpdateStudent(InstructorAttributes instructor1OfCourse1, | ||
StudentAttributes student1InCourse1, | ||
String newStudentEmail) { | ||
______TS("Typical case, successful edit and save student detail"); | ||
String newStudentEmail = "[email protected]"; | ||
|
||
String newStudentTeam = "new student's team"; | ||
String newStudentComments = "this is new comment after editing"; | ||
StudentUpdateRequest updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), newStudentEmail, | ||
|
@@ -70,7 +72,19 @@ public void testExecute() throws Exception { | |
}; | ||
|
||
UpdateStudentAction updateAction = getAction(updateRequest, submissionParams); | ||
JsonResult actionOutput = getJsonResult(updateAction); | ||
return getJsonResult(updateAction); | ||
} | ||
|
||
@Test | ||
public void testExecute_saveEditStudentDetails() { | ||
|
||
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1"); | ||
String newStudentEmail = "[email protected]"; | ||
String instructorId = instructor1OfCourse1.getGoogleId(); | ||
loginAsInstructor(instructorId); | ||
|
||
JsonResult actionOutput = saveAndUpdateStudent(instructor1OfCourse1, student1InCourse1, newStudentEmail); | ||
|
||
MessageOutput msgOutput = (MessageOutput) actionOutput.getOutput(); | ||
assertEquals("Student has been updated and email sent", msgOutput.getMessage()); | ||
|
@@ -83,13 +97,60 @@ public void testExecute() throws Exception { | |
assertEquals(newStudentEmail, email.getRecipient()); | ||
|
||
verifySpecifiedTasksAdded(Const.TaskQueue.SEARCH_INDEXING_QUEUE_NAME, 1); | ||
} | ||
|
||
@Test | ||
public void testExecute_studentDoesNotExist() { | ||
|
||
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1"); | ||
|
||
String instructorId = instructor1OfCourse1.getGoogleId(); | ||
loginAsInstructor(instructorId); | ||
String newStudentEmail = "[email protected]"; | ||
saveAndUpdateStudent(instructor1OfCourse1, student1InCourse1, newStudentEmail); | ||
______TS("Error case, student does not exist"); | ||
|
||
String nonExistentEmailForStudent = "[email protected]"; | ||
|
||
StudentUpdateRequest updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), | ||
student1InCourse1.getEmail(), | ||
student1InCourse1.getTeam(), | ||
student1InCourse1.getSection(), | ||
student1InCourse1.getComments(), | ||
false); | ||
|
||
String[] submissionParams = new String[] { | ||
Const.ParamsNames.COURSE_ID, instructor1OfCourse1.getCourseId(), | ||
Const.ParamsNames.STUDENT_EMAIL, nonExistentEmailForStudent, | ||
}; | ||
|
||
EntityNotFoundException enfe = verifyEntityNotFound(updateRequest, submissionParams); | ||
assertEquals(UpdateStudentAction.STUDENT_NOT_FOUND_FOR_EDIT, enfe.getMessage()); | ||
|
||
verifyNoTasksAdded(); | ||
} | ||
|
||
@Test | ||
public void testExecute_withNonTrimmedInputAfterSuccessfulEntry() { | ||
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1"); | ||
|
||
String instructorId = instructor1OfCourse1.getGoogleId(); | ||
loginAsInstructor(instructorId); | ||
String newStudentEmail = "[email protected]"; | ||
saveAndUpdateStudent(instructor1OfCourse1, student1InCourse1, newStudentEmail); | ||
|
||
______TS("Typical case, successful edit and save student detail with spaces to be trimmed"); | ||
String newStudentEmailToBeTrimmed = " [email protected] "; // after trim, this is equal to newStudentEmail | ||
String newStudentTeamToBeTrimmed = " New team "; | ||
String newStudentCommentsToBeTrimmed = " this is new comment after editing "; | ||
updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), newStudentEmailToBeTrimmed, | ||
newStudentTeamToBeTrimmed, student1InCourse1.getSection(), newStudentCommentsToBeTrimmed, true); | ||
StudentUpdateRequest updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), | ||
newStudentEmailToBeTrimmed, | ||
newStudentTeamToBeTrimmed, | ||
student1InCourse1.getSection(), | ||
newStudentCommentsToBeTrimmed, | ||
true); | ||
|
||
String[] submissionParamsToBeTrimmed = new String[] { | ||
Const.ParamsNames.COURSE_ID, instructor1OfCourse1.getCourseId(), | ||
|
@@ -102,39 +163,63 @@ public void testExecute() throws Exception { | |
MessageOutput msgTrimmedOutput = (MessageOutput) outputToBeTrimmed.getOutput(); | ||
assertEquals("Student has been updated", msgTrimmedOutput.getMessage()); | ||
verifyNoEmailsSent(); | ||
} | ||
|
||
@Test | ||
public void testExecute_withInvalidEmailParameter() throws ReflectiveOperationException { | ||
|
||
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1"); | ||
|
||
String instructorId = instructor1OfCourse1.getGoogleId(); | ||
loginAsInstructor(instructorId); | ||
String newStudentEmail = "[email protected]"; | ||
saveAndUpdateStudent(instructor1OfCourse1, student1InCourse1, newStudentEmail); | ||
|
||
______TS("Error case, invalid email parameter (email has too many characters)"); | ||
|
||
String invalidStudentEmail = StringHelperExtension.generateStringOfLength(255 - "@gmail.tmt".length()) | ||
+ "@gmail.tmt"; | ||
assertEquals(FieldValidator.EMAIL_MAX_LENGTH + 1, invalidStudentEmail.length()); | ||
|
||
updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), invalidStudentEmail, | ||
StudentUpdateRequest updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), invalidStudentEmail, | ||
student1InCourse1.getTeam(), student1InCourse1.getSection(), student1InCourse1.getComments(), false); | ||
|
||
submissionParams = new String[] { | ||
String[] submissionParams = new String[] { | ||
Const.ParamsNames.COURSE_ID, instructor1OfCourse1.getCourseId(), | ||
Const.ParamsNames.STUDENT_EMAIL, newStudentEmail, | ||
}; | ||
|
||
InvalidHttpRequestBodyException ihrbe = verifyHttpRequestBodyFailure(updateRequest, submissionParams); | ||
|
||
assertEquals(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, invalidStudentEmail, | ||
FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_TOO_LONG, | ||
FieldValidator.EMAIL_MAX_LENGTH), | ||
FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_TOO_LONG, | ||
FieldValidator.EMAIL_MAX_LENGTH), | ||
ihrbe.getMessage()); | ||
|
||
verifyNoTasksAdded(); | ||
} | ||
|
||
@Test | ||
public void testExecute_emailAlreadyTaken() { | ||
|
||
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1"); | ||
|
||
String instructorId = instructor1OfCourse1.getGoogleId(); | ||
loginAsInstructor(instructorId); | ||
String newStudentEmail = "[email protected]"; | ||
saveAndUpdateStudent(instructor1OfCourse1, student1InCourse1, newStudentEmail); | ||
|
||
______TS("Error case, invalid email parameter (email already taken by others)"); | ||
|
||
StudentAttributes student2InCourse1 = typicalBundle.students.get("student2InCourse1"); | ||
String takenStudentEmail = student2InCourse1.getEmail(); | ||
|
||
updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), takenStudentEmail, | ||
StudentUpdateRequest updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), takenStudentEmail, | ||
student1InCourse1.getTeam(), student1InCourse1.getSection(), student1InCourse1.getComments(), false); | ||
|
||
submissionParams = new String[] { | ||
String[] submissionParams = new String[] { | ||
Const.ParamsNames.COURSE_ID, instructor1OfCourse1.getCourseId(), | ||
Const.ParamsNames.STUDENT_EMAIL, newStudentEmail, | ||
}; | ||
|
@@ -147,22 +232,6 @@ public void testExecute() throws Exception { | |
// deleting edited student | ||
logic.deleteAccountCascade(student2InCourse1.getGoogleId()); | ||
logic.deleteAccountCascade(student1InCourse1.getGoogleId()); | ||
|
||
______TS("Error case, student does not exist"); | ||
|
||
String nonExistentEmailForStudent = "[email protected]"; | ||
updateRequest = new StudentUpdateRequest(student1InCourse1.getName(), student1InCourse1.getEmail(), | ||
student1InCourse1.getTeam(), student1InCourse1.getSection(), student1InCourse1.getComments(), false); | ||
|
||
submissionParams = new String[] { | ||
Const.ParamsNames.COURSE_ID, instructor1OfCourse1.getCourseId(), | ||
Const.ParamsNames.STUDENT_EMAIL, nonExistentEmailForStudent, | ||
}; | ||
|
||
EntityNotFoundException enfe = verifyEntityNotFound(updateRequest, submissionParams); | ||
assertEquals(UpdateStudentAction.STUDENT_NOT_FOUND_FOR_EDIT, enfe.getMessage()); | ||
|
||
verifyNoTasksAdded(); | ||
} | ||
|
||
@Test | ||
|
@@ -275,6 +344,13 @@ public void testExecute_withEmptySectionName_shouldBeUpdatedWithDefaultSectionNa | |
assertEquals(student5InCourse1.getComments(), actualStudent.getComments()); | ||
} | ||
|
||
@Override | ||
|
||
@Test | ||
public void testExecute() throws Exception { | ||
testExecute_withInvalidParameters(); | ||
} | ||
|
||
@Override | ||
@Test | ||
protected void testAccessControl() throws Exception { | ||
|