Search in sources :

Example 61 with EntityDoesNotExistException

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

Example 62 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException 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());
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) HashMap(java.util.HashMap) InvalidParametersException(teammates.common.exception.InvalidParametersException) FeedbackResponseDetails(teammates.common.datatransfer.questions.FeedbackResponseDetails) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 63 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class InstructorsDbTest method testUpdateInstructorByGoogleId.

@Test
public void testUpdateInstructorByGoogleId() throws Exception {
    InstructorAttributes instructorToEdit = dataBundle.instructors.get("instructor2OfCourse1");
    ______TS("Success: update an instructor");
    instructorToEdit.name = "New Name";
    instructorToEdit.email = "InstrDbT.new-email@email.tmt";
    instructorToEdit.isArchived = true;
    instructorToEdit.role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER;
    instructorToEdit.isDisplayedToStudents = false;
    instructorToEdit.displayedName = "New Displayed Name";
    instructorToEdit.privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER);
    instructorsDb.updateInstructorByGoogleId(instructorToEdit);
    InstructorAttributes instructorUpdated = instructorsDb.getInstructorForGoogleId(instructorToEdit.courseId, instructorToEdit.googleId);
    assertEquals(instructorToEdit.name, instructorUpdated.name);
    assertEquals(instructorToEdit.email, instructorUpdated.email);
    assertTrue(instructorUpdated.isArchived);
    assertEquals(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER, instructorUpdated.role);
    assertFalse(instructorUpdated.isDisplayedToStudents);
    assertEquals("New Displayed Name", instructorUpdated.displayedName);
    assertTrue(instructorUpdated.hasObserverPrivileges());
    // Verifying less privileged 'Observer' role did not return false positive in case old 'Manager' role is unchanged.
    assertFalse(instructorUpdated.hasManagerPrivileges());
    ______TS("Failure: invalid parameters");
    instructorToEdit.name = "";
    instructorToEdit.email = "aaa";
    instructorToEdit.role = "invalid role";
    try {
        instructorsDb.updateInstructorByGoogleId(instructorToEdit);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedEmptyStringErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.PERSON_NAME_MAX_LENGTH) + System.lineSeparator() + getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, instructorToEdit.email, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH) + System.lineSeparator() + String.format(FieldValidator.ROLE_ERROR_MESSAGE, instructorToEdit.role), e.getMessage());
    }
    ______TS("Failure: non-existent entity");
    instructorToEdit.googleId = "idOfInstructor4";
    instructorToEdit.name = "New Name 2";
    instructorToEdit.email = "InstrDbT.new-email2@email.tmt";
    instructorToEdit.role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER;
    try {
        instructorsDb.updateInstructorByGoogleId(instructorToEdit);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains(EntitiesDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, e.getMessage());
    }
    ______TS("Failure: null parameters");
    try {
        instructorsDb.updateInstructorByGoogleId(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 64 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class StudentsDbTest method testUpdateStudentWithoutDocument.

@Test
public void testUpdateStudentWithoutDocument() throws InvalidParametersException, EntityDoesNotExistException {
    // Create a new student with valid attributes
    StudentAttributes s = createNewStudent();
    studentsDb.updateStudentWithoutSearchability(s.course, s.email, "new-name", "new-team", "new-section", "new@email.com", "new.google.id", "lorem ipsum dolor si amet");
    ______TS("non-existent case");
    try {
        studentsDb.updateStudentWithoutSearchability("non-existent-course", "non@existent.email", "no-name", "non-existent-team", "non-existent-section", "non.existent.ID", "blah", "blah");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals(StudentsDb.ERROR_UPDATE_NON_EXISTENT_STUDENT + "non-existent-course/non@existent.email", e.getMessage());
    }
    // Only check first 2 params (course & email) which are used to identify the student entry.
    // The rest are actually allowed to be null.
    ______TS("null course case");
    try {
        studentsDb.updateStudentWithoutSearchability(null, s.email, "new-name", "new-team", "new-section", "new@email.com", "new.google.id", "lorem ipsum dolor si amet");
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("null email case");
    try {
        studentsDb.updateStudentWithoutSearchability(s.course, null, "new-name", "new-team", "new-section", "new@email.com", "new.google.id", "lorem ipsum dolor si amet");
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("duplicate email case");
    s = createNewStudent();
    // Create a second student with different email address
    StudentAttributes s2 = createNewStudent("valid2@email.com");
    try {
        studentsDb.updateStudentWithoutSearchability(s.course, s.email, "new-name", "new-team", "new-section", s2.email, "new.google.id", "lorem ipsum dolor si amet");
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertEquals(StudentsDb.ERROR_UPDATE_EMAIL_ALREADY_USED + s2.name + "/" + s2.email, e.getMessage());
    }
    ______TS("typical success case");
    String originalEmail = s.email;
    s.name = "new-name-2";
    s.team = "new-team-2";
    s.email = "new-email-2@email.com";
    s.googleId = "new-id-2";
    s.comments = "this are new comments";
    studentsDb.updateStudentWithoutSearchability(s.course, originalEmail, s.name, s.team, s.section, s.email, s.googleId, s.comments);
    StudentAttributes updatedStudent = studentsDb.getStudentForEmail(s.course, s.email);
    assertTrue(updatedStudent.isEnrollInfoSameAs(s));
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 65 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogic method updateCourse.

/**
 * Updates the course details.
 * @param courseId Id of the course to update
 * @param courseName new name of the course
 * @param courseTimeZone new time zone of the course
 */
public void updateCourse(String courseId, String courseName, String courseTimeZone) throws InvalidParametersException, EntityDoesNotExistException {
    CourseAttributes newCourse = validateAndCreateCourseAttributes(courseId, courseName, courseTimeZone);
    CourseAttributes oldCourse = coursesDb.getCourse(newCourse.getId());
    if (oldCourse == null) {
        throw new EntityDoesNotExistException("Trying to update a course that does not exist.");
    }
    coursesDb.updateCourse(newCourse);
}
Also used : CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4