Search in sources :

Example 6 with AccountAttributes

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

the class AccountAttributesTest method testGetIdentificationString.

@Test
public void testGetIdentificationString() {
    AccountAttributes account = createValidAccountAttributesObject();
    assertEquals(account.googleId, account.getIdentificationString());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 7 with AccountAttributes

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

the class AccountAttributesTest method testSanitizeForSaving.

@Test
public void testSanitizeForSaving() {
    AccountAttributes actualAccount = createAccountAttributesToSanitize();
    AccountAttributes expectedAccount = createAccountAttributesToSanitize();
    actualAccount.sanitizeForSaving();
    assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.googleId), actualAccount.googleId);
    assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.name), actualAccount.name);
    assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.email), actualAccount.email);
    assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.institute), actualAccount.institute);
    expectedAccount.studentProfile.sanitizeForSaving();
    assertEquals(expectedAccount.studentProfile.toString(), actualAccount.studentProfile.toString());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 8 with AccountAttributes

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

the class AccountAttributesTest method testGetInvalidStateInfo.

// TODO: test toString() method
@Test
public void testGetInvalidStateInfo() throws Exception {
    ______TS("valid account");
    AccountAttributes account = createValidAccountAttributesObject();
    assertTrue("all valid values", account.isValid());
    ______TS("null studentProfile");
    account.studentProfile = null;
    try {
        account.isValid();
        signalFailureToDetectException(" - AssertionError");
    } catch (AssertionError ae) {
        assertEquals("Non-null value expected for studentProfile", ae.getMessage());
    }
    ______TS("invalid account");
    account = createInvalidAccountAttributesObject();
    String expectedError = 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.GOOGLE_ID_ERROR_MESSAGE, "invalid google id", FieldValidator.GOOGLE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.GOOGLE_ID_MAX_LENGTH) + System.lineSeparator() + getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, "invalid@email@com", FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH) + System.lineSeparator() + getPopulatedErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FieldValidator.INSTITUTE_NAME_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.INSTITUTE_NAME_MAX_LENGTH);
    assertFalse("all valid values", account.isValid());
    assertEquals("all valid values", expectedError, StringHelper.toString(account.getInvalidityInfo()));
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 9 with AccountAttributes

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

the class AccountAttributesTest method testBuilderWithDefaultValues.

@Test
public void testBuilderWithDefaultValues() {
    AccountAttributes observedAccountAttributes = AccountAttributes.builder().build();
    assertNull(observedAccountAttributes.createdAt);
    assertNull(observedAccountAttributes.getEmail());
    assertNull(observedAccountAttributes.getGoogleId());
    assertNull(observedAccountAttributes.getInstitute());
    assertFalse(observedAccountAttributes.isInstructor());
    assertNull(observedAccountAttributes.getName());
    assertNull(observedAccountAttributes.studentProfile);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 10 with AccountAttributes

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

the class AccountAttributesTest method testToEntity.

@Override
@Test
public void testToEntity() {
    AccountAttributes account = createValidAccountAttributesObject();
    Account expectedAccount = new Account(account.googleId, account.name, account.isInstructor, account.email, account.institute, account.studentProfile.toEntity());
    Account actualAccount = account.toEntity();
    assertEquals(expectedAccount.getGoogleId(), actualAccount.getGoogleId());
    assertEquals(expectedAccount.getName(), actualAccount.getName());
    assertEquals(expectedAccount.getEmail(), actualAccount.getEmail());
    assertEquals(expectedAccount.getInstitute(), actualAccount.getInstitute());
    assertEquals(expectedAccount.isInstructor(), actualAccount.isInstructor());
    ProfilesDb profilesDb = new ProfilesDb();
    profilesDb.saveEntity(account.studentProfile.toEntity());
    String expectedProfile = StudentProfileAttributes.valueOf(expectedAccount.getStudentProfile()).toString();
    String actualProfile = StudentProfileAttributes.valueOf(actualAccount.getStudentProfile()).toString();
    assertEquals(expectedProfile, actualProfile);
    profilesDb.deleteEntity(account.studentProfile);
}
Also used : Account(teammates.storage.entity.Account) ProfilesDb(teammates.storage.api.ProfilesDb) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

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