Search in sources :

Example 46 with ShowPageResult

use of teammates.ui.controller.ShowPageResult in project teammates by TEAMMATES.

the class AdminActivityLogPageActionTest method statusMessageAndContinueSearch_withManyLogs_searchCorrectly.

// The two test groups should have different 'priority' so that they can run separately
// as they depend on different sets of log messages
@Test(groups = "manyActivityLogs", priority = 2)
public void statusMessageAndContinueSearch_withManyLogs_searchCorrectly() {
    Instant now = Instant.now();
    // default search will stop at #logs around 50
    AdminActivityLogPageAction action = getAction();
    ShowPageResult result = getShowPageResult(action);
    Instant earliestDateInUtc = now.minusMillis(54 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000);
    verifyManyLogs(55, 0, 54, result.data, result.getStatusMessage(), earliestDateInUtc);
    // continue search will get next #logs around 50
    long nextSearch = now.toEpochMilli() - 56 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000;
    action = getAction("searchTimeOffset", String.valueOf(nextSearch));
    result = getShowPageResult(action);
    earliestDateInUtc = now.minusMillis(110 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000);
    verifyManyLogs(56, 55, 110, result.data, result.getStatusMessage(), earliestDateInUtc);
    // continue search will get logs until no logs
    nextSearch = now.toEpochMilli() - 112 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000;
    action = getAction("searchTimeOffset", String.valueOf(nextSearch));
    result = getShowPageResult(action);
    earliestDateInUtc = Instant.ofEpochMilli(nextSearch - 24 * 60 * 60 * 1000);
    verifyManyLogs(39, 111, 149, result.data, result.getStatusMessage(), earliestDateInUtc);
    // default search with filter stop at #logs around 50
    action = getAction("filterQuery", "request:testdata1");
    result = getShowPageResult(action);
    earliestDateInUtc = now.minusMillis(54 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000);
    verifyManyLogs(55, 0, 54, result.data, result.getStatusMessage(), earliestDateInUtc);
    // continue search with filter will get logs until no logs
    nextSearch = now.toEpochMilli() - 56 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000;
    action = getAction("filterQuery", "request:testdata1", "searchTimeOffset", String.valueOf(nextSearch));
    result = getShowPageResult(action);
    earliestDateInUtc = Instant.ofEpochMilli(nextSearch - 24 * 60 * 60 * 1000);
    verifyManyLogs(95, 55, 60, result.data, result.getStatusMessage(), earliestDateInUtc);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AdminActivityLogPageAction(teammates.ui.controller.AdminActivityLogPageAction) Instant(java.time.Instant) Test(org.testng.annotations.Test)

Example 47 with ShowPageResult

use of teammates.ui.controller.ShowPageResult in project teammates by TEAMMATES.

the class AdminEmailComposePageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    final String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    ______TS("compose new email : typical values given : success");
    AdminEmailComposePageAction action = getAction();
    ShowPageResult pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
    String normalLogSegment = "adminEmailComposePage Page Load";
    AssertHelper.assertContains(normalLogSegment, action.getLogMessage());
    assertEquals("", pageResult.getStatusMessage());
    AdminEmailComposePageData data = (AdminEmailComposePageData) pageResult.data;
    assertNull(data.emailToEdit);
    ______TS("edit existing email : typical values given : success");
    // retrieve email id from logic
    AdminEmailAttributes emailData = dataBundle.adminEmails.get("adminEmail1");
    AdminEmailAttributes email = adminEmailsLogic.getAdminEmailBySubject(emailData.subject);
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_ID, email.emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, "admin.user"), pageResult.getDestinationWithParams());
    String expectedLogSegment = normalLogSegment + " : Edit Email [Admin Email 1 <b>bold tags</b>]";
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    assertEquals("", pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertNotNull(data.emailToEdit);
    ______TS("edit existing email : email does not exist : failure");
    String emailId = "nonexistingEmailId";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, "admin.user"), pageResult.getDestinationWithParams());
    expectedLogSegment = normalLogSegment + " : " + Const.StatusMessages.EMAIL_NOT_FOUND;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    assertEquals(Const.StatusMessages.EMAIL_NOT_FOUND, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertNull(data.emailToEdit);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AdminEmailComposePageAction(teammates.ui.controller.AdminEmailComposePageAction) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

Example 48 with ShowPageResult

use of teammates.ui.controller.ShowPageResult in project teammates by TEAMMATES.

the class AdminEmailComposeSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    final String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    ______TS("save new email : typical values given : success");
    String subject = "New Email Subject";
    String content = "<p>Email Content</p>";
    String receiver = "test@example.tmt";
    AdminEmailComposeSaveAction action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver);
    ShowPageResult pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
    String expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>Subject: New Email Subject";
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
    AdminEmailComposePageData data = (AdminEmailComposePageData) pageResult.data;
    assertNull(data.emailToEdit);
    AdminEmailAttributes savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
    assertNotNull("Email should be saved and should exists.", savedEmail);
    assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
    assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
    ______TS("save new email : invalid subject : failure");
    content = "<p>Email Content</p>";
    subject = "!Not starting with alphanumeric";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.ACTION_RESULT_FAILURE;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    String expectedStatus = "\"!Not starting with alphanumeric\" is not acceptable to TEAMMATES as a/an email subject";
    AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertEquals(subject, data.emailToEdit.subject);
    ______TS("save new email : invalid content : failure");
    content = "";
    subject = "valid subject";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.ACTION_RESULT_FAILURE;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    expectedStatus = "email content should not be empty.";
    AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertEquals(subject, data.emailToEdit.subject);
    ______TS("save existing email : typical values given : success");
    AdminEmailAttributes emailData = dataBundle.adminEmails.get("adminEmail1");
    AdminEmailAttributes email = adminEmailsLogic.getAdminEmailBySubject(emailData.getSubject());
    String emailId = email.emailId;
    content = "valid content";
    subject = "valid existing email subject";
    receiver = "test@example.tmt, test2@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: valid existing email subject";
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertNull(data.emailToEdit);
    savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
    assertNotNull("Email should be saved and should exists.", savedEmail);
    assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
    assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
    ______TS("save existing email : values require sanitization : success");
    emailId = email.emailId;
    content = "<p onclick=\"alert('hello');\">contents</p> </div> unclosed tags <script>alert(\"hello\");</script>";
    subject = "valid existing email subject <b>To check sanitization</b>";
    receiver = "test@example.tmt, test2@example.tmt, test3@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: valid existing email subject &lt;b&gt;To check sanitization&lt;&#x2f;b&gt;";
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertNull(data.emailToEdit);
    savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
    assertNotNull("Email should be saved and should exists.", savedEmail);
    assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
    assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
    ______TS("save existing email : invalid subject : failure");
    content = "valid content";
    subject = " ";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.ACTION_RESULT_FAILURE;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    expectedStatus = "The provided email subject is not acceptable to TEAMMATES as it contains only whitespace" + " or contains extra spaces at the beginning or at the end of the text.";
    AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertEquals(subject, data.emailToEdit.subject);
    assertEquals(email.emailId, data.emailToEdit.emailId);
    ______TS("save existing email : invalid content : failure");
    content = "";
    subject = "valid subject";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.ACTION_RESULT_FAILURE;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    expectedStatus = "email content should not be empty.";
    AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertEquals(subject, data.emailToEdit.subject);
    assertEquals(email.emailId, data.emailToEdit.emailId);
    ______TS("save non-existing email : typical values given : success");
    emailId = "nonExisitingId";
    content = "valid content";
    subject = "valid non-existing email subject <b>To check sanitization</b>";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: valid non-existing email subject &lt;b&gt;To check sanitization&lt;&#x2f;b&gt;";
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertNull(data.emailToEdit);
    savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
    assertNotNull("Email should be saved and should exists.", savedEmail);
    assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
    assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
    ______TS("save non-existing email : invalid subject : failure");
    emailId = "nonExisitingId";
    content = "valid content";
    subject = "";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, "admin.user"), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.ACTION_RESULT_FAILURE;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    expectedStatus = "The field 'email subject' is empty.";
    AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertEquals(subject, data.emailToEdit.subject);
    ______TS("save non-existing email : invalid content : failure");
    emailId = "nonExisitingId";
    content = "";
    subject = "valid subject";
    receiver = "test@example.tmt";
    action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
    pageResult = getShowPageResult(action);
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, "admin.user"), pageResult.getDestinationWithParams());
    expectedLogSegment = Const.ACTION_RESULT_FAILURE;
    AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
    expectedStatus = "email content should not be empty.";
    AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
    data = (AdminEmailComposePageData) pageResult.data;
    assertEquals(subject, data.emailToEdit.subject);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AdminEmailComposeSaveAction(teammates.ui.controller.AdminEmailComposeSaveAction) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) Test(org.testng.annotations.Test)

