Search in sources :

Example 31 with CourseAttributes

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

the class CoursesLogicTest method testCreateCourseAndInstructor.

private void testCreateCourseAndInstructor() throws Exception {
    /* Explanation: SUT has 5 paths. They are,
         * path 1 - exit because the account doesn't' exist.
         * path 2 - exit because the account exists but doesn't have instructor privileges.
         * path 3 - exit because course creation failed.
         * path 4 - exit because instructor creation failed.
         * path 5 - success.
         * Accordingly, we have 5 test cases.
         */
    ______TS("fails: account doesn't exist");
    CourseAttributes c = CourseAttributes.builder("fresh-course-tccai", "Fresh course for tccai", ZoneId.of("America/Los_Angeles")).build();
    @SuppressWarnings("deprecation") InstructorAttributes i = InstructorAttributes.builder("instructor-for-tccai", c.getId(), "Instructor for tccai", "ins.for.iccai@gmail.tmt").build();
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, c.getId(), c.getName(), c.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("for a non-existent instructor", e.getMessage());
    }
    verifyAbsentInDatastore(c);
    verifyAbsentInDatastore(i);
    ______TS("fails: account doesn't have instructor privileges");
    AccountAttributes a = AccountAttributes.builder().withGoogleId(i.googleId).withName(i.name).withIsInstructor(false).withEmail(i.email).withInstitute("TEAMMATES Test Institute 5").withDefaultStudentProfileAttributes(i.googleId).build();
    accountsDb.createAccount(a);
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, c.getId(), c.getName(), c.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("doesn't have instructor privileges", e.getMessage());
    }
    verifyAbsentInDatastore(c);
    verifyAbsentInDatastore(i);
    ______TS("fails: error during course creation");
    a.isInstructor = true;
    accountsDb.updateAccount(a);
    CourseAttributes invalidCourse = CourseAttributes.builder("invalid id", "Fresh course for tccai", ZoneId.of("UTC")).build();
    String expectedError = "\"" + invalidCourse.getId() + "\" is not acceptable to TEAMMATES as a/an course ID because" + " it is not in the correct format. " + "A course ID can contain letters, numbers, fullstops, hyphens, underscores, and dollar signs. " + "It cannot be longer than 40 characters, cannot be empty and cannot contain spaces.";
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, invalidCourse.getId(), invalidCourse.getName(), invalidCourse.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertEquals(expectedError, e.getMessage());
    }
    verifyAbsentInDatastore(invalidCourse);
    verifyAbsentInDatastore(i);
    ______TS("fails: error during instructor creation due to duplicate instructor");
    CourseAttributes courseWithDuplicateInstructor = CourseAttributes.builder("fresh-course-tccai", "Fresh course for tccai", ZoneId.of("UTC")).build();
    // create a duplicate instructor
    instructorsDb.createEntity(i);
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Unexpected exception while trying to create instructor for a new course", e.getMessage());
    }
    verifyAbsentInDatastore(courseWithDuplicateInstructor);
    ______TS("fails: error during instructor creation due to invalid parameters");
    i.email = "ins.for.iccai.gmail.tmt";
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Unexpected exception while trying to create instructor for a new course", e.getMessage());
    }
    verifyAbsentInDatastore(courseWithDuplicateInstructor);
    ______TS("success: typical case");
    i.email = "ins.for.iccai@gmail.tmt";
    // remove the duplicate instructor object from the datastore.
    instructorsDb.deleteInstructor(i.courseId, i.email);
    coursesLogic.createCourseAndInstructor(i.googleId, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
    verifyPresentInDatastore(courseWithDuplicateInstructor);
    verifyPresentInDatastore(i);
    ______TS("Null parameter");
    try {
        coursesLogic.createCourseAndInstructor(null, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 32 with CourseAttributes

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

the class CoursesLogicTest method testCreateCourse.

private void testCreateCourse() throws Exception {
    ______TS("typical case");
    CourseAttributes c = CourseAttributes.builder("Computing101-fresh", "Basic Computing", ZoneId.of("Asia/Singapore")).build();
    coursesLogic.createCourse(c.getId(), c.getName(), c.getTimeZone().getId());
    verifyPresentInDatastore(c);
    coursesLogic.deleteCourseCascade(c.getId());
    ______TS("Null parameter");
    try {
        coursesLogic.createCourse(null, c.getName(), c.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals("Non-null value expected", e.getMessage());
    }
    ______TS("Invalid time zone");
    String invalidTimeZone = "Invalid Timezone";
    try {
        coursesLogic.createCourse(c.getId(), c.getName(), invalidTimeZone);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        String expectedErrorMessage = getPopulatedErrorMessage(FieldValidator.TIME_ZONE_ERROR_MESSAGE, invalidTimeZone, FieldValidator.TIME_ZONE_FIELD_NAME, FieldValidator.REASON_UNAVAILABLE_AS_CHOICE);
        assertEquals(expectedErrorMessage, e.getMessage());
    }
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 33 with CourseAttributes

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

the class CoursesLogicTest method testGetCourseSummary.

private void testGetCourseSummary() throws Exception {
    ______TS("typical case");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseDetailsBundle courseSummary = coursesLogic.getCourseSummary(course.getId());
    assertEquals(course.getId(), courseSummary.course.getId());
    assertEquals(course.getName(), courseSummary.course.getName());
    assertEquals(2, courseSummary.stats.teamsTotal);
    assertEquals(5, courseSummary.stats.studentsTotal);
    assertEquals(0, courseSummary.stats.unregisteredTotal);
    assertEquals(1, courseSummary.sections.get(0).teams.size());
    assertEquals("Team 1.1</td></div>'\"", courseSummary.sections.get(0).teams.get(0).name);
    ______TS("course without students");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
    AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "Asia/Singapore");
    courseSummary = coursesLogic.getCourseSummary("course1");
    assertEquals("course1", courseSummary.course.getId());
    assertEquals("course 1", courseSummary.course.getName());
    assertEquals("Asia/Singapore", courseSummary.course.getTimeZone().getId());
    assertEquals(0, courseSummary.stats.teamsTotal);
    assertEquals(0, courseSummary.stats.studentsTotal);
    assertEquals(0, courseSummary.stats.unregisteredTotal);
    assertEquals(0, courseSummary.sections.size());
    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");
    ______TS("non-existent");
    try {
        coursesLogic.getCourseSummary("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("The course does not exist:", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getCourseSummary((CourseAttributes) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
    try {
        coursesLogic.getCourseSummary((String) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 34 with CourseAttributes

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

the class CoursesLogicTest method testGetCourseDetails.

private void testGetCourseDetails() throws Exception {
    ______TS("typical case");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseDetailsBundle courseDetails = coursesLogic.getCourseSummary(course.getId());
    assertEquals(course.getId(), courseDetails.course.getId());
    assertEquals(course.getName(), courseDetails.course.getName());
    assertEquals(course.getTimeZone(), courseDetails.course.getTimeZone());
    assertEquals(2, courseDetails.stats.teamsTotal);
    assertEquals(5, courseDetails.stats.studentsTotal);
    assertEquals(0, courseDetails.stats.unregisteredTotal);
    assertEquals(1, courseDetails.sections.get(0).teams.size());
    assertEquals("Team 1.1</td></div>'\"", courseDetails.sections.get(0).teams.get(0).name);
    ______TS("course without students");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
    AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "Australia/Adelaide");
    courseDetails = coursesLogic.getCourseSummary("course1");
    assertEquals("course1", courseDetails.course.getId());
    assertEquals("course 1", courseDetails.course.getName());
    assertEquals("Australia/Adelaide", courseDetails.course.getTimeZone().getId());
    assertEquals(0, courseDetails.stats.teamsTotal);
    assertEquals(0, courseDetails.stats.studentsTotal);
    assertEquals(0, courseDetails.stats.unregisteredTotal);
    assertEquals(0, courseDetails.sections.size());
    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");
    ______TS("non-existent");
    try {
        coursesLogic.getCourseSummary("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("The course does not exist:", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getCourseSummary((String) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 35 with CourseAttributes

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

the class CoursesLogicTest method testUpdateCourse.

private void testUpdateCourse() throws Exception {
    CourseAttributes c = CourseAttributes.builder("Computing101-getthis", "Basic Computing Getting", ZoneId.of("UTC")).build();
    coursesDb.createEntity(c);
    ______TS("Typical case");
    String newName = "New Course Name";
    String validTimeZone = "Asia/Singapore";
    coursesLogic.updateCourse(c.getId(), newName, validTimeZone);
    c.setName(newName);
    c.setTimeZone(ZoneId.of(validTimeZone));
    verifyPresentInDatastore(c);
    ______TS("Invalid time zone and name");
    String emptyName = "";
    String invalidTimeZone = "Invalid Timezone";
    try {
        coursesLogic.updateCourse(c.getId(), emptyName, invalidTimeZone);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        String expectedErrorMessage = getPopulatedEmptyStringErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.COURSE_NAME_FIELD_NAME, FieldValidator.COURSE_NAME_MAX_LENGTH) + System.lineSeparator() + getPopulatedErrorMessage(FieldValidator.TIME_ZONE_ERROR_MESSAGE, invalidTimeZone, FieldValidator.TIME_ZONE_FIELD_NAME, FieldValidator.REASON_UNAVAILABLE_AS_CHOICE);
        assertEquals(expectedErrorMessage, e.getMessage());
        verifyPresentInDatastore(c);
    }
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

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