use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailGeneratorTest method testGenerateFeedbackSessionEmails_testSanitization.
@Test
public void testGenerateFeedbackSessionEmails_testSanitization() throws IOException {
FeedbackSessionAttributes session = fsLogic.getFeedbackSession("Normal feedback session name", "idOfTestingSanitizationCourse");
CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
StudentAttributes student1 = studentsLogic.getStudentForEmail(course.getId(), "normal@sanitization.tmt");
InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail(course.getId(), "instructor1@sanitization.tmt");
______TS("feedback session opening emails: sanitization required");
List<EmailWrapper> emails = new EmailGenerator().generateFeedbackSessionOpeningEmails(session);
assertEquals(2, emails.size());
String subject = String.format(EmailType.FEEDBACK_OPENING.getSubject(), course.getName(), session.getFeedbackSessionName());
verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionOpeningEmailTestingSanitzationForStudent.html");
verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionOpeningEmailTestingSanitizationForInstructor.html");
______TS("feedback session closed alerts: sanitization required");
emails = new EmailGenerator().generateFeedbackSessionClosedEmails(session);
assertEquals(2, emails.size());
subject = String.format(EmailType.FEEDBACK_CLOSED.getSubject(), course.getName(), session.getFeedbackSessionName());
verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionClosedEmailTestingSanitizationForStudent.html");
verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionClosedEmailTestingSanitizationForInstructor.html");
______TS("feedback sessions summary of course email: sanitization required");
EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(session.getCourseId(), student1);
subject = String.format(EmailType.STUDENT_EMAIL_CHANGED.getSubject(), course.getName(), course.getId());
verifyEmail(email, student1.email, subject, "/summaryOfFeedbackSessionsOfCourseEmailTestingSanitizationForStudent.html");
______TS("feedback session submission email: sanitization required");
Instant time = TimeHelper.parseInstant("2016-09-04 05:30 AM +0000");
email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor1, time);
subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
verifyEmail(email, instructor1.email, subject, "/sessionSubmissionConfirmationEmailTestingSanitization.html");
}
use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailGeneratorTest method testGenerateInstructorJoinEmail_testSanitization.
@Test
public void testGenerateInstructorJoinEmail_testSanitization() throws IOException {
______TS("instructor new account email: sanitization required");
InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail("idOfTestingSanitizationCourse", "instructor1@sanitization.tmt");
String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructor1.key)).withInstructorInstitution("Test Institute").toAbsoluteString();
EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructor1.email, instructor1.name, joinLink);
// InstructorAttributes sanitizes name before saving
String subject = String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), SanitizationHelper.sanitizeForHtml(instructor1.name));
verifyEmail(email, instructor1.email, subject, "/instructorNewAccountEmailTestingSanitization.html");
assertEquals(email.getBcc(), Config.SUPPORT_EMAIL);
______TS("instructor course join email: sanitization required");
AccountAttributes inviter = dataBundle.accounts.get("instructor1OfTestingSanitizationCourse");
CourseAttributes course = coursesLogic.getCourse("idOfTestingSanitizationCourse");
email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor1, course);
subject = String.format(EmailType.INSTRUCTOR_COURSE_JOIN.getSubject(), course.getName(), course.getId());
verifyEmail(email, instructor1.email, subject, "/instructorCourseJoinEmailTestingSanitization.html");
}
use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailGeneratorTest method testGenerateAdminEmail.
@Test
public void testGenerateAdminEmail() {
String recipient = "recipient@email.com";
String content = "Generic content";
String subject = "Generic subject";
EmailWrapper email = new EmailGenerator().generateAdminEmail(content, subject, recipient);
// Do not use verify email since the content is not based on any template
assertEquals(recipient, email.getRecipient());
assertEquals(subject, email.getSubject());
assertEquals(Config.EMAIL_SENDERNAME, email.getSenderName());
assertEquals(Config.EMAIL_SENDEREMAIL, email.getSenderEmail());
assertEquals(Config.EMAIL_REPLYTO, email.getReplyTo());
assertEquals(content, email.getContent());
}
use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailGeneratorTest method verifyEmailReceivedCorrectly.
private void verifyEmailReceivedCorrectly(List<EmailWrapper> actualEmails, String recipient, String subject, String emailContentFilePath, String containsString) throws IOException {
boolean hasReceivedEmailCorrectly = false;
for (EmailWrapper email : actualEmails) {
if (email.getRecipient().equals(recipient) && email.getContent().contains(containsString)) {
verifyEmail(email, recipient, subject, emailContentFilePath);
hasReceivedEmailCorrectly = true;
}
}
assertTrue(hasReceivedEmailCorrectly);
}
use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.
the class EmailGeneratorTest method testGenerateCompiledLogsEmail.
@Test
public void testGenerateCompiledLogsEmail() throws IOException {
AppLogLine typicalLogLine = new AppLogLine();
typicalLogLine.setLogLevel(LogLevel.ERROR);
typicalLogLine.setLogMessage("Typical log message");
AppLogLine logLineWithLineBreak = new AppLogLine();
logLineWithLineBreak.setLogLevel(LogLevel.ERROR);
logLineWithLineBreak.setLogMessage("Log line \n with line break <br> and also HTML br tag");
EmailWrapper email = new EmailGenerator().generateCompiledLogsEmail(Arrays.asList(typicalLogLine, logLineWithLineBreak));
String subject = String.format(EmailType.SEVERE_LOGS_COMPILATION.getSubject(), Config.getAppVersion());
verifyEmail(email, Config.SUPPORT_EMAIL, subject, "/severeLogsCompilationEmail.html");
}
Aggregations