use of teammates.ui.controller.AdminInstructorAccountAddAction 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));
}
Aggregations