use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class FeedbackSessionsLogicTest method testPublishUnpublishFeedbackSession.
private void testPublishUnpublishFeedbackSession() throws Exception {
______TS("success: publish");
FeedbackSessionAttributes sessionUnderTest = dataBundle.feedbackSessions.get("session1InCourse1");
// set as manual publish
sessionUnderTest.setResultsVisibleFromTime(Const.TIME_REPRESENTS_LATER);
fsLogic.updateFeedbackSession(sessionUnderTest);
fsLogic.publishFeedbackSession(sessionUnderTest);
// Set real time of publishing
FeedbackSessionAttributes sessionPublished = fsLogic.getFeedbackSession(sessionUnderTest.getFeedbackSessionName(), sessionUnderTest.getCourseId());
sessionUnderTest.setResultsVisibleFromTime(sessionPublished.getResultsVisibleFromTime());
assertEquals(sessionUnderTest.toString(), sessionPublished.toString());
______TS("failure: already published");
try {
fsLogic.publishFeedbackSession(sessionUnderTest);
signalFailureToDetectException("Did not catch exception signalling that session is already published.");
} catch (InvalidParametersException e) {
assertEquals("Error publishing feedback session: Session has already been published.", e.getMessage());
}
______TS("success: unpublish");
fsLogic.unpublishFeedbackSession(sessionUnderTest);
sessionUnderTest.setResultsVisibleFromTime(Const.TIME_REPRESENTS_LATER);
assertEquals(sessionUnderTest.toString(), fsLogic.getFeedbackSession(sessionUnderTest.getFeedbackSessionName(), sessionUnderTest.getCourseId()).toString());
______TS("failure: not published");
try {
fsLogic.unpublishFeedbackSession(sessionUnderTest);
signalFailureToDetectException("Did not catch exception signalling that session is not published.");
} catch (InvalidParametersException e) {
assertEquals("Error unpublishing feedback session: Session has already been unpublished.", e.getMessage());
}
______TS("failure: private session");
sessionUnderTest = dataBundle.feedbackSessions.get("session1InCourse2");
try {
fsLogic.publishFeedbackSession(sessionUnderTest);
signalFailureToDetectException("Did not catch exception signalling that private session can't " + "be published.");
} catch (InvalidParametersException e) {
assertEquals("Error publishing feedback session: Session is private and can't be published.", e.getMessage());
}
try {
fsLogic.unpublishFeedbackSession(sessionUnderTest);
signalFailureToDetectException("Did not catch exception signalling that private session should " + "not be published");
} catch (InvalidParametersException e) {
assertEquals("Error unpublishing feedback session: Session is private and can't be unpublished.", e.getMessage());
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorsLogicTest method testAddInstructor.
private void testAddInstructor() throws Exception {
______TS("success: add an instructor");
String courseId = "test-course";
String name = "New Instructor";
String email = "ILT.instr@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 instr = InstructorAttributes.builder(null, courseId, name, email).withRole(role).withDisplayedName(displayedName).withPrivileges(privileges).build();
instructorsLogic.createInstructor(instr);
verifyPresentInDatastore(instr);
______TS("failure: instructor already exists");
try {
instructorsLogic.createInstructor(instr);
signalFailureToDetectException();
} catch (EntityAlreadyExistsException e) {
AssertHelper.assertContains("Trying to create a Instructor that exists", e.getMessage());
}
instructorsLogic.deleteInstructorCascade(instr.courseId, instr.email);
______TS("failure: invalid parameter");
instr.email = "invalidEmail.tmt";
String expectedError = "\"" + instr.email + "\" is not acceptable to TEAMMATES as a/an email " + "because it is not in the correct format. An email address contains " + "some text followed by one '@' sign followed by some more text. " + "It cannot be longer than 254 characters, cannot be empty and " + "cannot contain spaces.";
try {
instructorsLogic.createInstructor(instr);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
assertEquals(expectedError, e.getMessage());
}
______TS("failure: null parameters");
try {
instructorsLogic.createInstructor(null);
signalFailureToDetectException();
} catch (AssertionError e) {
AssertHelper.assertContains("Supplied parameter was null", e.getMessage());
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class StudentsLogicTest method testupdateStudentCascadeWithoutDocument.
private void testupdateStudentCascadeWithoutDocument() throws Exception {
______TS("typical edit");
StudentAttributes student4InCourse1 = dataBundle.students.get("student4InCourse1");
verifyPresentInDatastore(student4InCourse1);
String originalEmail = student4InCourse1.email;
student4InCourse1 = studentsLogic.getStudentForEmail(student4InCourse1.course, student4InCourse1.email);
student4InCourse1.name = student4InCourse1.name + "y";
student4InCourse1.googleId = student4InCourse1.googleId + "y";
student4InCourse1.comments = student4InCourse1.comments + "y";
student4InCourse1.email = student4InCourse1.email + "y";
student4InCourse1.section = "Section 2";
// move to a different team
student4InCourse1.team = "Team 1.2";
studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, student4InCourse1);
StudentAttributes updatedStudent4InCourse1 = studentsLogic.getStudentForEmail(student4InCourse1.course, student4InCourse1.email);
assertFalse(student4InCourse1.getUpdatedAt().equals(updatedStudent4InCourse1.getUpdatedAt()));
______TS("check for KeepExistingPolicy : change email only");
originalEmail = student4InCourse1.email;
String newEmail = student4InCourse1.email + "y";
student4InCourse1.email = newEmail;
// create an empty student and then copy course and email attributes
StudentAttributes copyOfStudent1 = StudentAttributes.builder(student4InCourse1.course, student4InCourse1.name, newEmail).build();
student4InCourse1.googleId = "";
student4InCourse1.section = "None";
studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, copyOfStudent1);
verifyPresentInDatastore(student4InCourse1);
______TS("check for KeepExistingPolicy : change nothing");
originalEmail = student4InCourse1.email;
copyOfStudent1.email = null;
studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, copyOfStudent1);
verifyPresentInDatastore(copyOfStudent1);
______TS("non-existent student");
try {
studentsLogic.updateStudentCascadeWithoutDocument("non-existent@email", student4InCourse1);
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
assertEquals(StudentsDb.ERROR_UPDATE_NON_EXISTENT_STUDENT + student4InCourse1.course + "/" + "non-existent@email", e.getMessage());
}
______TS("check for InvalidParameters");
copyOfStudent1.email = "invalid email";
try {
studentsLogic.updateStudentCascadeWithoutDocument(originalEmail, copyOfStudent1);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains(FieldValidator.REASON_INCORRECT_FORMAT, e.getMessage());
}
// delete student from db
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class AccountsDbTest method testCreateAccount.
@Test
public void testCreateAccount() throws Exception {
______TS("typical success case (legacy data)");
AccountAttributes a = AccountAttributes.builder().withGoogleId("test.account").withName("Test account Name").withIsInstructor(false).withEmail("fresh-account@email.com").withInstitute("TEAMMATES Test Institute 1").build();
a.studentProfile = null;
accountsDb.createAccount(a);
______TS("success case: duplicate account");
StudentProfileAttributes spa = StudentProfileAttributes.builder(a.googleId).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";
spa.googleId = a.googleId;
a.studentProfile = spa;
accountsDb.createAccount(a);
______TS("test persistence of latest entry");
AccountAttributes accountDataTest = accountsDb.getAccount(a.googleId, true);
assertEquals(spa.shortName, accountDataTest.studentProfile.shortName);
assertEquals(spa.gender, accountDataTest.studentProfile.gender);
assertEquals(spa.institute, accountDataTest.studentProfile.institute);
assertEquals(a.institute, accountDataTest.institute);
assertEquals(spa.email, accountDataTest.studentProfile.email);
assertFalse(accountDataTest.isInstructor);
// Change a field
accountDataTest.isInstructor = true;
accountDataTest.studentProfile.gender = Const.GenderTypes.FEMALE;
accountsDb.createAccount(accountDataTest);
// Re-retrieve
accountDataTest = accountsDb.getAccount(a.googleId, true);
assertTrue(accountDataTest.isInstructor);
assertEquals(Const.GenderTypes.FEMALE, accountDataTest.studentProfile.gender);
accountsDb.deleteAccount(a.googleId);
// Should we not allow empty fields?
______TS("failure case: invalid parameter");
a.email = "invalid email";
try {
accountsDb.createAccount(a);
signalFailureToDetectException(" - InvalidParametersException");
} catch (InvalidParametersException e) {
AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, "invalid email", FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH), e.getMessage());
}
______TS("failure: null parameter");
try {
accountsDb.createAccount(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 CoursesDbTest method testUpdateCourse.
@Test
public void testUpdateCourse() throws Exception {
______TS("Failure: null paramater");
try {
coursesDb.updateCourse(null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
______TS("Failure: update course with invalid parameters");
CourseAttributes invalidCourse = CourseAttributes.builder("", "", ZoneId.of("UTC")).build();
try {
coursesDb.updateCourse(invalidCourse);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
AssertHelper.assertContains("The field 'course ID' is empty", e.getMessage());
AssertHelper.assertContains("The field 'course name' is empty", e.getMessage());
}
______TS("fail: non-exisitng course");
CourseAttributes nonExistentCourse = CourseAttributes.builder("CDbT.non-exist-course", "Non existing course", ZoneId.of("UTC")).build();
try {
coursesDb.updateCourse(nonExistentCourse);
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
assertEquals(CoursesDb.ERROR_UPDATE_NON_EXISTENT_COURSE, e.getMessage());
}
______TS("success: typical case");
CourseAttributes c = createNewCourse();
CourseAttributes updatedCourse = CourseAttributes.builder(c.getId(), c.getName() + " updated", ZoneId.of("UTC")).build();
coursesDb.updateCourse(updatedCourse);
CourseAttributes retrieved = coursesDb.getCourse(c.getId());
assertEquals(c.getName() + " updated", retrieved.getName());
}
Aggregations