Search in sources :

Example 76 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class InstructorCourseJoinAuthenticatedActionTest method testExecuteAndPostProcess.

@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    InstructorsDb instrDb = new InstructorsDb();
    instructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    ______TS("Failure: Invalid key");
    String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
    InstructorCourseJoinAuthenticatedAction joinAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, true, "idOfInstructor1OfCourse1", invalidEncryptedKey), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You have used an invalid join link: " + Const.ActionURIs.INSTRUCTOR_COURSE_JOIN + "?key=" + invalidEncryptedKey, redirectResult.getStatusMessage());
    String expectedLogSegment = "Servlet Action Failure : You have used an invalid join link: " + Const.ActionURIs.INSTRUCTOR_COURSE_JOIN + "?key=" + invalidEncryptedKey + "<br><br>Action Instructor Joins Course<br>" + "Google ID: idOfInstructor1OfCourse1<br>Key : invalidKey";
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure: Instructor already registered");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, instructor.courseId, true, "idOfInstructor1OfCourse1", StringHelper.encrypt(instructor.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(instructor.googleId + " has already joined this course", redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : " + instructor.googleId + " has already joined this course" + "<br><br>Action Instructor Joins Course<br>Google ID: " + instructor.googleId + "<br>Key : " + instructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure: the current key has been registered by another account");
    InstructorAttributes instructor2 = typicalBundle.instructors.get("instructor2OfCourse1");
    instructor2 = instrDb.getInstructorForGoogleId(instructor2.courseId, instructor2.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor2.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, instructor2.courseId, true, "idOfInstructor1OfCourse1", StringHelper.encrypt(instructor2.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    AssertHelper.assertContains("The join link used belongs to a different user", redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : The join link used belongs to a different user";
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Typical case: authenticate for new instructor with corresponding key");
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAAT.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAAT.instr";
    AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    gaeSimulation.loginUser(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, "idOfTypicalCourse1", false, "ICJAAT.instr", StringHelper.encrypt(newInstructor.key)), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("", redirectResult.getStatusMessage());
    InstructorAttributes retrievedInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    assertEquals(instructor.googleId, retrievedInstructor.googleId);
    expectedLogSegment = "Action Instructor Joins Course<br>Google ID: " + instructor.googleId + "<br>Key : " + newInstructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure case: the current unused key is not for this account ");
    String currentLoginId = instructor.googleId;
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor 2", "ICJAAT2.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAAT2.instr";
    newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, "idOfTypicalCourse1", true, "ICJAAT.instr", StringHelper.encrypt(newInstructor.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, currentLoginId), redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : " + String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, currentLoginId) + "<br><br>Action Instructor Joins Course<br>Google ID: " + currentLoginId + "<br>Key : " + newInstructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
}
Also used : InstructorCourseJoinAuthenticatedAction(teammates.ui.controller.InstructorCourseJoinAuthenticatedAction) InstructorsDb(teammates.storage.api.InstructorsDb) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 77 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class BaseTestCaseWithDatastoreAccess method verifyEquals.

private void verifyEquals(EntityAttributes<?> expected, EntityAttributes<?> actual) {
    if (expected instanceof AccountAttributes) {
        AccountAttributes expectedAccount = ((AccountAttributes) expected).getCopy();
        AccountAttributes actualAccount = (AccountAttributes) actual;
        equalizeIrrelevantData(expectedAccount, actualAccount);
        assertEquals(JsonUtils.toJson(expectedAccount), JsonUtils.toJson(actualAccount));
    } else if (expected instanceof CourseAttributes) {
        CourseAttributes expectedCourse = (CourseAttributes) expected;
        CourseAttributes actualCourse = (CourseAttributes) actual;
        equalizeIrrelevantData(expectedCourse, actualCourse);
        assertEquals(JsonUtils.toJson(expectedCourse), JsonUtils.toJson(actualCourse));
    } else if (expected instanceof FeedbackQuestionAttributes) {
        FeedbackQuestionAttributes expectedFq = (FeedbackQuestionAttributes) expected;
        FeedbackQuestionAttributes actualFq = (FeedbackQuestionAttributes) actual;
        equalizeIrrelevantData(expectedFq, actualFq);
        assertEquals(JsonUtils.toJson(expectedFq), JsonUtils.toJson(actualFq));
    } else if (expected instanceof FeedbackResponseCommentAttributes) {
        FeedbackResponseCommentAttributes expectedFrc = (FeedbackResponseCommentAttributes) expected;
        FeedbackResponseCommentAttributes actualFrc = (FeedbackResponseCommentAttributes) actual;
        assertEquals(expectedFrc.courseId, actualFrc.courseId);
        assertEquals(expectedFrc.giverEmail, actualFrc.giverEmail);
        assertEquals(expectedFrc.feedbackSessionName, actualFrc.feedbackSessionName);
        assertEquals(expectedFrc.commentText, actualFrc.commentText);
    } else if (expected instanceof FeedbackResponseAttributes) {
        FeedbackResponseAttributes expectedFr = (FeedbackResponseAttributes) expected;
        FeedbackResponseAttributes actualFr = (FeedbackResponseAttributes) actual;
        equalizeIrrelevantData(expectedFr, actualFr);
        assertEquals(JsonUtils.toJson(expectedFr), JsonUtils.toJson(actualFr));
    } else if (expected instanceof FeedbackSessionAttributes) {
        FeedbackSessionAttributes expectedFs = ((FeedbackSessionAttributes) expected).getCopy();
        FeedbackSessionAttributes actualFs = (FeedbackSessionAttributes) actual;
        equalizeIrrelevantData(expectedFs, actualFs);
        assertEquals(JsonUtils.toJson(expectedFs), JsonUtils.toJson(actualFs));
    } else if (expected instanceof InstructorAttributes) {
        InstructorAttributes expectedInstructor = ((InstructorAttributes) expected).getCopy();
        InstructorAttributes actualInstructor = (InstructorAttributes) actual;
        equalizeIrrelevantData(expectedInstructor, actualInstructor);
        assertTrue(expectedInstructor.isEqualToAnotherInstructor(actualInstructor));
    } else if (expected instanceof StudentAttributes) {
        StudentAttributes expectedStudent = ((StudentAttributes) expected).getCopy();
        StudentAttributes actualStudent = (StudentAttributes) actual;
        equalizeIrrelevantData(expectedStudent, actualStudent);
        assertEquals(JsonUtils.toJson(expectedStudent), JsonUtils.toJson(actualStudent));
    } else {
        throw new RuntimeException("Unknown entity type!");
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 78 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class Logic method createAccount.

/**
 * Creates a new Account based on given values. If a profile is not given,
 * a default empty profile is created for the user<br>
 * Preconditions: <br>
 * * All parameters are non-null.
 */
public void createAccount(String googleId, String name, boolean isInstructor, String email, String institute, StudentProfileAttributes studentProfileParam) throws InvalidParametersException {
    Assumption.assertNotNull(googleId);
    Assumption.assertNotNull(name);
    Assumption.assertNotNull(isInstructor);
    Assumption.assertNotNull(email);
    Assumption.assertNotNull(institute);
    StudentProfileAttributes studentProfile = studentProfileParam;
    if (studentProfile == null) {
        studentProfile = StudentProfileAttributes.builder(googleId).build();
    }
    AccountAttributes accountToAdd = AccountAttributes.builder().withGoogleId(googleId).withName(name).withEmail(email).withInstitute(institute).withIsInstructor(isInstructor).withStudentProfileAttributes(studentProfile).build();
    accountsLogic.createAccount(accountToAdd);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 79 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class BackDoorLogic method editAccountAsJson.

public void editAccountAsJson(String newValues) throws InvalidParametersException, EntityDoesNotExistException {
    AccountAttributes account = JsonUtils.fromJson(newValues, AccountAttributes.class);
    updateAccount(account);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes)

Example 80 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.

the class AccountsLogic method getCourseInstitute.

public String getCourseInstitute(String courseId) {
    CourseAttributes cd = coursesLogic.getCourse(courseId);
    Assumption.assertNotNull("Trying to getCourseInstitute for inexistent course with id " + courseId, cd);
    List<InstructorAttributes> instructorList = instructorsLogic.getInstructorsForCourse(cd.getId());
    Assumption.assertTrue("Course has no instructors: " + cd.getId(), !instructorList.isEmpty());
    // Retrieve institute field from one of the instructors of the course
    String institute = "";
    for (int i = 0; i < instructorList.size(); i++) {
        String instructorGoogleId = instructorList.get(i).googleId;
        if (instructorGoogleId == null) {
            continue;
        }
        AccountAttributes instructorAcc = accountsDb.getAccount(instructorGoogleId);
        if (instructorAcc != null) {
            institute = instructorAcc.institute;
            break;
        }
    }
    Assumption.assertNotEmpty("No institute found for the course", institute);
    return institute;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Aggregations

AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)84 Test (org.testng.annotations.Test)53 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)28 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 ArrayList (java.util.ArrayList)13 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)11 HashMap (java.util.HashMap)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InvalidParametersException (teammates.common.exception.InvalidParametersException)6 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)5 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)4 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 EmailWrapper (teammates.common.util.EmailWrapper)4 RedirectResult (teammates.ui.controller.RedirectResult)4 List (java.util.List)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 AccountsDb (teammates.storage.api.AccountsDb)3 Account (teammates.storage.entity.Account)3 ShowPageResult (teammates.ui.controller.ShowPageResult)3