diff --git a/src/e2e/java/teammates/e2e/cases/InstructorCourseDetailsPageE2ETest.java b/src/e2e/java/teammates/e2e/cases/InstructorCourseDetailsPageE2ETest.java index f8d0f09f89d..b2885be1c09 100644 --- a/src/e2e/java/teammates/e2e/cases/InstructorCourseDetailsPageE2ETest.java +++ b/src/e2e/java/teammates/e2e/cases/InstructorCourseDetailsPageE2ETest.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Set; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -77,26 +78,26 @@ public void testAll() { StudentAttributes studentToView = testData.students.get("benny.tmms@ICDet.CS2104"); InstructorCourseStudentDetailsViewPage studentDetailsViewPage = - detailsPage.clickViewStudent(studentToView); + detailsPage.clickViewStudent(studentToView.getEmail()); studentDetailsViewPage.verifyIsCorrectPage(course.getId(), studentToView.getEmail()); studentDetailsViewPage.closeCurrentWindowAndSwitchToParentWindow(); ______TS("link: edit student details page"); InstructorCourseStudentDetailsEditPage studentDetailsEditPage = - detailsPage.clickEditStudent(studentToView); + detailsPage.clickEditStudent(studentToView.getEmail()); studentDetailsEditPage.verifyIsCorrectPage(course.getId(), studentToView.getEmail()); studentDetailsEditPage.closeCurrentWindowAndSwitchToParentWindow(); ______TS("link: view all records page"); InstructorStudentRecordsPage studentRecordsPage = - detailsPage.clickViewAllRecords(studentToView); + detailsPage.clickViewAllRecords(studentToView.getEmail()); studentRecordsPage.verifyIsCorrectPage(course.getId(), studentToView.getName()); studentRecordsPage.closeCurrentWindowAndSwitchToParentWindow(); ______TS("send invite"); - detailsPage.sendInvite(student); + detailsPage.sendInvite(student.getEmail()); detailsPage.verifyStatusMessage("An email has been sent to " + student.getEmail()); String expectedEmailSubject = "TEAMMATES: Invitation to join course [" @@ -121,7 +122,7 @@ public void testAll() { detailsPage.sortByName(); detailsPage.sortByStatus(); StudentAttributes[] studentsAfterDelete = { students[0], students[3], students[1] }; - detailsPage.deleteStudent(student); + detailsPage.deleteStudent(student.getEmail()); detailsPage.verifyStatusMessage("Student is successfully deleted from course \"" + course.getId() + "\""); @@ -139,6 +140,11 @@ public void testAll() { } } + @AfterClass + public void classTearDown() { + BACKDOOR.removeDataBundle(testData); + } + private void verifyCourseDetails(InstructorCourseDetailsPage detailsPage, CourseAttributes course, InstructorAttributes[] instructors, StudentAttributes[] students) { Set sections = new HashSet<>(); diff --git a/src/e2e/java/teammates/e2e/cases/sql/BaseE2ETestCase.java b/src/e2e/java/teammates/e2e/cases/sql/BaseE2ETestCase.java index dc957a59d67..b61a4a8cf2a 100644 --- a/src/e2e/java/teammates/e2e/cases/sql/BaseE2ETestCase.java +++ b/src/e2e/java/teammates/e2e/cases/sql/BaseE2ETestCase.java @@ -22,11 +22,13 @@ import teammates.e2e.util.TestProperties; import teammates.storage.sqlentity.FeedbackQuestion; import teammates.storage.sqlentity.FeedbackResponse; +import teammates.storage.sqlentity.Student; import teammates.test.BaseTestCaseWithSqlDatabaseAccess; import teammates.test.FileHelper; import teammates.test.ThreadHelper; import teammates.ui.output.FeedbackQuestionData; import teammates.ui.output.FeedbackResponseData; +import teammates.ui.output.StudentData; /** * Base class for all browser tests. @@ -254,4 +256,13 @@ FeedbackResponseData getFeedbackResponse(String questionId, String giver, String protected FeedbackResponseData getFeedbackResponse(FeedbackResponse fr) { return getFeedbackResponse(fr.getFeedbackQuestion().getId().toString(), fr.getGiver(), fr.getRecipient()); } + + StudentData getStudent(String courseId, String studentEmailAddress) { + return BACKDOOR.getStudentData(courseId, studentEmailAddress); + } + + @Override + protected StudentData getStudent(Student student) { + return getStudent(student.getCourseId(), student.getEmail()); + } } diff --git a/src/e2e/java/teammates/e2e/cases/sql/InstructorCourseDetailsPageE2ETest.java b/src/e2e/java/teammates/e2e/cases/sql/InstructorCourseDetailsPageE2ETest.java new file mode 100644 index 00000000000..e80168fca4c --- /dev/null +++ b/src/e2e/java/teammates/e2e/cases/sql/InstructorCourseDetailsPageE2ETest.java @@ -0,0 +1,139 @@ +package teammates.e2e.cases.sql; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import teammates.common.util.AppUrl; +import teammates.common.util.Const; +import teammates.e2e.pageobjects.InstructorCourseDetailsPage; +import teammates.e2e.pageobjects.InstructorCourseStudentDetailsEditPage; +import teammates.e2e.pageobjects.InstructorCourseStudentDetailsViewPage; +import teammates.e2e.pageobjects.InstructorStudentRecordsPage; +import teammates.e2e.util.TestProperties; +import teammates.storage.sqlentity.Course; +import teammates.storage.sqlentity.Instructor; +import teammates.storage.sqlentity.Student; + +/** + * SUT: {@link Const.WebPageURIs#INSTRUCTOR_COURSE_DETAILS_PAGE}. + */ +public class InstructorCourseDetailsPageE2ETest extends BaseE2ETestCase { + private Course course; + private Student student3; + private String downloadedFileName; + + @Override + protected void prepareTestData() { + testData = loadSqlDataBundle("/InstructorCourseDetailsPageE2ESqlTest.json"); + student3 = testData.students.get("charlie.tmms@ICDet.CS2104"); + student3.setEmail(TestProperties.TEST_EMAIL); + removeAndRestoreDataBundle(testData); + course = testData.courses.get("ICDet.CS2104"); + downloadedFileName = "/" + course.getId() + "_studentList.csv"; + } + + @BeforeClass + public void classSetup() { + deleteDownloadsFile(downloadedFileName); + } + + @AfterClass + public void classTearDown() { + deleteDownloadsFile(downloadedFileName); + BACKDOOR.removeSqlDataBundle(testData); + } + + @Test + @Override + protected void testAll() { + Instructor instructor1 = testData.instructors.get("ICDet.instr"); + AppUrl detailsPageUrl = createFrontendUrl(Const.WebPageURIs.INSTRUCTOR_COURSE_DETAILS_PAGE) + .withCourseId(course.getId()); + InstructorCourseDetailsPage detailsPage = + loginToPage(detailsPageUrl, InstructorCourseDetailsPage.class, instructor1.getGoogleId()); + + ______TS("verify loaded details"); + List instructors = Arrays.asList(instructor1, testData.instructors.get("ICDet.instr2")); + List students = Arrays.asList( + testData.students.get("alice.tmms@ICDet.CS2104"), + testData.students.get("benny.tmms@ICDet.CS2104"), + testData.students.get("charlie.tmms@ICDet.CS2104"), + testData.students.get("danny.tmms@ICDet.CS2104") + ); + Set sectionNames = new HashSet<>(); + Set teamNames = new HashSet<>(); + students.forEach(student -> { + sectionNames.add(student.getSectionName()); + teamNames.add(student.getTeamName()); + }); + detailsPage.verifyCourseDetails(course, instructors, sectionNames.size(), teamNames.size(), students.size()); + detailsPage.verifyNumStudents(students.size()); + detailsPage.verifyStudentDetails(students); + + ______TS("link: view student details page"); + Student studentToView = testData.students.get("benny.tmms@ICDet.CS2104"); + InstructorCourseStudentDetailsViewPage studentDetailsViewPage = + detailsPage.clickViewStudent(studentToView.getEmail()); + studentDetailsViewPage.verifyIsCorrectPage(course.getId(), studentToView.getEmail()); + studentDetailsViewPage.closeCurrentWindowAndSwitchToParentWindow(); + + ______TS("link: edit student details page"); + InstructorCourseStudentDetailsEditPage studentDetailsEditPage = + detailsPage.clickEditStudent(studentToView.getEmail()); + studentDetailsEditPage.verifyIsCorrectPage(course.getId(), studentToView.getEmail()); + studentDetailsEditPage.closeCurrentWindowAndSwitchToParentWindow(); + + ______TS("link: view all records page"); + InstructorStudentRecordsPage studentRecordsPage = + detailsPage.clickViewAllRecords(studentToView.getEmail()); + studentRecordsPage.verifyIsCorrectPage(course.getId(), studentToView.getName()); + studentRecordsPage.closeCurrentWindowAndSwitchToParentWindow(); + + ______TS("send invite"); + detailsPage.sendInvite(student3.getEmail()); + detailsPage.verifyStatusMessage("An email has been sent to " + student3.getEmail()); + String expectedEmailSubject = "TEAMMATES: Invitation to join course [" + + course.getName() + "][Course ID: " + course.getId() + "]"; + verifyEmailSent(student3.getEmail(), expectedEmailSubject); + + ______TS("remind all students to join"); + detailsPage.remindAllToJoin(); + detailsPage.verifyStatusMessage("Emails have been sent to unregistered students."); + verifyEmailSent(student3.getEmail(), expectedEmailSubject); + + ______TS("download student list"); + detailsPage.downloadStudentList(); + String status = "Yet to Join"; + String[] studentInfo = { student3.getTeamName(), student3.getName(), status, student3.getEmail() }; + List expectedContent = Arrays.asList("Course ID," + course.getId(), + "Course Name," + course.getName(), String.join(",", studentInfo)); + verifyDownloadedFile(downloadedFileName, expectedContent); + + ______TS("delete student"); + detailsPage.sortByName(); + detailsPage.sortByStatus(); + List studentsAfterDelete = Arrays.asList( + testData.students.get("alice.tmms@ICDet.CS2104"), + testData.students.get("danny.tmms@ICDet.CS2104"), + testData.students.get("benny.tmms@ICDet.CS2104") + ); + detailsPage.deleteStudent(student3.getEmail()); + detailsPage.verifyStatusMessage("Student is successfully deleted from course \"" + + course.getId() + "\""); + detailsPage.verifyNumStudents(studentsAfterDelete.size()); + detailsPage.verifyStudentDetails(studentsAfterDelete); + verifyAbsentInDatabase(student3); + + ______TS("delete all students"); + detailsPage.deleteAllStudents(); + detailsPage.verifyStatusMessage("All the students have been removed from the course"); + detailsPage.verifyNumStudents(0); + studentsAfterDelete.forEach(this::verifyAbsentInDatabase); + } +} diff --git a/src/e2e/java/teammates/e2e/pageobjects/InstructorCourseDetailsPage.java b/src/e2e/java/teammates/e2e/pageobjects/InstructorCourseDetailsPage.java index 237bed8e2f3..14f34f842f9 100644 --- a/src/e2e/java/teammates/e2e/pageobjects/InstructorCourseDetailsPage.java +++ b/src/e2e/java/teammates/e2e/pageobjects/InstructorCourseDetailsPage.java @@ -15,6 +15,9 @@ import teammates.common.datatransfer.attributes.InstructorAttributes; import teammates.common.datatransfer.attributes.StudentAttributes; import teammates.e2e.util.TestProperties; +import teammates.storage.sqlentity.Course; +import teammates.storage.sqlentity.Instructor; +import teammates.storage.sqlentity.Student; import teammates.test.ThreadHelper; /** @@ -62,16 +65,31 @@ public void verifyCourseDetails(CourseAttributes course, InstructorAttributes[] assertEquals(getExpectedInstructorString(instructors), instructorsField.getText()); } + public void verifyCourseDetails(Course course, List instructors, int numSections, int numTeams, + int numStudents) { + assertEquals(course.getId(), courseIdField.getText()); + assertEquals(course.getName(), courseNameField.getText()); + assertEquals(course.getInstitute(), courseInstituteField.getText()); + assertEquals(Integer.toString(numSections), numSectionsField.getText()); + assertEquals(Integer.toString(numTeams), numTeamsField.getText()); + assertEquals(Integer.toString(numStudents), numStudentsField.getText()); + assertEquals(getExpectedInstructorsString(instructors), instructorsField.getText()); + } + public void verifyStudentDetails(StudentAttributes[] students) { verifyTableBodyValues(getStudentList(), getExpectedStudentValues(students)); } + public void verifyStudentDetails(List students) { + verifyTableBodyValues(getStudentList(), getExpectedStudentValues(students)); + } + public void verifyNumStudents(int expected) { assertEquals(expected, getNumStudents()); } - public void sendInvite(StudentAttributes student) { - clickAndConfirm(getSendInviteButton(student)); + public void sendInvite(String studentEmailAddress) { + clickAndConfirm(getSendInviteButton(studentEmailAddress)); } public void remindAllToJoin() { @@ -92,8 +110,8 @@ public void sortByStatus() { waitUntilAnimationFinish(); } - public void deleteStudent(StudentAttributes student) { - clickAndConfirm(getDeleteButton(student)); + public void deleteStudent(String studentEmailAddress) { + clickAndConfirm(getDeleteButton(studentEmailAddress)); } public void deleteAllStudents() { @@ -106,6 +124,13 @@ private String getExpectedInstructorString(InstructorAttributes[] instructors) { .collect(Collectors.joining(TestProperties.LINE_SEPARATOR)); } + private String getExpectedInstructorsString(List instructors) { + return instructors.stream() + .map(instructor -> instructor.getRole().getRoleName() + ": " + + instructor.getName() + " (" + instructor.getEmail() + ")") + .collect(Collectors.joining(TestProperties.LINE_SEPARATOR)); + } + private WebElement getStudentList() { return browser.driver.findElement(By.cssSelector("#student-list table")); } @@ -123,13 +148,31 @@ private String[][] getExpectedStudentValues(StudentAttributes[] students) { return expected; } - private WebElement getSendInviteButton(StudentAttributes student) { - WebElement studentRow = getStudentRow(student); + private String[][] getExpectedStudentValues(List students) { + String[][] expected = new String[students.size()][5]; + for (int i = 0; i < students.size(); i++) { + Student student = students.get(i); + expected[i][0] = student.getSectionName(); + expected[i][1] = student.getTeamName(); + expected[i][2] = student.getName(); + String googleId = student.getGoogleId(); + if (googleId == null || googleId.isEmpty()) { + expected[i][3] = "Yet to Join"; + } else { + expected[i][3] = "Joined"; + } + expected[i][4] = student.getEmail(); + } + return expected; + } + + private WebElement getSendInviteButton(String studentEmailAddress) { + WebElement studentRow = getStudentRow(studentEmailAddress); return studentRow.findElement(By.cssSelector("[id^='btn-send-invite-']")); } - private WebElement getDeleteButton(StudentAttributes student) { - WebElement studentRow = getStudentRow(student); + private WebElement getDeleteButton(String studentEmailAddress) { + WebElement studentRow = getStudentRow(studentEmailAddress); return studentRow.findElement(By.cssSelector("[id^='btn-delete-']")); } @@ -145,19 +188,19 @@ private int getNumStudents() { } } - private WebElement getStudentRow(StudentAttributes student) { + private WebElement getStudentRow(String studentEmailAddress) { List studentRows = getAllStudentRows(); for (WebElement studentRow : studentRows) { List studentCells = studentRow.findElements(By.tagName("td")); - if (studentCells.get(4).getText().equals(student.getEmail())) { + if (studentCells.get(4).getText().equals(studentEmailAddress)) { return studentRow; } } return null; } - public InstructorCourseStudentDetailsViewPage clickViewStudent(StudentAttributes student) { - WebElement studentRow = getStudentRow(student); + public InstructorCourseStudentDetailsViewPage clickViewStudent(String studentEmailAddress) { + WebElement studentRow = getStudentRow(studentEmailAddress); WebElement viewButton = studentRow.findElement(By.cssSelector("[id^='btn-view-details-']")); click(viewButton); ThreadHelper.waitFor(2000); @@ -165,8 +208,8 @@ public InstructorCourseStudentDetailsViewPage clickViewStudent(StudentAttributes return changePageType(InstructorCourseStudentDetailsViewPage.class); } - public InstructorCourseStudentDetailsEditPage clickEditStudent(StudentAttributes student) { - WebElement studentRow = getStudentRow(student); + public InstructorCourseStudentDetailsEditPage clickEditStudent(String studentEmailAddress) { + WebElement studentRow = getStudentRow(studentEmailAddress); WebElement viewButton = studentRow.findElement(By.cssSelector("[id^='btn-edit-details-']")); click(viewButton); ThreadHelper.waitFor(2000); @@ -174,8 +217,8 @@ public InstructorCourseStudentDetailsEditPage clickEditStudent(StudentAttributes return changePageType(InstructorCourseStudentDetailsEditPage.class); } - public InstructorStudentRecordsPage clickViewAllRecords(StudentAttributes student) { - WebElement studentRow = getStudentRow(student); + public InstructorStudentRecordsPage clickViewAllRecords(String studentEmailAddress) { + WebElement studentRow = getStudentRow(studentEmailAddress); WebElement viewButton = studentRow.findElement(By.cssSelector("[id^='btn-view-records-']")); click(viewButton); ThreadHelper.waitFor(2000); diff --git a/src/e2e/resources/data/InstructorCourseDetailsPageE2ESqlTest.json b/src/e2e/resources/data/InstructorCourseDetailsPageE2ESqlTest.json new file mode 100644 index 00000000000..8bbd4548de3 --- /dev/null +++ b/src/e2e/resources/data/InstructorCourseDetailsPageE2ESqlTest.json @@ -0,0 +1,203 @@ +{ + "accounts": { + "ICDet.instr": { + "id": "00000000-0000-4000-8000-000000000001", + "googleId": "tm.e2e.ICDet.instr", + "name": "Teammates Test", + "email": "ICDet.instr@gmail.tmt" + }, + "ICDet.instr2": { + "id": "00000000-0000-4000-8000-000000000002", + "googleId": "tm.e2e.ICDet.instr2", + "name": "Teammates Test 2", + "email": "ICDet.instr2@gmail.tmt" + }, + "Alice": { + "id": "00000000-0000-4000-8000-000000000003", + "googleId": "tm.e2e.ICDet.alice.b", + "name": "Alice Betsy", + "email": "alice.b.tmms@gmail.tmt" + }, + "Danny": { + "id": "00000000-0000-4000-8000-000000000004", + "googleId": "tm.e2e.ICDet.danny.e", + "name": "Charlie Davis", + "email": "danny.e.tmms@gmail.tmt" + } + }, + "courses": { + "ICDet.CS2104": { + "id": "tm.e2e.ICDet.CS2104", + "name": "Programming Language Concepts", + "institute": "TEAMMATES Test Institute 1", + "timeZone": "UTC" + } + }, + "instructors": { + "ICDet.instr": { + "id": "00000000-0000-4000-8000-000000000501", + "account": { + "id": "00000000-0000-4000-8000-000000000001" + }, + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "name": "ICDet Instructor 1", + "email": "ICDet.instr@gmail.tmt", + "role": "INSTRUCTOR_PERMISSION_ROLE_COOWNER", + "isDisplayedToStudents": true, + "displayName": "ICDet Instructor 1", + "privileges": { + "courseLevel": { + "canModifyCourse": true, + "canModifyInstructor": true, + "canModifySession": true, + "canModifyStudent": true, + "canViewStudentInSections": true, + "canViewSessionInSections": true, + "canSubmitSessionInSections": true, + "canModifySessionCommentsInSections": true + }, + "sectionLevel": {}, + "sessionLevel": {} + } + }, + "ICDet.instr2": { + "id": "00000000-0000-4000-8000-000000000502", + "account": { + "id": "00000000-0000-4000-8000-000000000002" + }, + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "name": "ICDet Instructor 2", + "email": "ICDet.instr2@gmail.tmt", + "role": "INSTRUCTOR_PERMISSION_ROLE_TUTOR", + "isDisplayedToStudents": true, + "displayName": "ICDet Instructor 2", + "privileges": { + "courseLevel": { + "canViewStudentInSections": true, + "canSubmitSessionInSections": true, + "canModifySessionCommentsInSections": false, + "canModifyCourse": false, + "canViewSessionInSections": true, + "canModifySession": false, + "canModifyStudent": false, + "canModifyInstructor": false + }, + "sectionLevel": {}, + "sessionLevel": {} + } + } + }, + "students": { + "alice.tmms@ICDet.CS2104": { + "id": "00000000-0000-4000-8000-000000000601", + "account": { + "id": "00000000-0000-4000-8000-000000000003" + }, + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "team": { + "id": "00000000-0000-4000-8000-000000000301" + }, + "email": "alice.b.tmms@gmail.tmt", + "name": "Alice Betsy", + "comments": "This student's name is Alice Betsy" + }, + "benny.tmms@ICDet.CS2104": { + "id": "00000000-0000-4000-8000-000000000602", + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "team": { + "id": "00000000-0000-4000-8000-000000000302" + }, + "email": "benny.c.tmms@gmail.tmt", + "name": "Benny Charles", + "comments": "This student's name is Benny Charles" + }, + "charlie.tmms@ICDet.CS2104": { + "id": "00000000-0000-4000-8000-000000000603", + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "team": { + "id": "00000000-0000-4000-8000-000000000303" + }, + "email": "charlie.d.tmms@gmail.tmt", + "name": "Charlie Davis", + "comments": "This student's name is Charlie Davis" + }, + "danny.tmms@ICDet.CS2104": { + "id": "00000000-0000-4000-8000-000000000604", + "account": { + "id": "00000000-0000-4000-8000-000000000004" + }, + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "team": { + "id": "00000000-0000-4000-8000-000000000304" + }, + "email": "danny.e.tmms@gmail.tmt", + "name": "Danny Engrid", + "comments": "This student's name is Danny Engrid" + } + }, + "sections": { + "sectionNoneInCourse1": { + "id": "00000000-0000-4000-8000-000000000200", + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "name": "None" + }, + "section1InCourse1": { + "id": "00000000-0000-4000-8000-000000000201", + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "name": "Section 1" + }, + "section2InCourse1": { + "id": "00000000-0000-4000-8000-000000000202", + "course": { + "id": "tm.e2e.ICDet.CS2104" + }, + "name": "Section 2" + } + }, + "teams": { + "team1InSectionNone": { + "id": "00000000-0000-4000-8000-000000000301", + "section": { + "id": "00000000-0000-4000-8000-000000000200" + }, + "name": "Team 1" + }, + "team2InSectionNone": { + "id": "00000000-0000-4000-8000-000000000302", + "section": { + "id": "00000000-0000-4000-8000-000000000200" + }, + "name": "Team 2" + }, + "team1InSection1": { + "id": "00000000-0000-4000-8000-000000000303", + "section": { + "id": "00000000-0000-4000-8000-000000000201" + }, + "name": "Team 1" + }, + "team2InSection2": { + "id": "00000000-0000-4000-8000-000000000304", + "section": { + "id": "00000000-0000-4000-8000-000000000202" + }, + "name": "Team 2" + } + } +} diff --git a/src/e2e/resources/testng-e2e-sql.xml b/src/e2e/resources/testng-e2e-sql.xml index bfb28c3b2c0..78dcc2d13a1 100644 --- a/src/e2e/resources/testng-e2e-sql.xml +++ b/src/e2e/resources/testng-e2e-sql.xml @@ -9,6 +9,7 @@ + diff --git a/src/test/java/teammates/test/BaseTestCaseWithSqlDatabaseAccess.java b/src/test/java/teammates/test/BaseTestCaseWithSqlDatabaseAccess.java index 831d34a7e67..dddf3288a93 100644 --- a/src/test/java/teammates/test/BaseTestCaseWithSqlDatabaseAccess.java +++ b/src/test/java/teammates/test/BaseTestCaseWithSqlDatabaseAccess.java @@ -203,8 +203,24 @@ protected void verifyPresentInDatabase(BaseEntity expected) { verifyEquals(expected, actual); } + /** + * Verifies that the given entity is absent in the database. + */ + protected void verifyAbsentInDatabase(BaseEntity expected) { + int retryLimit = VERIFICATION_RETRY_COUNT; + ApiOutput actual = getEntity(expected); + while (actual != null && retryLimit > 0) { + retryLimit--; + ThreadHelper.waitFor(VERIFICATION_RETRY_DELAY_IN_MS); + actual = getEntity(expected); + } + assertNull(actual); + } + private ApiOutput getEntity(BaseEntity entity) { - if (entity instanceof FeedbackQuestion) { + if (entity instanceof Student) { + return getStudent((Student) entity); + } else if (entity instanceof FeedbackQuestion) { return getFeedbackQuestion((FeedbackQuestion) entity); } else if (entity instanceof FeedbackResponse) { return getFeedbackResponse((FeedbackResponse) entity); @@ -217,4 +233,6 @@ private ApiOutput getEntity(BaseEntity entity) { protected abstract FeedbackResponseData getFeedbackResponse(FeedbackResponse fq); + protected abstract StudentData getStudent(Student student); + }