use of teammates.common.exception.EntityAlreadyExistsException 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.EntityAlreadyExistsException 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());
}
}
use of teammates.common.exception.EntityAlreadyExistsException 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());
}
}
use of teammates.common.exception.EntityAlreadyExistsException in project teammates by TEAMMATES.
the class FeedbackQuestionsDbTest method testCreateDeleteFeedbackQuestion.
@Test
public void testCreateDeleteFeedbackQuestion() throws InvalidParametersException, EntityAlreadyExistsException {
______TS("standard success case");
FeedbackQuestionAttributes fqa = getNewFeedbackQuestionAttributes();
// remove possibly conflicting entity from the database
fqDb.deleteEntity(fqa);
fqDb.createEntity(fqa);
verifyPresentInDatastore(fqa);
______TS("duplicate - with same id.");
try {
fqDb.createEntity(fqa);
signalFailureToDetectException();
} catch (EntityAlreadyExistsException e) {
AssertHelper.assertContains(String.format(FeedbackQuestionsDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, fqa.getEntityTypeAsString()) + fqa.getIdentificationString(), e.getMessage());
}
______TS("delete - with id specified");
fqDb.deleteEntity(fqa);
verifyAbsentInDatastore(fqa);
______TS("null params");
try {
fqDb.createEntity(null);
signalFailureToDetectException();
} catch (AssertionError e) {
AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
}
______TS("invalid params");
try {
fqa.creatorEmail = "haha";
fqDb.createEntity(fqa);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains("Invalid creator's email", e.getLocalizedMessage());
}
}
use of teammates.common.exception.EntityAlreadyExistsException in project teammates by TEAMMATES.
the class FeedbackResponsesDbTest method testCreateDeleteFeedbackResponse.
@Test
public void testCreateDeleteFeedbackResponse() throws Exception {
______TS("standard success case");
FeedbackResponseAttributes fra = getNewFeedbackResponseAttributes();
// remove possibly conflicting entity from the database
frDb.deleteEntity(fra);
frDb.createEntity(fra);
// sets the id for fra
verifyPresentInDatastore(fra);
______TS("duplicate - with same id.");
try {
frDb.createEntity(fra);
signalFailureToDetectException();
} catch (EntityAlreadyExistsException e) {
AssertHelper.assertContains(String.format(FeedbackResponsesDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, fra.getEntityTypeAsString()) + fra.getIdentificationString(), e.getMessage());
}
______TS("delete - with id specified");
frDb.deleteEntity(fra);
verifyAbsentInDatastore(fra);
______TS("null params");
try {
frDb.createEntity(null);
signalFailureToDetectException();
} catch (AssertionError e) {
AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
}
______TS("invalid params");
try {
fra.courseId = "invalid course id!";
frDb.createEntity(fra);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, "invalid course id!", FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), e.getLocalizedMessage());
}
}
Aggregations