use of teammates.common.exception.InvalidParametersException 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());
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class FeedbackSessionsDbTest method testCreateDeleteFeedbackSession.
@Test
public void testCreateDeleteFeedbackSession() throws Exception {
______TS("standard success case");
FeedbackSessionAttributes fsa = getNewFeedbackSession();
fsDb.createEntity(fsa);
verifyPresentInDatastore(fsa);
______TS("duplicate");
try {
fsDb.createEntity(fsa);
signalFailureToDetectException();
} catch (EntityAlreadyExistsException e) {
AssertHelper.assertContains(String.format(FeedbackSessionsDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, fsa.getEntityTypeAsString()) + fsa.getIdentificationString(), e.getMessage());
}
fsDb.deleteEntity(fsa);
verifyAbsentInDatastore(fsa);
______TS("null params");
try {
fsDb.createEntity(null);
signalFailureToDetectException();
} catch (AssertionError e) {
AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
}
______TS("invalid params");
try {
fsa.setStartTime(Instant.now());
fsDb.createEntity(fsa);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
// start time is now after end time
AssertHelper.assertContains("start time", e.getLocalizedMessage());
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorsDbTest method testCreateInstructor.
@Test
public void testCreateInstructor() throws Exception {
______TS("Success: create an instructor");
String googleId = "valid.fresh.id";
String courseId = "valid.course.Id";
String name = "valid.name";
String email = "valid@email.tmt";
String role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
String displayedName = InstructorAttributes.DEFAULT_DISPLAY_NAME;
InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
InstructorAttributes i = InstructorAttributes.builder(googleId, courseId, name, email).withRole(role).withDisplayedName(displayedName).withPrivileges(privileges).build();
instructorsDb.deleteEntity(i);
instructorsDb.createEntity(i);
verifyPresentInDatastore(i);
______TS("Failure: create a duplicate instructor");
try {
instructorsDb.createEntity(i);
signalFailureToDetectException();
} catch (EntityAlreadyExistsException e) {
AssertHelper.assertContains(String.format(InstructorsDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, "Instructor"), e.getMessage());
}
______TS("Failure: create an instructor with invalid parameters");
i.googleId = "invalid id with spaces";
try {
instructorsDb.createEntity(i);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.GOOGLE_ID_ERROR_MESSAGE, i.googleId, FieldValidator.GOOGLE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.GOOGLE_ID_MAX_LENGTH), e.getMessage());
}
i.googleId = "valid.fresh.id";
i.email = "invalid.email.tmt";
i.role = "role invalid";
try {
instructorsDb.createEntity(i);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, i.email, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH) + System.lineSeparator() + String.format(FieldValidator.ROLE_ERROR_MESSAGE, i.role), e.getMessage());
}
______TS("Failure: null parameters");
try {
instructorsDb.createEntity(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 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());
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class AccountsLogicTest method testJoinCourseForStudent.
@Test
public void testJoinCourseForStudent() throws Exception {
String correctStudentId = "correctStudentId";
String courseId = "idOfTypicalCourse1";
String originalEmail = "original@email.com";
// Create correct student with original@email.com
StudentAttributes studentData = StudentAttributes.builder(courseId, "name", originalEmail).withSection("sectionName").withTeam("teamName").withComments("").build();
studentsLogic.createStudentCascadeWithoutDocument(studentData);
studentData = StudentsLogic.inst().getStudentForEmail(courseId, originalEmail);
verifyPresentInDatastore(studentData);
______TS("failure: wrong key");
try {
accountsLogic.joinCourseForStudent(StringHelper.encrypt("wrongkey"), correctStudentId);
signalFailureToDetectException();
} catch (JoinCourseException e) {
assertEquals("You have used an invalid join link: %s", e.getMessage());
}
______TS("failure: invalid parameters");
try {
accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), "wrong student");
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains(FieldValidator.REASON_INCORRECT_FORMAT, e.getMessage());
}
______TS("failure: googleID belongs to an existing student in the course");
String existingId = "AccLogicT.existing.studentId";
StudentAttributes existingStudent = StudentAttributes.builder(courseId, "name", "differentEmail@email.com").withSection("sectionName").withTeam("teamName").withComments("").withGoogleId(existingId).build();
studentsLogic.createStudentCascadeWithoutDocument(existingStudent);
try {
accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), existingId);
signalFailureToDetectException();
} catch (JoinCourseException e) {
assertEquals(String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, existingId), e.getMessage());
}
______TS("success: without encryption and account already exists");
StudentProfileAttributes spa = StudentProfileAttributes.builder(correctStudentId).withInstitute("TEAMMATES Test Institute 1").build();
AccountAttributes accountData = AccountAttributes.builder().withGoogleId(correctStudentId).withName("nameABC").withEmail("real@gmail.com").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build();
accountsLogic.createAccount(accountData);
accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), correctStudentId);
studentData.googleId = accountData.googleId;
verifyPresentInDatastore(studentData);
assertEquals(correctStudentId, logic.getStudentForEmail(studentData.course, studentData.email).googleId);
______TS("failure: already joined");
try {
accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), correctStudentId);
signalFailureToDetectException();
} catch (JoinCourseException e) {
assertEquals("You (" + correctStudentId + ") have already joined this course", e.getMessage());
}
______TS("failure: valid key belongs to a different user");
try {
accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), "wrongstudent");
signalFailureToDetectException();
} catch (JoinCourseException e) {
assertEquals("The join link used belongs to a different user whose " + "Google ID is corre..dentId (only part of the Google ID is " + "shown to protect privacy). If that Google ID is owned by you, " + "please logout and re-login using that Google account. " + "If it doesn’t belong to you, please " + "<a href=\"mailto:" + Config.SUPPORT_EMAIL + "?" + "body=Your name:%0AYour course:%0AYour university:\">" + "contact us</a> so that we can investigate.", e.getMessage());
}
______TS("success: with encryption and new account to be created");
logic.deleteAccount(correctStudentId);
originalEmail = "email2@gmail.com";
studentData = StudentAttributes.builder(courseId, "name", originalEmail).withSection("sectionName").withTeam("teamName").withComments("").build();
studentsLogic.createStudentCascadeWithoutDocument(studentData);
studentData = StudentsLogic.inst().getStudentForEmail(courseId, originalEmail);
String encryptedKey = StringHelper.encrypt(studentData.key);
accountsLogic.joinCourseForStudent(encryptedKey, correctStudentId);
studentData.googleId = correctStudentId;
verifyPresentInDatastore(studentData);
assertEquals(correctStudentId, logic.getStudentForEmail(studentData.course, studentData.email).googleId);
// check that we have the corresponding new account created.
accountData.googleId = correctStudentId;
accountData.email = originalEmail;
accountData.name = "name";
accountData.isInstructor = false;
verifyPresentInDatastore(accountData);
______TS("success: join course as student does not revoke instructor status");
// promote account to instructor
accountsLogic.makeAccountInstructor(correctStudentId);
// make the student 'unregistered' again
studentData.googleId = "";
studentsLogic.updateStudentCascadeWithoutDocument(studentData.email, studentData);
assertEquals("", logic.getStudentForEmail(studentData.course, studentData.email).googleId);
// rejoin
logic.joinCourseForStudent(encryptedKey, correctStudentId);
assertEquals(correctStudentId, logic.getStudentForEmail(studentData.course, studentData.email).googleId);
// check if still instructor
assertTrue(logic.isInstructor(correctStudentId));
accountsLogic.deleteAccountCascade(correctStudentId);
accountsLogic.deleteAccountCascade(existingId);
}
Aggregations