use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class CoursesLogicTest method testGetCourseSummaryWithoutStats.
private void testGetCourseSummaryWithoutStats() throws Exception {
______TS("typical case");
CourseAttributes course = dataBundle.courses.get("typicalCourse1");
CourseSummaryBundle courseSummary = coursesLogic.getCourseSummaryWithoutStats(course.getId());
assertEquals(course.getId(), courseSummary.course.getId());
assertEquals(course.getName(), courseSummary.course.getName());
______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", "America/Los_Angeles");
courseSummary = coursesLogic.getCourseSummaryWithoutStats("course1");
assertEquals("course1", courseSummary.course.getId());
assertEquals("course 1", courseSummary.course.getName());
assertEquals("America/Los_Angeles", courseSummary.course.getTimeZone().getId());
coursesLogic.deleteCourseCascade("course1");
accountsDb.deleteAccount("instructor1");
______TS("non-existent");
try {
coursesLogic.getCourseSummaryWithoutStats("non-existent-course");
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("The course does not exist:", e.getMessage());
}
______TS("null parameter");
try {
coursesLogic.getCourseSummaryWithoutStats((CourseAttributes) null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
try {
coursesLogic.getCourseSummaryWithoutStats((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 testVerifyCourseIsPresent.
private void testVerifyCourseIsPresent() throws Exception {
______TS("typical case: verify a non-existent course");
CourseAttributes nonExistentCourse = CourseAttributes.builder("non-existent-course", "non existent course", ZoneId.of("UTC")).build();
try {
coursesLogic.verifyCourseIsPresent(nonExistentCourse.getId());
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("Course does not exist: ", e.getMessage());
}
______TS("typical case: verify an existent course");
CourseAttributes existingCourse = CourseAttributes.builder("idOfTypicalCourse1", "existing course", ZoneId.of("UTC")).build();
coursesLogic.verifyCourseIsPresent(existingCourse.getId());
______TS("Null parameter");
try {
coursesLogic.verifyCourseIsPresent(null);
signalFailureToDetectException();
} catch (AssertionError | EntityDoesNotExistException e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
}
use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class CoursesLogicTest method testGetTeamsForCourse.
private void testGetTeamsForCourse() throws Exception {
______TS("typical case");
CourseAttributes course = dataBundle.courses.get("typicalCourse1");
List<TeamDetailsBundle> teams = coursesLogic.getTeamsForCourse(course.getId());
assertEquals(2, teams.size());
assertEquals("Team 1.1</td></div>'\"", teams.get(0).name);
assertEquals("Team 1.2", teams.get(1).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", "UTC");
teams = coursesLogic.getTeamsForCourse("course1");
assertEquals(0, teams.size());
coursesLogic.deleteCourseCascade("course1");
accountsDb.deleteAccount("instructor1");
______TS("non-existent");
try {
coursesLogic.getTeamsForCourse("non-existent-course");
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("does not exist", e.getMessage());
}
______TS("null parameter");
try {
coursesLogic.getTeamsForCourse(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 FeedbackResponsesLogicTest method testUpdateFeedbackResponse.
private void testUpdateFeedbackResponse() throws Exception {
______TS("success: standard update with carried params ");
FeedbackResponseAttributes responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
responseToUpdate.responseMetaData = new Text("Updated Response");
responseToUpdate.feedbackSessionName = "copy over";
responseToUpdate.recipient = null;
frLogic.updateFeedbackResponse(responseToUpdate);
responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
responseToUpdate.responseMetaData = new Text("Updated Response");
assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
______TS("failure: recipient one that is already exists");
responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
FeedbackResponseAttributes existingResponse = new FeedbackResponseAttributes(responseToUpdate.feedbackSessionName, responseToUpdate.courseId, responseToUpdate.feedbackQuestionId, responseToUpdate.feedbackQuestionType, responseToUpdate.giver, responseToUpdate.giverSection, "student3InCourse1@gmail.tmt", responseToUpdate.recipientSection, responseToUpdate.responseMetaData);
frLogic.createFeedbackResponse(existingResponse);
responseToUpdate.recipient = "student3InCourse1@gmail.tmt";
try {
frLogic.updateFeedbackResponse(responseToUpdate);
signalFailureToDetectException("Should have detected that same giver->recipient response alr exists");
} catch (EntityAlreadyExistsException e) {
AssertHelper.assertContains("Trying to create a Feedback Response that exists", e.getMessage());
}
______TS("success: standard update with carried params - using createFeedbackResponse");
responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
responseToUpdate.responseMetaData = new Text("Updated Response 2");
responseToUpdate.feedbackSessionName = "copy over";
frLogic.createFeedbackResponse(responseToUpdate);
responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
responseToUpdate.responseMetaData = new Text("Updated Response 2");
assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
______TS("success: recipient changed to something else");
responseToUpdate.recipient = "student5InCourse1@gmail.tmt";
frLogic.updateFeedbackResponse(responseToUpdate);
assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
assertNull(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, "student2InCourse1@gmail.tmt"));
______TS("success: both giver and recipient changed (teammate changed response)");
responseToUpdate = getResponseFromDatastore("response1GracePeriodFeedback");
responseToUpdate.giver = "student5InCourse1@gmail.tmt";
responseToUpdate.recipient = "Team 1.1";
assertNotNull(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, "student4InCourse1@gmail.tmt", "Team 1.2"));
frLogic.updateFeedbackResponse(responseToUpdate);
assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
assertNull(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, "student4InCourse1@gmail.tmt", "Team 1.2"));
______TS("failure: invalid params");
// Cannot have invalid params as all possible invalid params
// are copied over from an existing response.
______TS("failure: no such response");
responseToUpdate.setId("invalidId");
try {
frLogic.updateFeedbackResponse(responseToUpdate);
signalFailureToDetectException("Should have detected that this response does not exist");
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("Trying to update a feedback response that does not exist.", e.getMessage());
}
}
use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class CoursesDbTest method testUpdateCourse.
@Test
public void testUpdateCourse() throws Exception {
______TS("Failure: null paramater");
try {
coursesDb.updateCourse(null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
______TS("Failure: update course with invalid parameters");
CourseAttributes invalidCourse = CourseAttributes.builder("", "", ZoneId.of("UTC")).build();
try {
coursesDb.updateCourse(invalidCourse);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains("The field 'course ID' is empty", e.getMessage());
AssertHelper.assertContains("The field 'course name' is empty", e.getMessage());
}
______TS("fail: non-exisitng course");
CourseAttributes nonExistentCourse = CourseAttributes.builder("CDbT.non-exist-course", "Non existing course", ZoneId.of("UTC")).build();
try {
coursesDb.updateCourse(nonExistentCourse);
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
assertEquals(CoursesDb.ERROR_UPDATE_NON_EXISTENT_COURSE, e.getMessage());
}
______TS("success: typical case");
CourseAttributes c = createNewCourse();
CourseAttributes updatedCourse = CourseAttributes.builder(c.getId(), c.getName() + " updated", ZoneId.of("UTC")).build();
coursesDb.updateCourse(updatedCourse);
CourseAttributes retrieved = coursesDb.getCourse(c.getId());
assertEquals(c.getName() + " updated", retrieved.getName());
}
Aggregations