Search in sources :

Example 76 with CourseAttributes

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

the class CoursesDbTest method testCreateCourse.

@Test
public void testCreateCourse() throws EntityAlreadyExistsException, InvalidParametersException {
    /*Explanation:
         * This is an inherited method from EntitiesDb and should be tested in
         * EntitiesDbTest class. We test it here too because the method in
         * the parent class actually calls an overridden method from the SUT.
         */
    ______TS("Success: typical case");
    CourseAttributes c = CourseAttributes.builder("CDbT.tCC.newCourse", "Basic Computing", ZoneId.of("UTC")).build();
    coursesDb.createEntity(c);
    verifyPresentInDatastore(c);
    ______TS("Failure: create duplicate course");
    try {
        coursesDb.createEntity(c);
        signalFailureToDetectException();
    } catch (EntityAlreadyExistsException e) {
        AssertHelper.assertContains(String.format(EntitiesDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, "Course"), e.getMessage());
    }
    ______TS("Failure: create a course with invalid parameter");
    CourseAttributes invalidIdCourse = CourseAttributes.builder("Invalid id", "Basic Computing", ZoneId.of("UTC")).build();
    try {
        coursesDb.createEntity(invalidIdCourse);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains("not acceptable to TEAMMATES as a/an course ID because it is not in the correct format", e.getMessage());
    }
    String longCourseName = StringHelperExtension.generateStringOfLength(FieldValidator.COURSE_NAME_MAX_LENGTH + 1);
    CourseAttributes invalidNameCourse = CourseAttributes.builder("CDbT.tCC.newCourse", longCourseName, ZoneId.of("UTC")).build();
    try {
        coursesDb.createEntity(invalidNameCourse);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains("not acceptable to TEAMMATES as a/an course name because it is too long", e.getMessage());
    }
    ______TS("Failure: null parameter");
    try {
        coursesDb.createEntity(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 77 with CourseAttributes

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

the class EntitiesDbTest method testCreateEntity.

@Test
public void testCreateEntity() throws Exception {
    // We are using CoursesDb to test EntititesDb here.
    CoursesDb coursesDb = new CoursesDb();
    /*Explanation:
         * The SUT (i.e. EntitiesDb::createEntity) has 4 paths. Therefore, we
         * have 4 test cases here, one for each path.
         */
    ______TS("success: typical case");
    CourseAttributes c = CourseAttributes.builder("Computing101-fresh", "Basic Computing", ZoneId.of("UTC")).build();
    coursesDb.deleteCourse(c.getId());
    verifyAbsentInDatastore(c);
    coursesDb.createEntity(c);
    verifyPresentInDatastore(c);
    ______TS("fails: entity already exists");
    try {
        coursesDb.createEntity(c);
        signalFailureToDetectException();
    } catch (EntityAlreadyExistsException e) {
        AssertHelper.assertContains(String.format(CoursesDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, c.getEntityTypeAsString()) + c.getIdentificationString(), e.getMessage());
    }
    coursesDb.deleteEntity(c);
    ______TS("fails: invalid parameters");
    CourseAttributes invalidCourse = CourseAttributes.builder("invalid id spaces", "Basic Computing", ZoneId.of("UTC")).build();
    try {
        coursesDb.createEntity(invalidCourse);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedErrorMessage(COURSE_ID_ERROR_MESSAGE, invalidCourse.getId(), FieldValidator.COURSE_ID_FIELD_NAME, REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), e.getMessage());
    }
    ______TS("fails: null parameter");
    try {
        coursesDb.createEntity(null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) CoursesDb(teammates.storage.api.CoursesDb) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 78 with CourseAttributes

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

the class BackDoorLogicTest method testPersistDataBundle.

@Test
public void testPersistDataBundle() throws Exception {
    ______TS("empty data bundle");
    String status = backDoorLogic.persistDataBundle(new DataBundle());
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    backDoorLogic.removeDataBundle(dataBundle);
    backDoorLogic.persistDataBundle(dataBundle);
    verifyPresentInDatastore(dataBundle);
    ______TS("try to persist while entities exist");
    backDoorLogic.persistDataBundle(loadDataBundle("/FeedbackSessionResultsTest.json"));
    verifyPresentInDatastore(loadDataBundle("/FeedbackSessionResultsTest.json"));
    ______TS("null parameter");
    try {
        backDoorLogic.persistDataBundle(null);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertEquals(Const.StatusCodes.NULL_PARAMETER, e.errorCode);
    }
    ______TS("invalid parameters in an entity");
    CourseAttributes invalidCourse = CourseAttributes.builder("invalid id", "valid course name", ZoneId.of("UTC")).build();
    dataBundle = new DataBundle();
    dataBundle.courses.put("invalid", invalidCourse);
    try {
        backDoorLogic.persistDataBundle(dataBundle);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertTrue(e.getMessage().equals(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, "invalid id", FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH)));
    }
// Not checking for invalid values in other entities because they
// should be checked at lower level methods
}
Also used : DataBundle(teammates.common.datatransfer.DataBundle) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 79 with CourseAttributes

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

the class StudentHomePageDataTest method createData.

private StudentHomePageData createData() {
    // Courses
    CourseAttributes course1 = CourseAttributes.builder("course-id-1", "old-course", ZoneId.of("UTC")).build();
    CourseAttributes course2 = CourseAttributes.builder("course-id-2", "new-course", ZoneId.of("UTC")).build();
    // Feedback sessions
    submittedSession = createFeedbackSession("submitted session", -1, 1, 1);
    pendingSession = createFeedbackSession("pending session", -1, 1, 1);
    awaitingSession = createFeedbackSession("awaiting session", 1, 2, 1);
    publishedSession = createFeedbackSession("published session", -1, -1, -1);
    closedSession = createFeedbackSession("closed session", -2, -1, 1);
    submittedClosedSession = createFeedbackSession("submitted closed session", -2, -1, 1);
    // Submission status
    Map<FeedbackSessionAttributes, Boolean> sessionSubmissionStatusMap = new HashMap<>();
    sessionSubmissionStatusMap.put(submittedSession, true);
    sessionSubmissionStatusMap.put(pendingSession, false);
    sessionSubmissionStatusMap.put(awaitingSession, false);
    sessionSubmissionStatusMap.put(publishedSession, false);
    sessionSubmissionStatusMap.put(closedSession, false);
    sessionSubmissionStatusMap.put(submittedClosedSession, true);
    // Tooltip and button texts
    tooltipTextMap = new HashMap<>();
    buttonTextMap = new HashMap<>();
    tooltipTextMap.put(submittedSession, Const.Tooltips.FEEDBACK_SESSION_EDIT_SUBMITTED_RESPONSE);
    buttonTextMap.put(submittedSession, "Edit Submission");
    tooltipTextMap.put(pendingSession, Const.Tooltips.FEEDBACK_SESSION_SUBMIT);
    buttonTextMap.put(pendingSession, "Start Submission");
    tooltipTextMap.put(awaitingSession, Const.Tooltips.FEEDBACK_SESSION_AWAITING);
    buttonTextMap.put(awaitingSession, "Start Submission");
    tooltipTextMap.put(publishedSession, Const.Tooltips.FEEDBACK_SESSION_VIEW_SUBMITTED_RESPONSE);
    buttonTextMap.put(publishedSession, "View Submission");
    tooltipTextMap.put(closedSession, Const.Tooltips.FEEDBACK_SESSION_VIEW_SUBMITTED_RESPONSE);
    buttonTextMap.put(closedSession, "View Submission");
    tooltipTextMap.put(submittedClosedSession, Const.Tooltips.FEEDBACK_SESSION_VIEW_SUBMITTED_RESPONSE);
    buttonTextMap.put(submittedClosedSession, "View Submission");
    // Packing into bundles
    CourseDetailsBundle newCourseBundle = createCourseBundle(course1, submittedSession, pendingSession, awaitingSession);
    CourseDetailsBundle oldCourseBundle = createCourseBundle(course2, publishedSession, closedSession, submittedClosedSession);
    courses = new ArrayList<>();
    courses.add(newCourseBundle);
    courses.add(oldCourseBundle);
    return new StudentHomePageData(AccountAttributes.builder().build(), dummySessionToken, courses, sessionSubmissionStatusMap);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) HashMap(java.util.HashMap) StudentHomePageData(teammates.ui.pagedata.StudentHomePageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 80 with CourseAttributes

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

the class InstructorFeedbackSessionsPageDataTest method testInit.

@Test
public void testInit() {
    AccountAttributes instructorAccount = dataBundle.accounts.get("instructor1OfCourse1");
    ______TS("typical success case with existing fs passed in");
    InstructorFeedbackSessionsPageData data = new InstructorFeedbackSessionsPageData(instructorAccount, dummySessionToken);
    Map<String, InstructorAttributes> courseInstructorMap = new HashMap<>();
    List<InstructorAttributes> instructors = getInstructorsForGoogleId(instructorAccount.googleId, true);
    for (InstructorAttributes instructor : instructors) {
        courseInstructorMap.put(instructor.courseId, instructor);
    }
    List<InstructorAttributes> instructorsForUser = new ArrayList<>(courseInstructorMap.values());
    List<CourseAttributes> courses = getCoursesForInstructor(instructorsForUser);
    List<FeedbackSessionAttributes> fsList = getFeedbackSessionsListForInstructor(instructorsForUser);
    FeedbackSessionAttributes fsa = dataBundle.feedbackSessions.get("session1InCourse1");
    data.init(courses, null, fsList, courseInstructorMap, fsa, null, null);
    ______TS("typical success case with existing fs passed in: test new fs form");
    // Test new fs form model
    FeedbackSessionsForm formModel = data.getNewFsForm();
    assertNull(formModel.getCourseId());
    assertEquals(1, formModel.getCoursesSelectField().size());
    assertEquals(2, formModel.getFeedbackSessionTypeOptions().size());
    assertEquals("session using template: team peer evaluation", formModel.getFeedbackSessionTypeOptions().get(1).getContent());
    assertNull(formModel.getFeedbackSessionTypeOptions().get(1).getAttributes().get("selected"));
    assertTrue(formModel.getFeedbackSessionTypeOptions().get(1).getAttributes().containsKey("selected"));
    assertEquals("Fri, 30 Apr, 2027", formModel.getFsEndDate());
    assertEquals(NUMBER_OF_HOURS_IN_DAY, formModel.getFsEndTimeOptions().size());
    assertEquals("First feedback session", formModel.getFsName());
    assertEquals("Sun, 01 Apr, 2012", formModel.getFsStartDate());
    assertEquals(NUMBER_OF_HOURS_IN_DAY, formModel.getFsStartTimeOptions().size());
    assertEquals(7, formModel.getGracePeriodOptions().size());
    int expectedDefaultGracePeriodOptionsIndex = 2;
    assertNull(formModel.getGracePeriodOptions().get(expectedDefaultGracePeriodOptionsIndex).getAttributes().get("selected"));
    assertTrue(formModel.getGracePeriodOptions().get(expectedDefaultGracePeriodOptionsIndex).getAttributes().containsKey("selected"));
    assertEquals("Please please fill in the following questions.", formModel.getInstructions());
    assertEquals("Sat, 01 May, 2027", formModel.getAdditionalSettings().getResponseVisibleDateValue());
    assertEquals(NUMBER_OF_HOURS_IN_DAY, formModel.getAdditionalSettings().getResponseVisibleTimeOptions().size());
    assertEquals("Wed, 28 Mar, 2012", formModel.getAdditionalSettings().getSessionVisibleDateValue());
    assertEquals(NUMBER_OF_HOURS_IN_DAY, formModel.getAdditionalSettings().getSessionVisibleTimeOptions().size());
    assertFalse(formModel.getAdditionalSettings().isResponseVisiblePublishManuallyChecked());
    assertTrue(formModel.getAdditionalSettings().isResponseVisibleDateChecked());
    assertFalse(formModel.getAdditionalSettings().isResponseVisibleImmediatelyChecked());
    assertFalse(formModel.getAdditionalSettings().isResponseVisibleDateDisabled());
    assertFalse(formModel.getAdditionalSettings().isSessionVisibleAtOpenChecked());
    assertFalse(formModel.getAdditionalSettings().isSessionVisibleDateDisabled());
    assertTrue(formModel.getAdditionalSettings().isSessionVisibleDateButtonChecked());
    assertFalse(formModel.getAdditionalSettings().isSessionVisiblePrivateChecked());
    ______TS("typical success case with existing fs passed in: session rows");
    FeedbackSessionsTable fsTableModel = data.getFsList();
    List<FeedbackSessionsTableRow> fsRows = fsTableModel.getExistingFeedbackSessions();
    assertEquals(6, fsRows.size());
    String firstFsName = "Grace Period Session";
    assertEquals(firstFsName, fsRows.get(0).getName());
    String lastFsName = "First feedback session";
    assertEquals(lastFsName, fsRows.get(fsRows.size() - 1).getName());
    ______TS("typical success case with existing fs passed in: copy modal");
    FeedbackSessionsCopyFromModal copyModalModel = data.getCopyFromModal();
    assertEquals(1, copyModalModel.getCoursesSelectField().size());
    assertEquals("First feedback session", copyModalModel.getFsName());
    assertEquals(6, copyModalModel.getExistingFeedbackSessions().size());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeedbackSessionsForm(teammates.ui.template.FeedbackSessionsForm) FeedbackSessionsCopyFromModal(teammates.ui.template.FeedbackSessionsCopyFromModal) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackSessionsTableRow(teammates.ui.template.FeedbackSessionsTableRow) FeedbackSessionsTable(teammates.ui.template.FeedbackSessionsTable) InstructorFeedbackSessionsPageData(teammates.ui.pagedata.InstructorFeedbackSessionsPageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Aggregations

CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)106 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 Test (org.testng.annotations.Test)40 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)33 ArrayList (java.util.ArrayList)31 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)19 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)16 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)15 EmailWrapper (teammates.common.util.EmailWrapper)15 HashMap (java.util.HashMap)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)10 EmailGenerator (teammates.logic.api.EmailGenerator)10 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)6 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)4 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)4 InstructorCoursesPageData (teammates.ui.pagedata.InstructorCoursesPageData)4 InstructorFeedbackSessionsPageData (teammates.ui.pagedata.InstructorFeedbackSessionsPageData)4