Search in sources :

Example 1 with Logic

use of teammates.logic.api.Logic 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));
}
Also used : AjaxResult(teammates.ui.controller.AjaxResult) AdminHomePageData(teammates.ui.pagedata.AdminHomePageData) AdminInstructorAccountAddAction(teammates.ui.controller.AdminInstructorAccountAddAction) Logic(teammates.logic.api.Logic) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 2 with Logic

use of teammates.logic.api.Logic in project teammates by TEAMMATES.

the class GenerateFeedbackReport method doOperation.

@Override
protected void doOperation() {
    Logic logic = new Logic();
    try {
        String fileContent = logic.getFeedbackSessionResultSummaryAsCsv("CourseID", "Session Name", "instructor@email.com", true, true, null);
        writeToFile("result.csv", fileContent);
    } catch (EntityDoesNotExistException | ExceedingRangeException e) {
        e.printStackTrace();
    }
}
Also used : ExceedingRangeException(teammates.common.exception.ExceedingRangeException) Logic(teammates.logic.api.Logic) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with Logic

use of teammates.logic.api.Logic in project teammates by TEAMMATES.

the class GateKeeperTest method testGetCurrentUser.

// TODO: test isUserLoggedIn method
@Test
public void testGetCurrentUser() throws Exception {
    ______TS("admin+instructor+student");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    CourseAttributes course = dataBundle.courses.get("typicalCourse2");
    gaeSimulation.loginAsAdmin(instructor.googleId);
    // also make this user a student of another course
    StudentAttributes instructorAsStudent = StudentAttributes.builder(course.getId(), "Instructor As Student", "instructorasstudent@yahoo.com").withSection("Section 1").withTeam("Team 1").withComments("").build();
    instructorAsStudent.googleId = instructor.googleId;
    new Logic().createStudentWithoutDocument(instructorAsStudent);
    UserType user = gateKeeper.getCurrentUser();
    assertEquals(instructor.googleId, user.id);
    assertTrue(user.isAdmin);
    assertTrue(user.isInstructor);
    assertTrue(user.isStudent);
    ______TS("unregistered");
    gaeSimulation.loginUser("unknown");
    user = gateKeeper.getCurrentUser();
    assertEquals("unknown", user.id);
    assertFalse(user.isAdmin);
    assertFalse(user.isInstructor);
    assertFalse(user.isStudent);
    ______TS("not logged in");
    // check for user not logged in
    gaeSimulation.logoutUser();
    assertNull(gateKeeper.getCurrentUser());
}
Also used : Logic(teammates.logic.api.Logic) UserType(teammates.common.datatransfer.UserType) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 4 with Logic

use of teammates.logic.api.Logic in project teammates by TEAMMATES.

the class StudentFeedbackResultsPageDataTest method testAll.

