use of teammates.ui.controller.AjaxResult in project teammates by TEAMMATES.
the class ErrorUserReportLogActionTest method testExecuteAndPostProcess.
@Override
@Test
protected void testExecuteAndPostProcess() throws Exception {
InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
gaeSimulation.loginAsInstructor(instructor1ofCourse1.googleId);
______TS("Typical Success Case");
final String testErrorReportSubject = "Test Error Subject";
final String testErrorReportContent = "This is a test user-submitted error report.";
final String testErrorReportRequestedUrl = "/page/testurl";
String[] params = new String[] { Const.ParamsNames.ERROR_FEEDBACK_URL_REQUESTED, testErrorReportRequestedUrl, Const.ParamsNames.ERROR_FEEDBACK_EMAIL_SUBJECT, testErrorReportSubject, Const.ParamsNames.ERROR_FEEDBACK_EMAIL_CONTENT, testErrorReportContent };
ErrorUserReportLogAction action = getAction(params);
AjaxResult result = getAjaxResult(action);
assertEquals(Const.StatusMessages.ERROR_FEEDBACK_SUBMIT_SUCCESS, result.getStatusMessage());
// getting basic AccountAttributes because ErrorUserReportLogAction only logs this.
AccountAttributes instructor1ofCourse1AccountAttributes = accountsLogic.getAccount(instructor1ofCourse1.googleId, false);
final String expectedLogMessage = "====== USER FEEDBACK ABOUT ERROR ====== \n" + "REQUESTED URL: " + testErrorReportRequestedUrl + "\n" + "ACCOUNT DETAILS: " + instructor1ofCourse1AccountAttributes.toString() + "\n" + "SUBJECT: " + testErrorReportSubject + "\n" + "FEEDBACK: " + testErrorReportContent;
assertEquals(expectedLogMessage, action.getUserErrorReportLogMessage());
}
use of teammates.ui.controller.AjaxResult in project teammates by TEAMMATES.
the class FeedbackSessionStatsPageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
String instructorId = instructor1OfCourse1.googleId;
String[] submissionParams;
gaeSimulation.loginAsInstructor(instructorId);
______TS("typical: instructor accesses feedback stats of his/her course");
FeedbackSessionAttributes accessableFeedbackSession = typicalBundle.feedbackSessions.get("session1InCourse1");
submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, accessableFeedbackSession.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
FeedbackSessionStatsPageAction a = getAction(addUserIdToParams(instructorId, submissionParams));
AjaxResult r = getAjaxResult(a);
FeedbackSessionStatsPageData data = (FeedbackSessionStatsPageData) r.data;
assertEquals(getPageResultDestination("", false, "idOfInstructor1OfCourse1"), r.getDestinationWithParams());
assertEquals(10, data.sessionDetails.stats.expectedTotal);
assertEquals(4, data.sessionDetails.stats.submittedTotal);
assertEquals("", r.getStatusMessage());
______TS("fail: instructor accesses stats of non-existent feedback session");
String nonexistentFeedbackSession = "nonexistentFeedbackSession";
submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, nonexistentFeedbackSession, Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
boolean hasThrownUnauthorizedAccessException = false;
String exceptionMessage = "";
a = getAction(addUserIdToParams(instructorId, submissionParams));
try {
r = getAjaxResult(a);
} catch (UnauthorizedAccessException e) {
hasThrownUnauthorizedAccessException = true;
exceptionMessage = e.getMessage();
}
assertTrue(hasThrownUnauthorizedAccessException);
assertEquals("Trying to access system using a non-existent feedback session entity", exceptionMessage);
assertEquals("", r.getStatusMessage());
}
use of teammates.ui.controller.AjaxResult in project teammates by TEAMMATES.
the class InstructorCourseDetailsPageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
gaeSimulation.loginAsInstructor(instructor1OfCourse1.googleId);
______TS("Not enough parameters");
verifyAssumptionFailure();
______TS("Typical Case, Course with at least one student");
String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
InstructorCourseDetailsPageAction pageAction = getAction(submissionParams);
ShowPageResult pageResult = getShowPageResult(pageAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_DETAILS, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
InstructorCourseDetailsPageData pageData = (InstructorCourseDetailsPageData) pageResult.data;
assertEquals(5, pageData.getInstructors().size());
assertEquals("idOfTypicalCourse1", pageData.getCourseDetails().course.getId());
assertEquals("Typical Course 1 with 2 Evals", pageData.getCourseDetails().course.getName());
assertEquals(2, pageData.getCourseDetails().stats.teamsTotal);
assertEquals(5, pageData.getCourseDetails().stats.studentsTotal);
assertEquals(0, pageData.getCourseDetails().stats.unregisteredTotal);
assertEquals(0, pageData.getCourseDetails().feedbackSessions.size());
String expectedLogMessage = "TEAMMATESLOG|||instructorCourseDetailsPage|||instructorCourseDetailsPage|||true" + "|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1" + "|||instr1@course1.tmt|||instructorCourseDetails Page Load<br>Viewing Course " + "Details for Course <span class=\"bold\">[idOfTypicalCourse1]</span>" + "|||/page/instructorCourseDetailsPage";
AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
______TS("Masquerade mode, Course with no student");
String adminUserId = "admin.user";
gaeSimulation.loginAsAdmin(adminUserId);
InstructorAttributes instructor4 = typicalBundle.instructors.get("instructor4");
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor4.courseId };
pageAction = getAction(addUserIdToParams(instructor4.googleId, submissionParams));
pageResult = getShowPageResult(pageAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_DETAILS, false, "idOfInstructor4"), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals(String.format(Const.StatusMessages.INSTRUCTOR_COURSE_EMPTY, pageResult.data.getInstructorCourseEnrollLink(instructor4.courseId)), pageResult.getStatusMessage());
pageData = (InstructorCourseDetailsPageData) pageResult.data;
assertEquals(1, pageData.getInstructors().size());
assertEquals("idOfCourseNoEvals", pageData.getCourseDetails().course.getId());
assertEquals("Typical Course 3 with 0 Evals", pageData.getCourseDetails().course.getName());
assertEquals(0, pageData.getCourseDetails().stats.teamsTotal);
assertEquals(0, pageData.getCourseDetails().stats.studentsTotal);
assertEquals(0, pageData.getCourseDetails().stats.unregisteredTotal);
assertEquals(0, pageData.getCourseDetails().feedbackSessions.size());
expectedLogMessage = "TEAMMATESLOG|||instructorCourseDetailsPage|||instructorCourseDetailsPage|||true|||" + "Instructor(M)|||Instructor 4 of CourseNoEvals|||idOfInstructor4|||" + "instr4@coursenoevals.tmt|||instructorCourseDetails Page Load<br>Viewing Course " + "Details for Course <span class=\"bold\">[idOfCourseNoEvals]</span>|||" + "/page/instructorCourseDetailsPage";
AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, pageAction.getLogMessage(), adminUserId);
______TS("HTML Table needed");
instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
gaeSimulation.loginAsInstructor(instructor1OfCourse1.googleId);
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.CSV_TO_HTML_TABLE_NEEDED, "true" };
pageAction = getAction(submissionParams);
AjaxResult ajaxResult = this.getAjaxResult(pageAction);
assertEquals(getPageResultDestination("", false, "idOfInstructor1OfCourse1"), ajaxResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", ajaxResult.getStatusMessage());
pageData = (InstructorCourseDetailsPageData) ajaxResult.data;
assertEquals("<table class=\"table table-bordered table-striped table-condensed\">" + "<tr>" + "<td>Course ID</td>" + "<td>idOfTypicalCourse1</td>" + "</tr>" + "<tr>" + "<td>Course Name</td>" + "<td>Typical Course 1 with 2 Evals</td>" + "</tr>" + "<tr>" + "<td>Section</td>" + "<td>Team</td>" + "<td>Full Name</td>" + "<td>Last Name</td>" + "<td>Status</td>" + "<td>Email</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1</td></div>'"</td>" + "<td>student1 In Course1</td></div>'"</td>" + "<td>Course1</td></div>'"</td>" + "<td>Joined</td>" + "<td>student1InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1</td></div>'"</td>" + "<td>student2 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student2InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1</td></div>'"</td>" + "<td>student3 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student3InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1</td></div>'"</td>" + "<td>student4 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student4InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 2</td>" + "<td>Team 1.2</td>" + "<td>student5 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student5InCourse1@gmail.tmt</td>" + "</tr>" + "</table>", pageData.getStudentListHtmlTableAsString());
}
use of teammates.ui.controller.AjaxResult in project teammates by TEAMMATES.
the class AdminInstructorAccountAddActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
final String name = "JamesBond";
final String email = "jamesbond89@gmail.tmt";
final String institute = "TEAMMATES Test Institute 1";
final String adminUserId = "admin.user";
______TS("Not enough parameters");
gaeSimulation.loginAsAdmin(adminUserId);
verifyAssumptionFailure();
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_NAME, name);
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_NAME, name, Const.ParamsNames.INSTRUCTOR_EMAIL, email);
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_NAME, name, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_EMAIL, email, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
______TS("Normal case: not importing demo couse, extra spaces around values");
final String nameWithSpaces = " " + name + " ";
final String emailWithSpaces = " " + email + " ";
final String instituteWithSpaces = " " + institute + " ";
AdminInstructorAccountAddAction a = getAction(Const.ParamsNames.INSTRUCTOR_NAME, nameWithSpaces, Const.ParamsNames.INSTRUCTOR_EMAIL, emailWithSpaces, Const.ParamsNames.INSTRUCTOR_INSTITUTION, instituteWithSpaces);
AjaxResult r = getAjaxResult(a);
assertTrue(r.getStatusMessage().contains("Instructor " + name + " has been successfully created"));
verifyNumberOfEmailsSent(a, 1);
EmailWrapper emailSent = a.getEmailSender().getEmailsSent().get(0);
assertEquals(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), name), emailSent.getSubject());
assertEquals(email, emailSent.getRecipient());
______TS("Error: invalid parameter");
final String invalidName = "James%20Bond99";
a = getAction(Const.ParamsNames.INSTRUCTOR_NAME, invalidName, Const.ParamsNames.INSTRUCTOR_EMAIL, email, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
String expectedError = "\"" + invalidName + "\" is not acceptable to TEAMMATES as a/an person name because " + "it contains invalid characters. A/An person name must start with an " + "alphanumeric character, and cannot contain any vertical bar (|) or percent sign (%).";
AjaxResult rInvalidParam = getAjaxResult(a);
assertEquals(expectedError, rInvalidParam.getStatusMessage());
AdminHomePageData pageData = (AdminHomePageData) rInvalidParam.data;
assertEquals(email, pageData.instructorEmail);
assertEquals(institute, pageData.instructorInstitution);
assertEquals(invalidName, pageData.instructorName);
verifyNoEmailsSent(a);
______TS("Normal case: importing demo couse");
a = getAction(Const.ParamsNames.INSTRUCTOR_NAME, name, Const.ParamsNames.INSTRUCTOR_EMAIL, email, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
r = getAjaxResult(a);
assertTrue(r.getStatusMessage().contains("Instructor " + name + " has been successfully created"));
verifyNumberOfEmailsSent(a, 1);
emailSent = a.getEmailSender().getEmailsSent().get(0);
assertEquals(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), name), emailSent.getSubject());
assertEquals(email, emailSent.getRecipient());
new Logic().deleteCourse(getDemoCourseIdRoot(email));
}
use of teammates.ui.controller.AjaxResult in project teammates by TEAMMATES.
the class StudentProfileCreateFormUrlActionTest method testGenerateUploadUrlSuccessMasqueradeMode.
private void testGenerateUploadUrlSuccessMasqueradeMode(AccountAttributes student) {
______TS("Typical case: masquerade mode");
gaeSimulation.loginAsAdmin("admin.user");
String[] submissionParams = new String[] { Const.ParamsNames.USER_ID, student.googleId };
StudentProfileCreateFormUrlAction action = getAction(addUserIdToParams(student.googleId, submissionParams));
AjaxResult result = getAjaxResult(action);
assertFalse(result.isError);
assertEquals("", result.getStatusMessage());
verifyLogMessage(student, action, result, true);
}
Aggregations