Search in sources :

Example 16 with EmailWrapper

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");
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EmailGenerator(teammates.logic.api.EmailGenerator) Instant(java.time.Instant) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 17 with EmailWrapper

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");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 18 with EmailWrapper

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());
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 19 with EmailWrapper

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);
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 20 with EmailWrapper

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");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AppLogLine(com.google.appengine.api.log.AppLogLine) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Aggregations

EmailWrapper (teammates.common.util.EmailWrapper)55 EmailGenerator (teammates.logic.api.EmailGenerator)24 Test (org.testng.annotations.Test)20 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)15 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)13 TeammatesException (teammates.common.exception.TeammatesException)13 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)12 ArrayList (java.util.ArrayList)6 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)3 EmailSendingException (teammates.common.exception.EmailSendingException)3 NullPostParameterException (teammates.common.exception.NullPostParameterException)3 StatusMessage (teammates.common.util.StatusMessage)3 RedirectResult (teammates.ui.controller.RedirectResult)3 Instant (java.time.Instant)2 DataBundle (teammates.common.datatransfer.DataBundle)2 FeedbackNumericalScaleQuestionDetails (teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2