use of teammates.common.exception.InvalidParametersException 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.InvalidParametersException 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.InvalidParametersException 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.InvalidParametersException in project teammates by TEAMMATES.
the class FeedbackQuestionsDbTest method testUpdateFeedbackQuestion.
@Test
public void testUpdateFeedbackQuestion() throws Exception {
______TS("null params");
try {
fqDb.updateFeedbackQuestion(null);
signalFailureToDetectException();
} catch (AssertionError e) {
AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
}
______TS("invalid feedback question attributes");
FeedbackQuestionAttributes invalidFqa = getNewFeedbackQuestionAttributes();
fqDb.deleteEntity(invalidFqa);
fqDb.createEntity(invalidFqa);
invalidFqa.setId(fqDb.getFeedbackQuestion(invalidFqa.feedbackSessionName, invalidFqa.courseId, invalidFqa.questionNumber).getId());
invalidFqa.creatorEmail = "haha";
try {
fqDb.updateFeedbackQuestion(invalidFqa);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains("Invalid creator's email", e.getLocalizedMessage());
}
______TS("feedback session does not exist");
FeedbackQuestionAttributes nonexistantFq = getNewFeedbackQuestionAttributes();
nonexistantFq.setId("non-existent fq id");
try {
fqDb.updateFeedbackQuestion(nonexistantFq);
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains(FeedbackQuestionsDb.ERROR_UPDATE_NON_EXISTENT, e.getLocalizedMessage());
}
______TS("standard success case");
FeedbackQuestionAttributes modifiedQuestion = getNewFeedbackQuestionAttributes();
fqDb.deleteEntity(modifiedQuestion);
fqDb.createEntity(modifiedQuestion);
verifyPresentInDatastore(modifiedQuestion);
modifiedQuestion = fqDb.getFeedbackQuestion(modifiedQuestion.feedbackSessionName, modifiedQuestion.courseId, modifiedQuestion.questionNumber);
FeedbackQuestionDetails fqd = modifiedQuestion.getQuestionDetails();
fqd.setQuestionText("New question text!");
modifiedQuestion.setQuestionDetails(fqd);
fqDb.updateFeedbackQuestion(modifiedQuestion);
verifyPresentInDatastore(modifiedQuestion);
modifiedQuestion = fqDb.getFeedbackQuestion(modifiedQuestion.feedbackSessionName, modifiedQuestion.courseId, modifiedQuestion.questionNumber);
assertEquals("New question text!", modifiedQuestion.getQuestionDetails().getQuestionText());
fqDb.deleteEntity(modifiedQuestion);
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class FeedbackResponsesDbTest method testUpdateFeedbackResponse.
@Test
public void testUpdateFeedbackResponse() throws Exception {
______TS("null params");
try {
frDb.updateFeedbackResponse(null);
signalFailureToDetectException();
} catch (AssertionError e) {
AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
}
______TS("invalid feedback response attributes");
FeedbackResponseAttributes invalidFra = getResponseAttributes("response3ForQ2S1C1");
invalidFra.setId(frDb.getFeedbackResponse(invalidFra.feedbackQuestionId, invalidFra.giver, invalidFra.recipient).getId());
invalidFra.courseId = "invalid course_";
try {
frDb.updateFeedbackResponse(invalidFra);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, "invalid course_", FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), e.getLocalizedMessage());
}
______TS("feedback response does not exist");
FeedbackResponseAttributes nonexistantFr = getResponseAttributes("response3ForQ2S1C1");
nonexistantFr.setId("non-existent fr id");
try {
frDb.updateFeedbackResponse(nonexistantFr);
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains(FeedbackResponsesDb.ERROR_UPDATE_NON_EXISTENT, e.getLocalizedMessage());
}
______TS("standard success case");
FeedbackResponseAttributes modifiedResponse = getResponseAttributes("response3ForQ2S1C1");
modifiedResponse = frDb.getFeedbackResponse(modifiedResponse.feedbackQuestionId, modifiedResponse.giver, modifiedResponse.recipient);
FeedbackResponseDetails frd = modifiedResponse.getResponseDetails();
Map<String, String[]> requestParameters = new HashMap<>();
requestParameters.put("questiontype-1", new String[] { "TEXT" });
requestParameters.put("responsetext-1-0", new String[] { "New answer text!" });
String[] answer = { "New answer text!" };
frd = FeedbackResponseDetails.createResponseDetails(answer, FeedbackQuestionType.TEXT, null, requestParameters, 1, 0);
modifiedResponse.setResponseDetails(frd);
frDb.updateFeedbackResponse(modifiedResponse);
verifyPresentInDatastore(modifiedResponse);
modifiedResponse = frDb.getFeedbackResponse(modifiedResponse.feedbackQuestionId, modifiedResponse.giver, modifiedResponse.recipient);
assertEquals("New answer text!", modifiedResponse.getResponseDetails().getAnswerString());
}
Aggregations