Search in sources :

Example 11 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException 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 12 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogicTest method testHasIndicatedSections.

private void testHasIndicatedSections() throws Exception {
    ______TS("Typical case: course with sections");
    CourseAttributes typicalCourse1 = dataBundle.courses.get("typicalCourse1");
    assertTrue(coursesLogic.hasIndicatedSections(typicalCourse1.getId()));
    ______TS("Typical case: course without sections");
    CourseAttributes typicalCourse2 = dataBundle.courses.get("typicalCourse2");
    assertFalse(coursesLogic.hasIndicatedSections(typicalCourse2.getId()));
    ______TS("Failure case: course does not exists");
    try {
        coursesLogic.hasIndicatedSections("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("Failure case: null parameter");
    try {
        coursesLogic.hasIndicatedSections(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 13 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogicTest method testGetCourseDetailsListForStudent.

private void testGetCourseDetailsListForStudent() throws Exception {
    ______TS("student having multiple evaluations in multiple courses");
    CourseAttributes expectedCourse1 = dataBundle.courses.get("typicalCourse1");
    // This student is in both course 1 and 2
    StudentAttributes studentInBothCourses = dataBundle.students.get("student2InCourse1");
    // Get course details for student
    List<CourseDetailsBundle> courseList = coursesLogic.getCourseDetailsListForStudent(studentInBothCourses.googleId);
    // Verify number of courses received
    assertEquals(2, courseList.size());
    CourseDetailsBundle actualCourse1 = courseList.get(0);
    assertEquals(expectedCourse1.getId(), actualCourse1.course.getId());
    assertEquals(expectedCourse1.getName(), actualCourse1.course.getName());
    // student with no courses is not applicable
    ______TS("non-existent student");
    try {
        coursesLogic.getCourseDetailsListForStudent("non-existent-student");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getCourseDetailsListForStudent(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 14 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackQuestionsLogicTest method testUpdateQuestion.

private void testUpdateQuestion() throws Exception {
    ______TS("standard update, no existing responses, with 'keep existing' policy");
    FeedbackQuestionAttributes questionToUpdate = getQuestionFromDatastore("qn2InSession2InCourse2");
    questionToUpdate.questionMetaData = new Text("new question text");
    questionToUpdate.questionNumber = 3;
    List<FeedbackParticipantType> newVisibility = new LinkedList<>();
    newVisibility.add(FeedbackParticipantType.INSTRUCTORS);
    questionToUpdate.showResponsesTo = newVisibility;
    // Check keep existing policy.
    String originalCourseId = questionToUpdate.courseId;
    questionToUpdate.courseId = null;
    fqLogic.updateFeedbackQuestion(questionToUpdate);
    questionToUpdate.courseId = originalCourseId;
    FeedbackQuestionAttributes updatedQuestion = fqLogic.getFeedbackQuestion(questionToUpdate.getId());
    assertEquals(updatedQuestion.toString(), questionToUpdate.toString());
    ______TS("cascading update, non-destructive changes, existing responses are preserved");
    questionToUpdate = getQuestionFromDatastore("qn2InSession1InCourse1");
    questionToUpdate.questionMetaData = new Text("new question text 2");
    questionToUpdate.numberOfEntitiesToGiveFeedbackTo = 2;
    int numberOfResponses = frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).size();
    fqLogic.updateFeedbackQuestion(questionToUpdate);
    updatedQuestion = fqLogic.getFeedbackQuestion(questionToUpdate.getId());
    assertEquals(updatedQuestion.toString(), questionToUpdate.toString());
    assertEquals(frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).size(), numberOfResponses);
    ______TS("cascading update, destructive changes, delete all existing responses");
    questionToUpdate = getQuestionFromDatastore("qn2InSession1InCourse1");
    questionToUpdate.questionMetaData = new Text("new question text 3");
    questionToUpdate.recipientType = FeedbackParticipantType.INSTRUCTORS;
    assertFalse(frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).isEmpty());
    fqLogic.updateFeedbackQuestion(questionToUpdate);
    updatedQuestion = fqLogic.getFeedbackQuestion(questionToUpdate.getId());
    assertEquals(updatedQuestion.toString(), questionToUpdate.toString());
    assertEquals(frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).size(), 0);
    ______TS("failure: question does not exist");
    questionToUpdate = getQuestionFromDatastore("qn3InSession1InCourse1");
    fqLogic.deleteFeedbackQuestionCascade(questionToUpdate.getId());
    try {
        fqLogic.updateFeedbackQuestion(questionToUpdate);
        signalFailureToDetectException("Expected EntityDoesNotExistException not caught.");
    } catch (EntityDoesNotExistException e) {
        assertEquals(e.getMessage(), "Trying to update a feedback question that does not exist.");
    }
    ______TS("failure: invalid parameters");
    questionToUpdate = getQuestionFromDatastore("qn3InSession1InCourse1");
    questionToUpdate.giverType = FeedbackParticipantType.TEAMS;
    questionToUpdate.recipientType = FeedbackParticipantType.OWN_TEAM_MEMBERS;
    try {
        fqLogic.updateFeedbackQuestion(questionToUpdate);
        signalFailureToDetectException("Expected InvalidParametersException not caught.");
    } catch (InvalidParametersException e) {
        assertEquals(e.getMessage(), String.format(FieldValidator.PARTICIPANT_TYPE_TEAM_ERROR_MESSAGE, questionToUpdate.recipientType.toDisplayRecipientName(), questionToUpdate.giverType.toDisplayGiverName()));
    }
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) FeedbackParticipantType(teammates.common.datatransfer.FeedbackParticipantType) LinkedList(java.util.LinkedList) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 15 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsLogicTest method testIsFeedbackSessionFullyCompletedByStudent.

private void testIsFeedbackSessionFullyCompletedByStudent() throws Exception {
    FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("session1InCourse1");
    StudentAttributes student1OfCourse1 = dataBundle.students.get("student1InCourse1");
    StudentAttributes student3OfCourse1 = dataBundle.students.get("student3InCourse1");
    ______TS("failure: non-existent feedback session for student");
    try {
        fsLogic.isFeedbackSessionFullyCompletedByStudent("nonExistentFSName", fs.getCourseId(), "random.student@email");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException edne) {
        assertEquals("Trying to check a non-existent feedback session: " + fs.getCourseId() + "/" + "nonExistentFSName", edne.getMessage());
    }
    ______TS("success case: fully done by student 1");
    assertTrue(fsLogic.isFeedbackSessionFullyCompletedByStudent(fs.getFeedbackSessionName(), fs.getCourseId(), student1OfCourse1.email));
    ______TS("success case: partially done by student 3");
    assertFalse(fsLogic.isFeedbackSessionFullyCompletedByStudent(fs.getFeedbackSessionName(), fs.getCourseId(), student3OfCourse1.email));
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4