Search in sources :

Example 1 with AuditLog

use of org.killbill.billing.client.model.gen.AuditLog 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)

Example 2 with AuditLog

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

the class TestAccountTimeline method verifyInvoices.

private void verifyInvoices(final UUID accountId, final DateTime startTime, final DateTime endTime) throws Exception {
    for (final AuditLevel auditLevel : AuditLevel.values()) {
        final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
        // Verify invoices
        Assert.assertEquals(timeline.getInvoices().size(), 3);
        // Verify audits
        final List<AuditLog> firstInvoiceAuditLogs = timeline.getInvoices().get(0).getAuditLogs();
        final List<AuditLog> secondInvoiceAuditLogs = timeline.getInvoices().get(1).getAuditLogs();
        final List<AuditLog> thirdInvoiceAuditLogs = timeline.getInvoices().get(2).getAuditLogs();
        if (AuditLevel.NONE.equals(auditLevel)) {
            Assert.assertEquals(firstInvoiceAuditLogs.size(), 0);
            Assert.assertEquals(secondInvoiceAuditLogs.size(), 0);
            Assert.assertEquals(thirdInvoiceAuditLogs.size(), 0);
        } else {
            Assert.assertEquals(firstInvoiceAuditLogs.size(), 1);
            verifyAuditLog(firstInvoiceAuditLogs.get(0), ChangeType.INSERT, null, null, TRANSITION, startTime, endTime);
            Assert.assertEquals(secondInvoiceAuditLogs.size(), 1);
            verifyAuditLog(secondInvoiceAuditLogs.get(0), ChangeType.INSERT, null, null, TRANSITION, startTime, endTime);
            Assert.assertEquals(thirdInvoiceAuditLogs.size(), 1);
            verifyAuditLog(thirdInvoiceAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        }
    }
}
Also used : AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.gen.AccountTimeline) AuditLog(org.killbill.billing.client.model.gen.AuditLog)

Example 3 with AuditLog

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

