Search in sources :

Example 21 with InvalidParametersException

use of teammates.common.exception.InvalidParametersException 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 InvalidParametersException

use of teammates.common.exception.InvalidParametersException 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 InvalidParametersException

use of teammates.common.exception.InvalidParametersException 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 InvalidParametersException

use of teammates.common.exception.InvalidParametersException 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 InvalidParametersException

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

the class AccountsLogicTest method testCreateAccount.

@Test
public void testCreateAccount() throws Exception {
    ______TS("typical success case");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("id").build();
    spa.shortName = "test acc na";
    spa.email = "test@personal.com";
    spa.gender = Const.GenderTypes.MALE;
    spa.nationality = "American";
    spa.institute = "institute";
    spa.moreInfo = "this is more info";
    AccountAttributes accountToCreate = AccountAttributes.builder().withGoogleId("id").withName("name").withEmail("test@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    accountsLogic.createAccount(accountToCreate);
    verifyPresentInDatastore(accountToCreate);
    accountsLogic.deleteAccountCascade("id");
    ______TS("invalid parameters exception case");
    accountToCreate = AccountAttributes.builder().withGoogleId("").withName("name").withEmail("test@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    try {
        accountsLogic.createAccount(accountToCreate);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        ignoreExpectedException();
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Aggregations

InvalidParametersException (teammates.common.exception.InvalidParametersException)83 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)37 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 StatusMessage (teammates.common.util.StatusMessage)21 Test (org.testng.annotations.Test)19 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)19 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)13 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)12 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 Text (com.google.appengine.api.datastore.Text)8 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)8 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)6 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)6 ArrayList (java.util.ArrayList)5 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)5 VoidWork (com.googlecode.objectify.VoidWork)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 PageData (teammates.ui.pagedata.PageData)4 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)3