-
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.
Browse files
Browse the repository at this point in the history
* Add methods for updating and deleting deadline maps for a user * Add tests for updating and deleting deadline maps for a user * Cascade instructor updates or deletes to deadline maps * Test cascade of instructor updates or deletes to deadline maps * Cascade student updates or deletes to deadline maps * Test cascade of student updates or deletes to deadline maps * Match deadline extension entities with deadline maps * Change deadlinesUpdater into a Consumer * Change unexpected error assertion into a severe log * Improve readability of feedback session deadline map update code * Clean code * Clean code further
- Loading branch information
1 parent
ba0980f
commit 87d60c5
Showing
8 changed files
with
475 additions
and
6 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
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
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
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 |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
@@ -724,6 +728,162 @@ public void testUpdateFeedbackSession_shouldAdjustEmailSendingStatusAccordingly( | |
typicalSession.getFeedbackSessionName(), typicalSession.getCourseId()).isSentPublishedEmail()); | ||
} | ||
|
||
@Test | ||
public void testUpdateFeedbackSessionsInstructorDeadlinesWithNewEmail() { | ||
InstructorAttributes instructorToBeUpdated = dataBundle.instructors.get("instructor1OfCourse1"); | ||
String courseId = instructorToBeUpdated.getCourseId(); | ||
String oldEmailAddress = instructorToBeUpdated.getEmail(); | ||
String newEmailAddress = "[email protected]"; | ||
|
||
______TS("Update email; transfers deadlines to new email."); | ||
|
||
Map<Instant, Integer> oldDeadlineCounts = fsLogic.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.map(FeedbackSessionAttributes::getInstructorDeadlines) | ||
.filter(instructorDeadlines -> instructorDeadlines.containsKey(oldEmailAddress)) | ||
.map(instructorDeadlines -> instructorDeadlines.get(oldEmailAddress)) | ||
.collect(Collectors.groupingBy(Function.identity(), Collectors.summingInt(deadline -> 1))); | ||
assertEquals(2, oldDeadlineCounts.values() | ||
.stream() | ||
.reduce(0, Integer::sum) | ||
.intValue()); | ||
|
||
fsLogic.updateFeedbackSessionsInstructorDeadlinesWithNewEmail(courseId, oldEmailAddress, newEmailAddress); | ||
|
||
assertTrue(fsLogic.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.noneMatch(feedbackSessionAttributes -> feedbackSessionAttributes.getInstructorDeadlines() | ||
.containsKey(oldEmailAddress))); | ||
Map<Instant, Integer> newDeadlineCounts = fsLogic.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.map(FeedbackSessionAttributes::getInstructorDeadlines) | ||
.filter(instructorDeadlines -> instructorDeadlines.containsKey(newEmailAddress)) | ||
.map(instructorDeadlines -> instructorDeadlines.get(newEmailAddress)) | ||
.collect(Collectors.groupingBy(Function.identity(), Collectors.summingInt(deadline -> 1))); | ||
assertEquals(oldDeadlineCounts, newDeadlineCounts); | ||
} | ||
|
||
@Test | ||
public void testUpdateFeedbackSessionsStudentDeadlinesWithNewEmail() { | ||
StudentAttributes student4InCourse1 = dataBundle.students.get("student4InCourse1"); | ||
String courseId = student4InCourse1.getCourse(); | ||
String oldEmailAddress = student4InCourse1.getEmail(); | ||
String newEmailAddress = "[email protected]"; | ||
|
||
______TS("Update email; transfers deadlines to new email."); | ||
|
||
Map<Instant, Integer> oldDeadlineCounts = fsLogic.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.map(FeedbackSessionAttributes::getStudentDeadlines) | ||
.filter(studentDeadlines -> studentDeadlines.containsKey(oldEmailAddress)) | ||
.map(studentDeadlines -> studentDeadlines.get(oldEmailAddress)) | ||
.collect(Collectors.groupingBy(Function.identity(), Collectors.summingInt(deadline -> 1))); | ||
assertEquals(2, oldDeadlineCounts.values() | ||
.stream() | ||
.reduce(0, Integer::sum) | ||
.intValue()); | ||
|
||
fsLogic.updateFeedbackSessionsStudentDeadlinesWithNewEmail(courseId, oldEmailAddress, newEmailAddress); | ||
|
||
assertTrue(fsLogic.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.noneMatch(feedbackSessionAttributes -> feedbackSessionAttributes.getStudentDeadlines() | ||
.containsKey(oldEmailAddress))); | ||
Map<Instant, Integer> newDeadlineCounts = fsLogic.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.map(FeedbackSessionAttributes::getStudentDeadlines) | ||
.filter(studentDeadlines -> studentDeadlines.containsKey(newEmailAddress)) | ||
.map(studentDeadlines -> studentDeadlines.get(newEmailAddress)) | ||
.collect(Collectors.groupingBy(Function.identity(), Collectors.summingInt(deadline -> 1))); | ||
assertEquals(oldDeadlineCounts, newDeadlineCounts); | ||
} | ||
|
||
@Test | ||
public void testDeleteFeedbackSessionsDeadlinesForInstructor() { | ||
InstructorAttributes instructor1OfCourse1 = dataBundle.instructors.get("instructor1OfCourse1"); | ||
verifyPresentInDatabase(instructor1OfCourse1); | ||
|
||
String courseId = instructor1OfCourse1.getCourseId(); | ||
String emailAddress = instructor1OfCourse1.getEmail(); | ||
|
||
______TS("Delete user; deadlines associated with the email are removed."); | ||
|
||
// The instructor should have selective deadlines. | ||
Set<FeedbackSessionAttributes> oldSessionsWithInstructor1Deadlines = fsLogic | ||
.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.filter(feedbackSessionAttributes -> feedbackSessionAttributes.getInstructorDeadlines() | ||
.containsKey(emailAddress)) | ||
.collect(Collectors.toSet()); | ||
Map<FeedbackSessionAttributes, Integer> oldSessionsDeadlineCounts = oldSessionsWithInstructor1Deadlines | ||
.stream() | ||
.collect(Collectors.toMap(fsa -> fsa, fsa -> fsa.getInstructorDeadlines().size())); | ||
assertEquals(2, oldSessionsWithInstructor1Deadlines.size()); | ||
|
||
fsLogic.deleteFeedbackSessionsDeadlinesForInstructor(courseId, emailAddress); | ||
|
||
// The instructor should have no more selective deadlines. | ||
Set<FeedbackSessionAttributes> newSessionsWithInstructor1Deadlines = fsLogic | ||
.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.filter(feedbackSessionAttributes -> feedbackSessionAttributes.getInstructorDeadlines() | ||
.containsKey(emailAddress)) | ||
.collect(Collectors.toSet()); | ||
assertTrue(newSessionsWithInstructor1Deadlines.isEmpty()); | ||
Map<FeedbackSessionAttributes, Integer> expectedSessionsDeadlineCounts = oldSessionsDeadlineCounts.entrySet() | ||
.stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() - 1)); | ||
Map<FeedbackSessionAttributes, Integer> newSessionsDeadlineCounts = fsLogic | ||
.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.filter(oldSessionsWithInstructor1Deadlines::contains) | ||
.collect(Collectors.toMap(fsa -> fsa, fsa -> fsa.getInstructorDeadlines().size())); | ||
assertEquals(expectedSessionsDeadlineCounts, newSessionsDeadlineCounts); | ||
} | ||
|
||
@Test | ||
public void testDeleteFeedbackSessionsDeadlinesForStudent() { | ||
StudentAttributes student4InCourse1 = dataBundle.students.get("student4InCourse1"); | ||
verifyPresentInDatabase(student4InCourse1); | ||
|
||
String courseId = student4InCourse1.getCourse(); | ||
String emailAddress = student4InCourse1.getEmail(); | ||
|
||
______TS("Delete user; deadlines associated with the email are removed."); | ||
|
||
// The student should have selective deadlines. | ||
Set<FeedbackSessionAttributes> oldSessionsWithStudent4Deadlines = fsLogic | ||
.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.filter(feedbackSessionAttributes -> feedbackSessionAttributes.getStudentDeadlines() | ||
.containsKey(emailAddress)) | ||
.collect(Collectors.toSet()); | ||
Map<FeedbackSessionAttributes, Integer> oldSessionsDeadlineCounts = oldSessionsWithStudent4Deadlines | ||
.stream() | ||
.collect(Collectors.toMap(fsa -> fsa, fsa -> fsa.getStudentDeadlines().size())); | ||
assertEquals(2, oldSessionsWithStudent4Deadlines.size()); | ||
|
||
fsLogic.deleteFeedbackSessionsDeadlinesForStudent(courseId, emailAddress); | ||
|
||
// The student should have no more selective deadlines. | ||
Set<FeedbackSessionAttributes> newSessionsWithStudent4Deadlines = fsLogic | ||
.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.filter(feedbackSessionAttributes -> feedbackSessionAttributes.getStudentDeadlines() | ||
.containsKey(emailAddress)) | ||
.collect(Collectors.toSet()); | ||
assertTrue(newSessionsWithStudent4Deadlines.isEmpty()); | ||
Map<FeedbackSessionAttributes, Integer> expectedSessionsDeadlineCounts = oldSessionsDeadlineCounts.entrySet() | ||
.stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() - 1)); | ||
Map<FeedbackSessionAttributes, Integer> newSessionsDeadlineCounts = fsLogic | ||
.getFeedbackSessionsForCourse(courseId) | ||
.stream() | ||
.filter(oldSessionsWithStudent4Deadlines::contains) | ||
.collect(Collectors.toMap(fsa -> fsa, fsa -> fsa.getStudentDeadlines().size())); | ||
assertEquals(expectedSessionsDeadlineCounts, newSessionsDeadlineCounts); | ||
} | ||
|
||
private void testPublishUnpublishFeedbackSession() throws Exception { | ||
|
||
______TS("success: publish"); | ||
|
Oops, something went wrong.