Search in sources :

Example 26 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class AccountsDbTest method testEditAccount.

@Test
public void testEditAccount() throws Exception {
    AccountAttributes a = createNewAccount();
    ______TS("typical edit success case (legacy data)");
    a.name = "Edited name";
    a.studentProfile = null;
    accountsDb.updateAccount(a);
    AccountAttributes actualAccount = accountsDb.getAccount(a.googleId, true);
    assertEquals(a.name, actualAccount.name);
    ______TS("typical success case (with profile)");
    a.studentProfile.shortName = "Edite";
    accountsDb.updateAccount(a, true);
    actualAccount = accountsDb.getAccount(a.googleId, true);
    assertEquals(a.studentProfile.shortName, actualAccount.studentProfile.shortName);
    ______TS("success: profile not modified in the default case");
    Instant expectedModifiedDate = actualAccount.studentProfile.modifiedDate;
    String expectedNationality = actualAccount.studentProfile.nationality;
    actualAccount.studentProfile.nationality = "Andorran";
    actualAccount.institute = "newer institute";
    accountsDb.updateAccount(actualAccount);
    a = accountsDb.getAccount(a.googleId, true);
    // ensure update was successful
    assertEquals(actualAccount.institute, a.institute);
    // ensure profile was not updated
    assertEquals(expectedModifiedDate, a.studentProfile.modifiedDate);
    assertEquals(expectedNationality, a.studentProfile.nationality);
    ______TS("success: modified date does not change if profile is not changed");
    actualAccount = accountsDb.getAccount(a.googleId, true);
    actualAccount.institute = "new institute";
    accountsDb.updateAccount(actualAccount);
    a = accountsDb.getAccount(a.googleId, true);
    // ensure update was successful
    assertEquals(actualAccount.institute, a.institute);
    // ensure modified date was not updated
    assertEquals(expectedModifiedDate, a.studentProfile.modifiedDate);
    ______TS("non-existent account");
    try {
        a.googleId = "non.existent";
        accountsDb.updateAccount(a);
        signalFailureToDetectException(" - EntityDoesNotExistException");
    } catch (EntityDoesNotExistException edne) {
        AssertHelper.assertContains(AccountsDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, edne.getMessage());
    }
    ______TS("failure: invalid parameters");
    a.googleId = "";
    a.email = "test-no-at-funny.com";
    a.name = "%asdf";
    a.institute = StringHelperExtension.generateStringOfLength(65);
    a.studentProfile.shortName = "??";
    try {
        accountsDb.updateAccount(a);
        signalFailureToDetectException(" - InvalidParametersException");
    } catch (InvalidParametersException ipe) {
        assertEquals(StringHelper.toString(a.getInvalidityInfo()), ipe.getMessage());
    }
    // Only check first 2 parameters (course & email) which are used to identify the student entry.
    // The rest are actually allowed to be null.
    ______TS("failure: null parameter");
    try {
        accountsDb.updateAccount(null);
        signalFailureToDetectException(" - AssertionError");
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Instant(java.time.Instant) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 27 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class AccountsDbTest method getNewAccountAttributes.

private AccountAttributes getNewAccountAttributes() {
    AccountAttributes a = AccountAttributes.builder().withGoogleId("valid.googleId").withName("Valid Fresh Account").withIsInstructor(false).withEmail("valid@email.com").withInstitute("TEAMMATES Test Institute 1").build();
    a.studentProfile = StudentProfileAttributes.builder(a.googleId).withInstitute(a.institute).build();
    return a;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes)

Example 28 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class AccountsDbTest method createNewAccount.

private AccountAttributes createNewAccount() throws Exception {
    AccountAttributes a = getNewAccountAttributes();
    accountsDb.createAccount(a);
    return a;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes)

Example 29 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class InstructorCourseDetailsPageDataTest method testAll.

@Test
public void testAll() {
    ______TS("test typical case");
    AccountAttributes instructorAccount = dataBundle.accounts.get("instructor1OfCourse1");
    InstructorCourseDetailsPageData pageData = new InstructorCourseDetailsPageData(instructorAccount, dummySessionToken);
    InstructorAttributes curInstructor = dataBundle.instructors.get("instructor1OfCourse1");
    List<InstructorAttributes> instructors = new ArrayList<>();
    for (InstructorAttributes instructor : dataBundle.instructors.values()) {
        if ("idOfTypicalCourse1".equals(instructor.courseId)) {
            instructors.add(instructor);
        }
    }
    CourseDetailsBundle courseDetails = new CourseDetailsBundle(dataBundle.courses.get("typicalCourse1"));
    courseDetails.sections = new ArrayList<>();
    SectionDetailsBundle sampleSection = new SectionDetailsBundle();
    sampleSection.name = "Sample section name";
    courseDetails.sections.add(sampleSection);
    pageData.init(curInstructor, courseDetails, instructors);
    assertEquals(instructors.size(), pageData.getInstructors().size());
    assertNotNull(pageData.getCourseRemindButton());
    assertFalse(pageData.getCourseRemindButton().getAttributes().isEmpty());
    assertNull(pageData.getCourseRemindButton().getContent());
    assertNotNull(pageData.getCourseDetails());
    assertNotNull(pageData.getCurrentInstructor());
    assertTrue(pageData.isHasSection());
    assertEquals(1, pageData.getSections().size());
    ______TS("test data bundle with no section");
    courseDetails.sections = new ArrayList<>();
    sampleSection = new SectionDetailsBundle();
    sampleSection.name = "None";
    courseDetails.sections.add(sampleSection);
    pageData.init(curInstructor, courseDetails, instructors);
    assertFalse(pageData.isHasSection());
    assertEquals(1, pageData.getSections().size());
    ______TS("test current instructor doesn't have any permission for the course");
    String[] allPrivileges = { Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS };
    for (String privilege : allPrivileges) {
        curInstructor.privileges.updatePrivilege(privilege, false);
    }
    pageData.init(curInstructor, courseDetails, instructors);
    assertEquals(instructors.size(), pageData.getInstructors().size());
    assertNotNull(pageData.getCourseRemindButton());
    assertFalse(pageData.getCourseRemindButton().getAttributes().isEmpty());
    assertNull(pageData.getCourseRemindButton().getContent());
    assertNotNull(pageData.getCourseDetails());
    assertNotNull(pageData.getCurrentInstructor());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) InstructorCourseDetailsPageData(teammates.ui.pagedata.InstructorCourseDetailsPageData) ArrayList(java.util.ArrayList) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 30 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class InstructorCourseEditPageDataTest method testAll.

@Test
public void testAll() {
    ______TS("test typical case");
    AccountAttributes account = dataBundle.accounts.get("instructor1OfCourse1");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    List<InstructorAttributes> instructorList = new ArrayList<>();
    instructorList.add(dataBundle.instructors.get("instructor1OfCourse1"));
    instructorList.add(dataBundle.instructors.get("instructor2OfCourse1"));
    instructorList.add(dataBundle.instructors.get("helperOfCourse1"));
    instructorList.add(dataBundle.instructors.get("instructorNotYetJoinCourse1"));
    InstructorAttributes currentInstructor = dataBundle.instructors.get("instructor1OfCourse1");
    int offset = -1;
    List<String> sectionNames = new ArrayList<>();
    sectionNames.add("Section 1");
    sectionNames.add("Section 2");
    List<String> feedbackSessionNames = new ArrayList<>();
    feedbackSessionNames.add("First feedback session");
    feedbackSessionNames.add("Second feedback session");
    feedbackSessionNames.add("Grace Period Session");
    feedbackSessionNames.add("Closed Session");
    feedbackSessionNames.add("Empty session");
    feedbackSessionNames.add("non visible session");
    InstructorCourseEditPageData pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
    assertEquals("idOfTypicalCourse1", pageData.getCourse().getId());
    assertEquals(-1, pageData.getInstructorToShowIndex());
    assertNotNull(pageData.getDeleteCourseButton());
    assertNotNull(pageData.getAddInstructorButton());
    assertNotNull(pageData.getInstructorPanelList());
    assertEquals(instructorList.size(), pageData.getInstructorPanelList().size());
    CourseEditInstructorPanel panel = pageData.getInstructorPanelList().get(0);
    assertEquals(4, panel.getPermissionInputGroup1().size());
    assertEquals(1, panel.getPermissionInputGroup2().size());
    assertEquals(3, panel.getPermissionInputGroup3().size());
    assertEquals("idOfInstructor1OfCourse1", panel.getInstructor().googleId);
    assertNotNull(panel.getDeleteButton());
    assertNotNull(panel.getEditButton());
    assertNull(panel.getResendInviteButton());
    assertEquals(sectionNames.size(), panel.getSectionRows().size());
    CourseEditSectionRow sectionRow = panel.getSectionRows().get(0);
    assertEquals(1, sectionRow.getPermissionInputGroup2().size());
    assertEquals(3, sectionRow.getPermissionInputGroup3().size());
    assertEquals(feedbackSessionNames.size(), sectionRow.getFeedbackSessions().size());
    assertFalse(sectionRow.isSectionSpecial());
    /*
         * Comment for below Assertion:
         * These sections are separated by a group of 3 so here is the formula to get the number
         * of groups.
         */
    assertEquals((sectionNames.size() - 1) / 3 + 1, sectionRow.getSpecialSections().size());
    assertNotNull(pageData.getAddInstructorPanel());
    CourseEditInstructorPanel addInstructorPanel = pageData.getAddInstructorPanel();
    assertEquals(4, addInstructorPanel.getPermissionInputGroup1().size());
    assertEquals(1, addInstructorPanel.getPermissionInputGroup2().size());
    assertEquals(3, addInstructorPanel.getPermissionInputGroup3().size());
    assertEquals(sectionNames.size(), addInstructorPanel.getSectionRows().size());
    sectionRow = addInstructorPanel.getSectionRows().get(0);
    assertEquals(feedbackSessionNames.size(), sectionRow.getFeedbackSessions().size());
    ______TS("test case when current instructor has no privilege");
    String[] privileges = { Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS };
    for (String privilege : privileges) {
        currentInstructor.privileges.updatePrivilege(privilege, false);
    }
    pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
    assertNull(pageData.getDeleteCourseButton().getAttributes().get("disabled"));
    assertTrue(pageData.getDeleteCourseButton().getAttributes().containsKey("disabled"));
    assertNull(pageData.getAddInstructorButton().getAttributes().get("disabled"));
    assertTrue(pageData.getAddInstructorButton().getAttributes().containsKey("disabled"));
    ______TS("test showing only one instructor");
    offset = 1;
    pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
    assertNotNull(pageData.getAddInstructorPanel());
    assertTrue(pageData.getInstructorPanelList().get(0).isAccessControlDisplayed());
    ______TS("test specialSection");
    InstructorAttributes instructor = instructorList.get(0);
    instructor.privileges.addSessionWithDefaultPrivileges("Section 1", "First feedback session");
    pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
    assertTrue(pageData.getInstructorPanelList().get(0).getSectionRows().get(0).isSectionSpecial());
    ______TS("test empty sectionNames");
    sectionNames = new ArrayList<>();
    pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
    assertNotNull(pageData.getAddInstructorPanel());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) InstructorCourseEditPageData(teammates.ui.pagedata.InstructorCourseEditPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseEditSectionRow(teammates.ui.template.CourseEditSectionRow) CourseEditInstructorPanel(teammates.ui.template.CourseEditInstructorPanel) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Aggregations

AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)84 Test (org.testng.annotations.Test)53 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)28 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 ArrayList (java.util.ArrayList)13 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)11 HashMap (java.util.HashMap)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InvalidParametersException (teammates.common.exception.InvalidParametersException)6 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)5 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)4 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 EmailWrapper (teammates.common.util.EmailWrapper)4 RedirectResult (teammates.ui.controller.RedirectResult)4 List (java.util.List)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 AccountsDb (teammates.storage.api.AccountsDb)3 Account (teammates.storage.entity.Account)3 ShowPageResult (teammates.ui.controller.ShowPageResult)3