Search in sources :

Example 11 with EntityAlreadyExistsException

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());
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) Text(com.google.appengine.api.datastore.Text) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 12 with EntityAlreadyExistsException

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());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 13 with EntityAlreadyExistsException

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());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) CoursesDb(teammates.storage.api.CoursesDb) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 14 with EntityAlreadyExistsException

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());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) Test(org.testng.annotations.Test)

Example 15 with EntityAlreadyExistsException

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());
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) Test(org.testng.annotations.Test)

Aggregations

EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)23 InvalidParametersException (teammates.common.exception.InvalidParametersException)19 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)10 Test (org.testng.annotations.Test)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)7 StatusMessage (teammates.common.util.StatusMessage)7 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)4 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)4 ArrayList (java.util.ArrayList)3 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)3 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)3 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)3 Text (com.google.appengine.api.datastore.Text)2 List (java.util.List)2 EnrollException (teammates.common.exception.EnrollException)2 InstructorCourseEnrollPageData (teammates.ui.pagedata.InstructorCourseEnrollPageData)2 InstructorCourseEnrollResultPageData (teammates.ui.pagedata.InstructorCourseEnrollResultPageData)2 Comparator (java.util.Comparator)1 CourseEnrollmentResult (teammates.common.datatransfer.CourseEnrollmentResult)1