Search in sources :

Example 21 with EntityDoesNotExistException

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

the class AccountsDbTest method testEditAccount.

@Test
public void testEditAccount() throws Exception {
    AccountAttributes a = createNewAccount();
    ______TS("typical edit success case (legacy data)");
    a.name = "Edited name";
    a.studentProfile = null;
    accountsDb.updateAccount(a);
    AccountAttributes actualAccount = accountsDb.getAccount(a.googleId, true);
    assertEquals(a.name, actualAccount.name);
    ______TS("typical success case (with profile)");
    a.studentProfile.shortName = "Edite";
    accountsDb.updateAccount(a, true);
    actualAccount = accountsDb.getAccount(a.googleId, true);
    assertEquals(a.studentProfile.shortName, actualAccount.studentProfile.shortName);
    ______TS("success: profile not modified in the default case");
    Instant expectedModifiedDate = actualAccount.studentProfile.modifiedDate;
    String expectedNationality = actualAccount.studentProfile.nationality;
    actualAccount.studentProfile.nationality = "Andorran";
    actualAccount.institute = "newer institute";
    accountsDb.updateAccount(actualAccount);
    a = accountsDb.getAccount(a.googleId, true);
    // ensure update was successful
    assertEquals(actualAccount.institute, a.institute);
    // ensure profile was not updated
    assertEquals(expectedModifiedDate, a.studentProfile.modifiedDate);
    assertEquals(expectedNationality, a.studentProfile.nationality);
    ______TS("success: modified date does not change if profile is not changed");
    actualAccount = accountsDb.getAccount(a.googleId, true);
    actualAccount.institute = "new institute";
    accountsDb.updateAccount(actualAccount);
    a = accountsDb.getAccount(a.googleId, true);
    // ensure update was successful
    assertEquals(actualAccount.institute, a.institute);
    // ensure modified date was not updated
    assertEquals(expectedModifiedDate, a.studentProfile.modifiedDate);
    ______TS("non-existent account");
    try {
        a.googleId = "non.existent";
        accountsDb.updateAccount(a);
        signalFailureToDetectException(" - EntityDoesNotExistException");
    } catch (EntityDoesNotExistException edne) {
        AssertHelper.assertContains(AccountsDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, edne.getMessage());
    }
    ______TS("failure: invalid parameters");
    a.googleId = "";
    a.email = "test-no-at-funny.com";
    a.name = "%asdf";
    a.institute = StringHelperExtension.generateStringOfLength(65);
    a.studentProfile.shortName = "??";
    try {
        accountsDb.updateAccount(a);
        signalFailureToDetectException(" - InvalidParametersException");
    } catch (InvalidParametersException ipe) {
        assertEquals(StringHelper.toString(a.getInvalidityInfo()), ipe.getMessage());
    }
    // Only check first 2 parameters (course & email) which are used to identify the student entry.
    // The rest are actually allowed to be null.
    ______TS("failure: null parameter");
    try {
        accountsDb.updateAccount(null);
        signalFailureToDetectException(" - AssertionError");
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Instant(java.time.Instant) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 22 with EntityDoesNotExistException

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

the class FeedbackResponseCommentsDbTest method testUpdateFeedbackResponseComment.

private void testUpdateFeedbackResponseComment() throws Exception {
    ______TS("null parameter");
    try {
        frcDb.updateFeedbackResponseComment(null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("typical success case");
    FeedbackResponseCommentAttributes frcaTemp = dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q2S1C1");
    frcaTemp.createdAt = Instant.now();
    frcaTemp.commentText = new Text("Update feedback response comment");
    frcDb.createEntity(frcaTemp);
    frcaTemp = frcDb.getFeedbackResponseComment(frcaTemp.feedbackResponseId, frcaTemp.giverEmail, frcaTemp.createdAt);
    FeedbackResponseCommentAttributes frcaExpected = frcDb.getFeedbackResponseComment(frcaTemp.courseId, frcaTemp.createdAt, frcaTemp.giverEmail);
    frcaExpected.commentText = new Text("This is new Text");
    frcDb.updateFeedbackResponseComment(frcaExpected);
    FeedbackResponseCommentAttributes frcaActual = frcDb.getFeedbackResponseComment(frcaExpected.courseId, frcaExpected.createdAt, frcaExpected.giverEmail);
    frcaExpected.setId(frcaActual.getId());
    frcaExpected.feedbackQuestionId = frcaActual.feedbackQuestionId;
    assertEquals(frcaExpected.courseId, frcaActual.courseId);
    assertEquals(frcaExpected.commentText, frcaActual.commentText);
    frcDb.deleteEntity(frcaTemp);
    ______TS("non-existent comment");
    frcaExpected.setId(-1L);
    try {
        frcDb.updateFeedbackResponseComment(frcaExpected);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException edne) {
        assertEquals(EntitiesDb.ERROR_UPDATE_NON_EXISTENT + frcaExpected.toString(), edne.getMessage());
    }
    // set responseId back
    frcaExpected.feedbackResponseId = frId;
    ______TS("invalid parameters");
    frcaExpected.courseId = "";
    frcaExpected.feedbackSessionName = "%asdt";
    frcaExpected.giverEmail = "test-no-at-funny.com";
    try {
        frcDb.updateFeedbackResponseComment(frcaExpected);
        signalFailureToDetectException();
    } catch (InvalidParametersException ipe) {
        assertEquals(StringHelper.toString(frcaExpected.getInvalidityInfo()), ipe.getMessage());
    }
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 23 with EntityDoesNotExistException

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

the class FeedbackSessionsDbTest method testUpdateFeedbackSession.

@Test
public void testUpdateFeedbackSession() throws Exception {
    ______TS("null params");
    try {
        fsDb.updateFeedbackSession(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("invalid feedback sesion attributes");
    FeedbackSessionAttributes invalidFs = getNewFeedbackSession();
    fsDb.deleteEntity(invalidFs);
    fsDb.createEntity(invalidFs);
    Instant afterEndTime = invalidFs.getEndTime().plus(Duration.ofDays(30));
    invalidFs.setStartTime(afterEndTime);
    invalidFs.setResultsVisibleFromTime(afterEndTime);
    try {
        fsDb.updateFeedbackSession(invalidFs);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertEquals(String.format(TIME_FRAME_ERROR_MESSAGE, SESSION_END_TIME_FIELD_NAME, SESSION_START_TIME_FIELD_NAME), e.getLocalizedMessage());
    }
    ______TS("feedback session does not exist");
    FeedbackSessionAttributes nonexistantFs = getNewFeedbackSession();
    nonexistantFs.setFeedbackSessionName("non existant fs");
    nonexistantFs.setCourseId("non.existant.course");
    try {
        fsDb.updateFeedbackSession(nonexistantFs);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains(FeedbackSessionsDb.ERROR_UPDATE_NON_EXISTENT, e.getLocalizedMessage());
    }
    ______TS("standard success case");
    FeedbackSessionAttributes modifiedSession = getNewFeedbackSession();
    fsDb.deleteEntity(modifiedSession);
    fsDb.createEntity(modifiedSession);
    verifyPresentInDatastore(modifiedSession);
    modifiedSession.setInstructions(new Text("new instructions"));
    modifiedSession.setGracePeriodMinutes(0);
    modifiedSession.setSentOpenEmail(false);
    fsDb.updateFeedbackSession(modifiedSession);
    verifyPresentInDatastore(modifiedSession);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) Instant(java.time.Instant) InvalidParametersException(teammates.common.exception.InvalidParametersException) Text(com.google.appengine.api.datastore.Text) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 24 with EntityDoesNotExistException

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

the class InstructorsDbTest method testUpdateInstructorByEmail.

@Test
public void testUpdateInstructorByEmail() throws Exception {
    InstructorAttributes instructorToEdit = instructorsDb.getInstructorForEmail("idOfTypicalCourse1", "instructor1@course1.tmt");
    ______TS("Success: update an instructor");
    instructorToEdit.googleId = "new-id";
    instructorToEdit.name = "New Name";
    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.updateInstructorByEmail(instructorToEdit);
    InstructorAttributes instructorUpdated = instructorsDb.getInstructorForEmail(instructorToEdit.courseId, instructorToEdit.email);
    assertEquals("new-id", instructorUpdated.googleId);
    assertEquals("New Name", instructorUpdated.name);
    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 'CoOwner' role is unchanged.
    assertFalse(instructorUpdated.hasCoownerPrivileges());
    ______TS("Failure: invalid parameters");
    instructorToEdit.googleId = "invalid id";
    instructorToEdit.name = "";
    instructorToEdit.role = "invalid role";
    try {
        instructorsDb.updateInstructorByEmail(instructorToEdit);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.GOOGLE_ID_ERROR_MESSAGE, instructorToEdit.googleId, FieldValidator.GOOGLE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.GOOGLE_ID_MAX_LENGTH) + System.lineSeparator() + getPopulatedEmptyStringErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.PERSON_NAME_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 = "newEmail@email.tmt";
    instructorToEdit.role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER;
    try {
        instructorsDb.updateInstructorByEmail(instructorToEdit);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains(EntitiesDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, e.getMessage());
    }
    ______TS("Failure: null parameters");
    try {
        instructorsDb.updateInstructorByEmail(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 25 with EntityDoesNotExistException

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

the class AccountsLogicTest method testAccountFunctions.

@Priority(-1)
@Test
public void testAccountFunctions() throws Exception {
    ______TS("test isAccountPresent");
    assertTrue(accountsLogic.isAccountPresent("idOfInstructor1OfCourse1"));
    assertTrue(accountsLogic.isAccountPresent("student1InCourse1"));
    assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
    ______TS("test isAccountAnInstructor");
    assertTrue(accountsLogic.isAccountAnInstructor("idOfInstructor1OfCourse1"));
    assertFalse(accountsLogic.isAccountAnInstructor("student1InCourse1"));
    assertFalse(accountsLogic.isAccountAnInstructor("id-does-not-exist"));
    ______TS("test getInstructorAccounts");
    for (AccountAttributes aa : accountsLogic.getInstructorAccounts()) {
        ______TS(aa.toString());
    }
    assertEquals(12, accountsLogic.getInstructorAccounts().size());
    ______TS("test updateAccount");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("idOfInstructor1OfCourse1").build();
    spa.institute = "dev";
    spa.shortName = "nam";
    AccountAttributes expectedAccount = AccountAttributes.builder().withGoogleId("idOfInstructor1OfCourse1").withName("name").withEmail("test2@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    // updates the profile
    accountsLogic.updateAccount(expectedAccount, true);
    AccountAttributes actualAccount = accountsLogic.getAccount(expectedAccount.googleId, true);
    expectedAccount.studentProfile.modifiedDate = actualAccount.studentProfile.modifiedDate;
    expectedAccount.createdAt = actualAccount.createdAt;
    assertEquals(expectedAccount.toString(), actualAccount.toString());
    // does not update the profile
    expectedAccount.studentProfile.shortName = "newNam";
    accountsLogic.updateAccount(expectedAccount);
    actualAccount = accountsLogic.getAccount(expectedAccount.googleId, true);
    // no change in the name
    assertEquals("nam", actualAccount.studentProfile.shortName);
    expectedAccount = AccountAttributes.builder().withGoogleId("id-does-not-exist").withName("name").withEmail("test2@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    try {
        accountsLogic.updateAccount(expectedAccount);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException edne) {
        AssertHelper.assertContains(AccountsDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, edne.getMessage());
    }
    ______TS("test downgradeInstructorToStudentCascade");
    accountsLogic.downgradeInstructorToStudentCascade("idOfInstructor2OfCourse1");
    assertFalse(accountsLogic.isAccountAnInstructor("idOfInstructor2OfCourse1"));
    accountsLogic.downgradeInstructorToStudentCascade("student1InCourse1");
    assertFalse(accountsLogic.isAccountAnInstructor("student1InCourse1"));
    accountsLogic.downgradeInstructorToStudentCascade("id-does-not-exist");
    assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
    ______TS("test makeAccountInstructor");
    accountsLogic.makeAccountInstructor("student2InCourse1");
    assertTrue(accountsLogic.isAccountAnInstructor("student2InCourse1"));
    accountsLogic.downgradeInstructorToStudentCascade("student2InCourse1");
    accountsLogic.makeAccountInstructor("id-does-not-exist");
    assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test) Priority(teammates.test.driver.Priority)

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