use of org.killbill.billing.account.api.DefaultAccountEmail in project killbill by killbill.
the class TestAccountDao method testAddRemoveAccountEmail.
@Test(groups = "slow", description = "Test Account DAO: add and remove email")
public void testAddRemoveAccountEmail() throws AccountApiException {
final UUID accountId = UUID.randomUUID();
// Add a new e-mail
final AccountEmail email = new DefaultAccountEmail(accountId, "test@gmail.com");
accountDao.addEmail(new AccountEmailModelDao(email), internalCallContext);
final List<AccountEmailModelDao> accountEmails = accountDao.getEmailsByAccountId(accountId, internalCallContext);
Assert.assertEquals(accountEmails.size(), 1);
Assert.assertEquals(accountEmails.get(0).getAccountId(), accountId);
Assert.assertEquals(accountEmails.get(0).getEmail(), email.getEmail());
// Verify audits
final List<AuditLog> auditLogsForAccountEmail = auditDao.getAuditLogsForId(TableName.ACCOUNT_EMAIL, email.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogsForAccountEmail.size(), 1);
Assert.assertEquals(auditLogsForAccountEmail.get(0).getChangeType(), ChangeType.INSERT);
// Delete the e-mail
accountDao.removeEmail(new AccountEmailModelDao(email), internalCallContext);
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 0);
}
use of org.killbill.billing.account.api.DefaultAccountEmail in project killbill by killbill.
the class TestDefaultAccountUserApiWithMocks method testAddEmail.
@Test(groups = "fast", description = "Test ability to add email to Account")
public void testAddEmail() throws Exception {
final UUID accountId = UUID.randomUUID();
// Verify the initial state
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 0);
// Add the first email
final String emailAddress1 = UUID.randomUUID().toString();
final AccountEmail email1 = new DefaultAccountEmail(accountId, emailAddress1);
accountUserApi.addEmail(accountId, email1, callContext);
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 1);
// Add a second one
final String emailAddress2 = UUID.randomUUID().toString();
final AccountEmail email2 = new DefaultAccountEmail(accountId, emailAddress2);
accountUserApi.addEmail(accountId, email2, callContext);
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 2);
// Remove the first second one
accountUserApi.removeEmail(accountId, email1, callContext);
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, tenantContext).size(), 1);
}
use of org.killbill.billing.account.api.DefaultAccountEmail in project killbill by killbill.
the class TestAccountDao method testAddAndRemoveMultipleAccountEmails.
@Test(groups = "slow", description = "Test Account DAO: add and remove multiple emails")
public void testAddAndRemoveMultipleAccountEmails() throws AccountApiException {
final UUID accountId = UUID.randomUUID();
final String email1 = UUID.randomUUID().toString();
final String email2 = UUID.randomUUID().toString();
// Verify the original state
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 0);
// Add a new e-mail
final AccountEmail accountEmail1 = new DefaultAccountEmail(accountId, email1);
accountDao.addEmail(new AccountEmailModelDao(accountEmail1), internalCallContext);
final List<AccountEmailModelDao> firstEmails = accountDao.getEmailsByAccountId(accountId, internalCallContext);
Assert.assertEquals(firstEmails.size(), 1);
Assert.assertEquals(firstEmails.get(0).getAccountId(), accountId);
Assert.assertEquals(firstEmails.get(0).getEmail(), email1);
// Add a second e-mail
final AccountEmail accountEmail2 = new DefaultAccountEmail(accountId, email2);
accountDao.addEmail(new AccountEmailModelDao(accountEmail2), internalCallContext);
final List<AccountEmailModelDao> secondEmails = accountDao.getEmailsByAccountId(accountId, internalCallContext);
Assert.assertEquals(secondEmails.size(), 2);
Assert.assertTrue(secondEmails.get(0).getAccountId().equals(accountId));
Assert.assertTrue(secondEmails.get(1).getAccountId().equals(accountId));
Assert.assertTrue(secondEmails.get(0).getEmail().equals(email1) || secondEmails.get(0).getEmail().equals(email2));
Assert.assertTrue(secondEmails.get(1).getEmail().equals(email1) || secondEmails.get(1).getEmail().equals(email2));
// Delete the first e-mail
accountDao.removeEmail(new AccountEmailModelDao(accountEmail1), internalCallContext);
final List<AccountEmailModelDao> thirdEmails = accountDao.getEmailsByAccountId(accountId, internalCallContext);
Assert.assertEquals(thirdEmails.size(), 1);
Assert.assertEquals(thirdEmails.get(0).getAccountId(), accountId);
Assert.assertEquals(thirdEmails.get(0).getEmail(), email2);
// Verify audits
final List<AuditLog> auditLogsForAccountEmail1 = auditDao.getAuditLogsForId(TableName.ACCOUNT_EMAIL, accountEmail1.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogsForAccountEmail1.size(), 2);
Assert.assertEquals(auditLogsForAccountEmail1.get(0).getChangeType(), ChangeType.INSERT);
Assert.assertEquals(auditLogsForAccountEmail1.get(1).getChangeType(), ChangeType.DELETE);
final List<AuditLog> auditLogsForAccountEmail2 = auditDao.getAuditLogsForId(TableName.ACCOUNT_EMAIL, accountEmail2.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogsForAccountEmail2.size(), 1);
Assert.assertEquals(auditLogsForAccountEmail2.get(0).getChangeType(), ChangeType.INSERT);
}
use of org.killbill.billing.account.api.DefaultAccountEmail in project killbill by killbill.
the class TestAccountDao method testHandleDuplicateEmails.
@Test(groups = "slow", description = "Test Account DAO: duplicate emails throws an exception")
public void testHandleDuplicateEmails() throws AccountApiException {
final UUID accountId = UUID.randomUUID();
final AccountEmail email = new DefaultAccountEmail(accountId, "test@gmail.com");
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 0);
final AccountEmailModelDao accountEmailModelDao = new AccountEmailModelDao(email);
accountDao.addEmail(accountEmailModelDao, internalCallContext);
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 1);
try {
accountDao.addEmail(accountEmailModelDao, internalCallContext);
Assert.fail();
} catch (AccountApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.ACCOUNT_EMAIL_ALREADY_EXISTS.getCode());
}
}
Aggregations