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);
}
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);
}
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 <b>To check sanitization</b>";
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 <b>To check sanitization</b>";
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);
}
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()));
}
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());
}
Aggregations