Example 49 with ShowPageResult

use of teammates.ui.controller.ShowPageResult in project teammates by TEAMMATES.

the class AdminEmailLogPageActionTest method verifyContinueSearch.

private void verifyContinueSearch(String[] params, int[][] expected, int totalLogs) {
    AdminEmailLogPageAction action = getAction(params);
    ShowPageResult result = getShowPageResult(action);
    AdminEmailLogPageData pageData = (AdminEmailLogPageData) result.data;
    verifyStatusMessage(result.getStatusMessage(), totalLogs);
    verifyLogs(expected, getLogsFromLogTemplateRows(pageData.getLogs()));
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AdminEmailLogPageData(teammates.ui.pagedata.AdminEmailLogPageData) AdminEmailLogPageAction(teammates.ui.controller.AdminEmailLogPageAction)

Example 50 with ShowPageResult

use of teammates.ui.controller.ShowPageResult in project teammates by TEAMMATES.

the class AdminEmailLogPageActionTest method statusMessageAndContinueSearch_withManyLogs_searchCorrectly.

// The two test groups should have different 'priority' so that they can run separately
// as they depend on different sets of log messages
@Test(groups = "manyEmailLogs", priority = 2)
public void statusMessageAndContinueSearch_withManyLogs_searchCorrectly() {
    Date today = TimeHelper.getDateOffsetToCurrentTime(0);
    // default search will stop at #logs around 50
    AdminEmailLogPageAction action = getAction();
    ShowPageResult result = getShowPageResult(action);
    verifyManyLogs(55, 0, 54, result.data, result.getStatusMessage());
    // continue search will get next #logs around 50
    long nextSearch = today.getTime() - 56 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000;
    action = getAction("offset", String.valueOf(nextSearch));
    result = getShowPageResult(action);
    verifyManyLogs(56, 55, 110, result.data, result.getStatusMessage());
    // continue search will get logs until no logs
    nextSearch = today.getTime() - 112 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000;
    action = getAction("offset", String.valueOf(nextSearch));
    result = getShowPageResult(action);
    verifyManyLogs(39, 111, 149, result.data, result.getStatusMessage());
    // default search with filter stop at #logs around 50
    action = getAction("filterQuery", "receiver:email1@email.com");
    result = getShowPageResult(action);
    verifyManyLogs(55, 0, 54, result.data, result.getStatusMessage());
    // continue search with filter will get logs until no logs
    nextSearch = today.getTime() - 56 * LOG_MESSAGE_INTERVAL_MANY_LOGS * 1000;
    action = getAction("filterQuery", "receiver:email1@email.com", "offset", String.valueOf(nextSearch));
    result = getShowPageResult(action);
    verifyManyLogs(95, 55, 69, result.data, result.getStatusMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AdminEmailLogPageAction(teammates.ui.controller.AdminEmailLogPageAction) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

ShowPageResult (teammates.ui.controller.ShowPageResult)51 Test (org.testng.annotations.Test)42 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)31 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 RedirectResult (teammates.ui.controller.RedirectResult)10 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)8 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)8 EntityNotFoundException (teammates.common.exception.EntityNotFoundException)5 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)4 NullPostParameterException (teammates.common.exception.NullPostParameterException)4 ArrayList (java.util.ArrayList)3 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)3 AdminActivityLogPageAction (teammates.ui.controller.AdminActivityLogPageAction)3 AdminEmailLogPageAction (teammates.ui.controller.AdminEmailLogPageAction)3 AjaxResult (teammates.ui.controller.AjaxResult)3 InstructorCourseEnrollPageAction (teammates.ui.controller.InstructorCourseEnrollPageAction)3 InstructorCourseEnrollPageData (teammates.ui.pagedata.InstructorCourseEnrollPageData)3 Instant (java.time.Instant)2 AdminEmailAttributes (teammates.common.datatransfer.attributes.AdminEmailAttributes)2 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)2