the class TestCustomField method testCustomFieldTagAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testCustomFieldTagAuditLogsWithHistory() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final CustomField customField = new CustomField();
    customField.setName("custom");
    customField.setValue(UUID.randomUUID().toString().substring(0, 5));
    final CustomFields body = new CustomFields();
    body.add(customField);
    CustomFields result = accountApi.createAccountCustomFields(accountJson.getAccountId(), body, requestOptions);
    // get all audit for the account
    final List<AuditLog> auditLogsJson = accountApi.getAccountAuditLogs(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(auditLogsJson.size(), 2);
    UUID objectId = null;
    for (AuditLog auditLog : auditLogsJson) {
        if (auditLog.getObjectType().equals(ObjectType.CUSTOM_FIELD)) {
            objectId = auditLog.getObjectId();
            break;
        }
    }
    assertNotNull(objectId);
    final List<AuditLog> customFieldAuditLogWithHistory = customFieldApi.getCustomFieldAuditLogsWithHistory(result.get(0).getCustomFieldId(), requestOptions);
    assertEquals(customFieldAuditLogWithHistory.size(), 1);
    assertEquals(customFieldAuditLogWithHistory.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(customFieldAuditLogWithHistory.get(0).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(customFieldAuditLogWithHistory.get(0).getObjectId(), objectId);
    final LinkedHashMap history1 = (LinkedHashMap) customFieldAuditLogWithHistory.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("fieldName"), "custom");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) CustomField(org.killbill.billing.client.model.gen.CustomField) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 4 with AuditLog

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

the class TestAccountTimeline method verifyCredits.

private void verifyCredits(final UUID accountId, final DateTime startTime, final DateTime endTime, final BigDecimal creditAmount) throws Exception {
    for (final AuditLevel auditLevel : AuditLevel.values()) {
        final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
        // Verify credits
        final List<InvoiceItem> credits = timeline.getInvoices().get(1).getCredits();
        Assert.assertEquals(credits.size(), 1);
        Assert.assertEquals(credits.get(0).getAmount().compareTo(creditAmount.negate()), 0);
        // Verify audits
        final List<AuditLog> creditAuditLogs = credits.get(0).getAuditLogs();
        if (AuditLevel.NONE.equals(auditLevel)) {
            Assert.assertEquals(creditAuditLogs.size(), 0);
        } else {
            Assert.assertEquals(creditAuditLogs.size(), 1);
            verifyAuditLog(creditAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        }
    }
}
Also used : InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.gen.AccountTimeline) AuditLog(org.killbill.billing.client.model.gen.AuditLog)

Example 5 with AuditLog

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

the class TestAccountTimeline method verifyBundles.

private void verifyBundles(final UUID accountId, final DateTime startTime, final DateTime endTime) throws Exception {
    for (final AuditLevel auditLevel : AuditLevel.values()) {
        final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
        // Verify bundles
        Assert.assertEquals(timeline.getBundles().size(), 1);
        Assert.assertEquals(timeline.getBundles().get(0).getSubscriptions().size(), 1);
        Assert.assertEquals(timeline.getBundles().get(0).getSubscriptions().get(0).getEvents().size(), 3);
        // Verify audits
        final List<AuditLog> bundleAuditLogs = timeline.getBundles().get(0).getAuditLogs();
        final List<AuditLog> subscriptionAuditLogs = timeline.getBundles().get(0).getSubscriptions().get(0).getAuditLogs();
        final List<AuditLog> subscriptionEvent1AuditLogs = timeline.getBundles().get(0).getSubscriptions().get(0).getEvents().get(0).getAuditLogs();
        final List<AuditLog> subscriptionEvent2AuditLogs = timeline.getBundles().get(0).getSubscriptions().get(0).getEvents().get(1).getAuditLogs();
        if (AuditLevel.NONE.equals(auditLevel)) {
            // Audits for bundles
            Assert.assertEquals(bundleAuditLogs.size(), 0);
            // Audits for subscriptions
            Assert.assertEquals(subscriptionAuditLogs.size(), 0);
            // Audit for subscription events
            Assert.assertEquals(subscriptionEvent1AuditLogs.size(), 0);
            Assert.assertEquals(subscriptionEvent2AuditLogs.size(), 0);
        } else if (AuditLevel.MINIMAL.equals(auditLevel)) {
            // Audits for bundles
            Assert.assertEquals(bundleAuditLogs.size(), 1);
            verifyAuditLog(bundleAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            // Audits for subscriptions
            Assert.assertEquals(subscriptionAuditLogs.size(), 1);
            verifyAuditLog(subscriptionAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            // Audit for subscription events
            Assert.assertEquals(subscriptionEvent1AuditLogs.size(), 1);
            verifyAuditLog(subscriptionEvent1AuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            Assert.assertEquals(subscriptionEvent2AuditLogs.size(), 1);
            verifyAuditLog(subscriptionEvent2AuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        } else {
            // Audits for bundles
            Assert.assertEquals(bundleAuditLogs.size(), 1);
            verifyAuditLog(bundleAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            // Audits for subscriptions
            Assert.assertEquals(subscriptionAuditLogs.size(), 3);
            verifyAuditLog(subscriptionAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            verifyAuditLog(subscriptionAuditLogs.get(1), ChangeType.UPDATE, null, null, TRANSITION, startTime, endTime);
            verifyAuditLog(subscriptionAuditLogs.get(2), ChangeType.UPDATE, null, null, TRANSITION, startTime, endTime);
            // Audit for subscription events
            Assert.assertEquals(subscriptionEvent1AuditLogs.size(), 1);
            verifyAuditLog(subscriptionEvent1AuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            Assert.assertEquals(subscriptionEvent2AuditLogs.size(), 1);
            verifyAuditLog(subscriptionEvent2AuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        }
    }
}
Also used : AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.gen.AccountTimeline) AuditLog(org.killbill.billing.client.model.gen.AuditLog)

Aggregations

AuditLog (org.killbill.billing.client.model.gen.AuditLog)14 Account (org.killbill.billing.client.model.gen.Account)10 Test (org.testng.annotations.Test)10 LinkedHashMap (java.util.LinkedHashMap)6 UUID (java.util.UUID)5 AccountTimeline (org.killbill.billing.client.model.gen.AccountTimeline)4 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)4 AuditLevel (org.killbill.billing.util.api.AuditLevel)4 Invoices (org.killbill.billing.client.model.Invoices)2 Invoice (org.killbill.billing.client.model.gen.Invoice)2 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)2 Tag (org.killbill.billing.client.model.gen.Tag)2 TagDefinition (org.killbill.billing.client.model.gen.TagDefinition)2 BigDecimal (java.math.BigDecimal)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 RequestOptions (org.killbill.billing.client.RequestOptions)1 CustomFields (org.killbill.billing.client.model.CustomFields)1 AccountEmail (org.killbill.billing.client.model.gen.AccountEmail)1 CustomField (org.killbill.billing.client.model.gen.CustomField)1