Search in sources :

Example 36 with InvalidParametersException

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());
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException)

Example 37 with InvalidParametersException

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());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 38 with InvalidParametersException

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
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 39 with InvalidParametersException

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());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 40 with InvalidParametersException

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());
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) 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