Search in sources :

Example 11 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorPrivilegesTest method testIsAllowedForPrivilege.

@Test
public void testIsAllowedForPrivilege() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    assertTrue(privileges.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    String sectionId = "sectionId";
    assertTrue(privileges.isAllowedForPrivilege(sectionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    privileges.updatePrivilege(sectionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    assertFalse(privileges.isAllowedForPrivilege(sectionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertFalse(privileges.isAllowedForPrivilege(sectionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    String sessionId = "sessionId";
    String sessionId2 = "sessionId2";
    assertFalse(privileges.isAllowedForPrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    privileges.addSessionWithDefaultPrivileges(sectionId, sessionId2);
    assertFalse(privileges.isAllowedForPrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    privileges.updatePrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, true);
    assertTrue(privileges.isAllowedForPrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertFalse(privileges.isAllowedForPrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 12 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges 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 13 with InstructorPrivileges

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

Example 14 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges 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());
    }
}
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 15 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorAttributesTest method testValueOf.

@Test
public void testValueOf() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder("valid.google.id", "valid-course-id", "valid name", "valid@email.com").withDisplayedName(InstructorAttributes.DEFAULT_DISPLAY_NAME).withRole(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER).withPrivileges(privileges).build();
    Instructor entity = instructor.toEntity();
    InstructorAttributes instructor1 = InstructorAttributes.valueOf(entity);
    assertEquals(instructor.googleId, instructor1.googleId);
    assertEquals(instructor.courseId, instructor1.courseId);
    assertEquals(instructor.name, instructor1.name);
    assertEquals(instructor.email, instructor1.email);
    assertEquals(instructor.role, instructor1.role);
    assertEquals(instructor.displayedName, instructor1.displayedName);
    assertEquals(instructor.privileges, instructor1.privileges);
    entity.setRole(null);
    entity.setDisplayedName(null);
    entity.setInstructorPrivilegeAsText(null);
    InstructorAttributes instructor2 = InstructorAttributes.valueOf(entity);
    assertEquals(instructor.googleId, instructor2.googleId);
    assertEquals(instructor.courseId, instructor2.courseId);
    assertEquals(instructor.name, instructor2.name);
    assertEquals(instructor.email, instructor2.email);
    // default values for these
    assertEquals(instructor.role, instructor2.role);
    assertEquals(instructor.displayedName, instructor2.displayedName);
    assertEquals(instructor.privileges, instructor2.privileges);
}
Also used : Instructor(teammates.storage.entity.Instructor) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)28 Test (org.testng.annotations.Test)21 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)14 InvalidParametersException (teammates.common.exception.InvalidParametersException)5 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)3 LinkedHashMap (java.util.LinkedHashMap)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 Instructor (teammates.storage.entity.Instructor)2 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 InstructorCoursesPage (teammates.test.pageobjects.InstructorCoursesPage)1