Search in sources :

Example 1 with AccountEmail

use of org.killbill.billing.client.model.gen.AccountEmail in project killbill by killbill.

the class TestAccountEmail method testAddAndRemoveAccountEmail.

@Test(groups = "slow", description = "Can create and delete account emails")
public void testAddAndRemoveAccountEmail() throws Exception {
    final Account input = createAccount();
    final UUID accountId = input.getAccountId();
    final String email1 = UUID.randomUUID().toString();
    final String email2 = UUID.randomUUID().toString();
    final AccountEmail accountEmailJson1 = new AccountEmail(accountId, email1, null);
    final AccountEmail accountEmailJson2 = new AccountEmail(accountId, email2, null);
    // Verify the initial state
    final List<AccountEmail> firstEmails = accountApi.getEmails(accountId, requestOptions);
    Assert.assertEquals(firstEmails.size(), 0);
    // Add an email
    accountApi.addEmail(accountId, accountEmailJson1, requestOptions);
    // Verify we can retrieve it
    final List<AccountEmail> secondEmails = accountApi.getEmails(accountId, requestOptions);
    Assert.assertEquals(secondEmails.size(), 1);
    Assert.assertEquals(secondEmails.get(0).getAccountId(), accountId);
    Assert.assertEquals(secondEmails.get(0).getEmail(), email1);
    // Add another email
    accountApi.addEmail(accountId, accountEmailJson2, requestOptions);
    // Verify we can retrieve both
    final List<AccountEmail> thirdEmails = accountApi.getEmails(accountId, requestOptions);
    Assert.assertEquals(thirdEmails.size(), 2);
    Assert.assertEquals(thirdEmails.get(0).getAccountId(), accountId);
    Assert.assertEquals(thirdEmails.get(1).getAccountId(), accountId);
    Assert.assertTrue(thirdEmails.get(0).getEmail().equals(email1) || thirdEmails.get(0).getEmail().equals(email2));
    Assert.assertTrue(thirdEmails.get(1).getEmail().equals(email1) || thirdEmails.get(1).getEmail().equals(email2));
    // Delete the first email
    accountApi.removeEmail(accountId, accountEmailJson1.getEmail(), requestOptions);
    // Verify it has been deleted
    final List<AccountEmail> fourthEmails = accountApi.getEmails(accountId, requestOptions);
    Assert.assertEquals(fourthEmails.size(), 1);
    Assert.assertEquals(fourthEmails.get(0).getAccountId(), accountId);
    Assert.assertEquals(fourthEmails.get(0).getEmail(), email2);
    // Try to add the same email
    accountApi.addEmail(accountId, accountEmailJson2, requestOptions);
    Assert.assertEquals(accountApi.getEmails(accountId, requestOptions), fourthEmails);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) AccountEmail(org.killbill.billing.client.model.gen.AccountEmail) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 2 with AccountEmail

use of org.killbill.billing.client.model.gen.AccountEmail in project killbill by killbill.

the class TestAccountEmail method testGetAccountEmailAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testGetAccountEmailAuditLogsWithHistory() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final String email1 = UUID.randomUUID().toString();
    final AccountEmail accountEmailJson1 = new AccountEmail(accountJson.getAccountId(), email1, EMPTY_AUDIT_LOGS);
    // Add an email
    accountApi.addEmail(accountJson.getAccountId(), accountEmailJson1, requestOptions);
    // get all audit for the account
    final List<AuditLog> auditLogsJson = accountApi.getAccountAuditLogs(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(auditLogsJson.size(), 2);
    final List<AuditLog> emailAuditLogWithHistories = accountApi.getAccountEmailAuditLogsWithHistory(accountJson.getAccountId(), auditLogsJson.get(0).getObjectId(), requestOptions);
    assertEquals(emailAuditLogWithHistories.size(), 1);
    assertEquals(emailAuditLogWithHistories.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(emailAuditLogWithHistories.get(0).getObjectType(), ObjectType.ACCOUNT_EMAIL);
    assertEquals(emailAuditLogWithHistories.get(0).getObjectId(), auditLogsJson.get(0).getObjectId());
    final LinkedHashMap history1 = (LinkedHashMap) emailAuditLogWithHistories.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("email"), email1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) AccountEmail(org.killbill.billing.client.model.gen.AccountEmail) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.gen.Account)2 AccountEmail (org.killbill.billing.client.model.gen.AccountEmail)2 Test (org.testng.annotations.Test)2 LinkedHashMap (java.util.LinkedHashMap)1 UUID (java.util.UUID)1 AuditLog (org.killbill.billing.client.model.gen.AuditLog)1