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());
}
}
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());
}
}
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);
}
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());
}
}
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();
}
}
Aggregations