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());
}
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());
}
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()));
}
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);
}
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);
}
Aggregations