@Test
public void testAll() throws EntityDoesNotExistException {
    ______TS("typical success case");
    AccountAttributes account = dataBundle.accounts.get("student1InCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    assertNotNull(student);
    String dummyKey = "key123";
    student.key = dummyKey;
    Logic logic = new Logic();
    StudentFeedbackResultsPageData pageData = new StudentFeedbackResultsPageData(account, student, dummySessionToken);
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponses = new LinkedHashMap<>();
    FeedbackQuestionAttributes question1 = dataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
    assertNotNull(question1);
    FeedbackQuestionAttributes question2 = dataBundle.feedbackQuestions.get("qn2InSession1InCourse1");
    assertNotNull(question2);
    List<FeedbackResponseAttributes> responsesForQ1 = new ArrayList<>();
    List<FeedbackResponseAttributes> responsesForQ2 = new ArrayList<>();
    /* Question 1 with responses */
    responsesForQ1.add(dataBundle.feedbackResponses.get("response1ForQ1S1C1"));
    questionsWithResponses.put(question1, responsesForQ1);
    /* Question 2 with responses */
    responsesForQ2.add(dataBundle.feedbackResponses.get("response1ForQ2S1C1"));
    responsesForQ2.add(dataBundle.feedbackResponses.get("response2ForQ2S1C1"));
    questionsWithResponses.put(question2, responsesForQ2);
    // need to obtain questionId and responseId as methods in FeedbackSessionResultsBundle require them
    questionsWithResponses = getActualQuestionsAndResponsesWithId(logic, questionsWithResponses);
    pageData.setBundle(logic.getFeedbackSessionResultsForStudent(question1.feedbackSessionName, question1.courseId, student.email));
    pageData.init(questionsWithResponses);
    StudentFeedbackResultsQuestionWithResponses questionBundle1 = pageData.getFeedbackResultsQuestionsWithResponses().get(0);
    StudentFeedbackResultsQuestionWithResponses questionBundle2 = pageData.getFeedbackResultsQuestionsWithResponses().get(1);
    assertNotNull(pageData.getFeedbackResultsQuestionsWithResponses());
    assertEquals(2, pageData.getFeedbackResultsQuestionsWithResponses().size());
    assertEquals("You are viewing feedback results as <span class='text-danger text-bold text-large'>" + "student1 In Course1</td></div>'\"</span>. You may submit feedback for sessions that are " + "currently open and view results without logging in. " + "To access other features you need <a href='/page/studentCourseJoinAuthentication?" + "key=" + StringHelper.encrypt(dummyKey) + "&studentemail=student1InCourse1%40gmail.tmt&courseid=idOfTypicalCourse1' class='link'>" + "to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
    assertNotNull(questionBundle1.getQuestionDetails());
    assertNotNull(questionBundle2.getQuestionDetails());
    assertEquals("1", questionBundle1.getQuestionDetails().getQuestionIndex());
    assertEquals("2", questionBundle2.getQuestionDetails().getQuestionIndex());
    assertEquals("", questionBundle1.getQuestionDetails().getAdditionalInfo());
    assertEquals("", questionBundle2.getQuestionDetails().getAdditionalInfo());
    assertNotNull(questionBundle1.getResponseTables());
    assertNotNull(questionBundle2.getResponseTables());
    assertEquals("You", questionBundle1.getResponseTables().get(0).getRecipientName());
    assertNotNull(questionBundle1.getResponseTables().get(0).getResponses());
    assertEquals("You", questionBundle1.getResponseTables().get(0).getResponses().get(0).getGiverName());
    assertEquals("Student 1 self feedback.", questionBundle1.getResponseTables().get(0).getResponses().get(0).getAnswer());
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    pageData = new StudentFeedbackResultsPageData(account, student, dummySessionToken);
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponsesUnregistered = new LinkedHashMap<>();
    pageData.init(questionsWithResponsesUnregistered);
    assertTrue(pageData.getFeedbackResultsQuestionsWithResponses().isEmpty());
    assertEquals("regKeyForStuNotYetJoinCourse", student.key);
    assertEquals("idOfUnregisteredCourse", student.course);
    assertEquals("student1InUnregisteredCourse@gmail.tmt", student.email);
    assertEquals("You are viewing feedback results as " + "<span class='text-danger text-bold text-large'>student1 In " + "unregisteredCourse</span>. You may submit feedback for sessions that are currently open " + "and view results without logging in. To access other features you need " + "<a href='/page/studentCourseJoinAuthentication?key=" + StringHelper.encrypt("regKeyForStuNotYetJoinCourse") + "&studentemail=student1InUnregisteredCourse%40gmail.tmt&courseid=idOfUnregisteredCourse' " + "class='link'>to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) LinkedHashMap(java.util.LinkedHashMap) StudentFeedbackResultsQuestionWithResponses(teammates.ui.template.StudentFeedbackResultsQuestionWithResponses) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) Logic(teammates.logic.api.Logic) Test(org.testng.annotations.Test)

Example 5 with Logic

use of teammates.logic.api.Logic in project teammates by TEAMMATES.

the class InstructorHomePageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    String[] submissionParams = new String[] { Const.ParamsNames.CHECK_PERSISTENCE_COURSE, "something" };
    ______TS("persistence issue");
    gaeSimulation.loginUser("unreg_user");
    InstructorHomePageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertFalse(a.account.isInstructor);
    assertEquals(Const.StatusMessages.INSTRUCTOR_PERSISTENCE_ISSUE, r.getStatusMessage());
    ______TS("instructor with no courses, right after registration (ie no persistence issue)");
    gaeSimulation.loginAsInstructor(typicalBundle.accounts.get("instructorWithoutCourses").googleId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    AssertHelper.assertContainsRegex(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, "instructorWithoutCourses"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.HINT_FOR_NEW_INSTRUCTOR, r.getStatusMessage());
    InstructorHomePageData data = (InstructorHomePageData) r.data;
    assertEquals(0, data.getCourseTables().size());
    String expectedLogMessage = "TEAMMATESLOG|||instructorHomePage|||instructorHomePage" + "|||true|||Instructor|||Instructor Without Courses" + "|||instructorWithoutCourses|||iwc@yahoo.tmt" + "|||instructorHome Page Load<br>Total Courses: 0" + "|||/page/instructorHomePage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    submissionParams = new String[] {};
    ______TS("instructor with multiple courses, sort by course id, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, Const.SORT_BY_COURSE_ID };
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    // access page in masquerade mode
    String instructorWithMultipleCourses = typicalBundle.accounts.get("instructor3").googleId;
    // create another course for sorting
    Logic logic = new Logic();
    // should be 1st if sort by course id
    String newCourseIdForSorting = "idOfTypicalCourse";
    // should be 3rd if sort by course name
    String newCourseNameForSorting = "Typical Course 3";
    logic.createCourseAndInstructor(instructorWithMultipleCourses, newCourseIdForSorting, newCourseNameForSorting, "UTC");
    a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, instructorWithMultipleCourses), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (InstructorHomePageData) r.data;
    assertEquals(3, data.getCourseTables().size());
    String expectedCourse1IdAfterSortByCourseId = "idOfTypicalCourse";
    String expectedCourse2IdAfterSortByCourseId = "idOfTypicalCourse1";
    String expectedCourse3IdAfterSortByCourseId = "idOfTypicalCourse2";
    String actualCourse1AfterSortByCourseId = data.getCourseTables().get(0).getCourseId();
    String actualCourse2AfterSortByCourseId = data.getCourseTables().get(1).getCourseId();
    String actualCourse3AfterSortByCourseId = data.getCourseTables().get(2).getCourseId();
    assertEquals(expectedCourse1IdAfterSortByCourseId, actualCourse1AfterSortByCourseId);
    assertEquals(expectedCourse2IdAfterSortByCourseId, actualCourse2AfterSortByCourseId);
    assertEquals(expectedCourse3IdAfterSortByCourseId, actualCourse3AfterSortByCourseId);
    assertEquals(Const.SORT_BY_COURSE_ID, data.getSortCriteria());
    expectedLogMessage = "TEAMMATESLOG|||instructorHomePage|||instructorHomePage|||true" + "|||Instructor(M)|||Instructor 3 of Course 1 and 2" + "|||idOfInstructor3|||instr3@course1n2.tmt" + "|||instructorHome Page Load<br>Total Courses: 3" + "|||/page/instructorHomePage";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, a.getLogMessage(), adminUserId);
    ______TS("instructor with multiple courses, sort by course name, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, Const.SORT_BY_COURSE_NAME };
    a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, instructorWithMultipleCourses), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (InstructorHomePageData) r.data;
    assertEquals(3, data.getCourseTables().size());
    String expectedCourse1IdAfterSortByCourseName = "idOfTypicalCourse1";
    String expectedCourse2IdAfterSortByCourseName = "idOfTypicalCourse2";
    String expectedCourse3IdAfterSortByCourseName = "idOfTypicalCourse";
    String actualCourse1AfterSortByCourseName = data.getCourseTables().get(0).getCourseId();
    String actualCourse2AfterSortByCourseName = data.getCourseTables().get(1).getCourseId();
    String actualCourse3AfterSortByCourseName = data.getCourseTables().get(2).getCourseId();
    assertEquals(expectedCourse1IdAfterSortByCourseName, actualCourse1AfterSortByCourseName);
    assertEquals(expectedCourse2IdAfterSortByCourseName, actualCourse2AfterSortByCourseName);
    assertEquals(expectedCourse3IdAfterSortByCourseName, actualCourse3AfterSortByCourseName);
    assertEquals(Const.SORT_BY_COURSE_NAME, data.getSortCriteria());
    ______TS("instructor with multiple courses, sort by course name, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, "haha" };
    try {
        a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
        r = getShowPageResult(a);
        signalFailureToDetectException("The Assertion error is not thrown as expected");
    } catch (AssertionError e) {
        assertNotNull(e);
    }
    ______TS("instructor with multiple courses, sort by creation date, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, Const.SORT_BY_COURSE_CREATION_DATE };
    a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, instructorWithMultipleCourses), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (InstructorHomePageData) r.data;
    assertEquals(3, data.getCourseTables().size());
    String expectedCourse1IdAfterSortByCourseCreationDate = "idOfTypicalCourse";
    String expectedCourse2IdAfterSortByCourseCreationDate = "idOfTypicalCourse2";
    String expectedCourse3IdAfterSortByCourseCreationDate = "idOfTypicalCourse1";
    String actualCourse1AfterSortByCourseCreationDate = data.getCourseTables().get(0).getCourseId();
    String actualCourse2AfterSortByCourseCreationDate = data.getCourseTables().get(1).getCourseId();
    String actualCourse3AfterSortByCourseCreationDate = data.getCourseTables().get(2).getCourseId();
    assertEquals(expectedCourse1IdAfterSortByCourseCreationDate, actualCourse1AfterSortByCourseCreationDate);
    assertEquals(expectedCourse2IdAfterSortByCourseCreationDate, actualCourse2AfterSortByCourseCreationDate);
    assertEquals(expectedCourse3IdAfterSortByCourseCreationDate, actualCourse3AfterSortByCourseCreationDate);
    assertEquals(Const.SORT_BY_COURSE_CREATION_DATE, data.getSortCriteria());
    // delete the new course
    CoursesLogic.inst().deleteCourseCascade(newCourseIdForSorting);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorHomePageData(teammates.ui.pagedata.InstructorHomePageData) CoursesLogic(teammates.logic.core.CoursesLogic) Logic(teammates.logic.api.Logic) InstructorHomePageAction(teammates.ui.controller.InstructorHomePageAction) Test(org.testng.annotations.Test)

Aggregations

Logic (teammates.logic.api.Logic)7 Test (org.testng.annotations.Test)4 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)2 EmailSender (teammates.logic.api.EmailSender)2 TaskQueuer (teammates.logic.api.TaskQueuer)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 UserType (teammates.common.datatransfer.UserType)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 ExceedingRangeException (teammates.common.exception.ExceedingRangeException)1 EmailWrapper (teammates.common.util.EmailWrapper)1 GateKeeper (teammates.logic.api.GateKeeper)1 CoursesLogic (teammates.logic.core.CoursesLogic)1 AdminInstructorAccountAddAction (teammates.ui.controller.AdminInstructorAccountAddAction)1