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());
}
}
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());
}
}
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());
}
}
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()));
}
}
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));
}
Aggregations