Search in sources :

Example 1 with AuditLevel

use of org.killbill.billing.util.api.AuditLevel 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<Credit> credits = timeline.getInvoices().get(1).getCredits();
        Assert.assertEquals(credits.size(), 1);
        Assert.assertEquals(credits.get(0).getCreditAmount().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 : Credit(org.killbill.billing.client.model.Credit) AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.AccountTimeline) AuditLog(org.killbill.billing.client.model.AuditLog)

Example 2 with AuditLevel

use of org.killbill.billing.util.api.AuditLevel 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.AccountTimeline) AuditLog(org.killbill.billing.client.model.AuditLog)

Example 3 with AuditLevel

use of org.killbill.billing.util.api.AuditLevel 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(), 3);
            verifyAuditLog(bundleAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            verifyAuditLog(bundleAuditLogs.get(1), ChangeType.UPDATE, null, null, TRANSITION, startTime, endTime);
            verifyAuditLog(bundleAuditLogs.get(2), ChangeType.UPDATE, null, null, TRANSITION, 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.AccountTimeline) AuditLog(org.killbill.billing.client.model.AuditLog)

Example 4 with AuditLevel

use of org.killbill.billing.util.api.AuditLevel in project killbill by killbill.

the class TestDefaultAuditDao method testRetrieveAuditsDirectly.

@Test(groups = "slow")
public void testRetrieveAuditsDirectly() throws Exception {
    addTag();
    // Verify we get an audit entry for the tag_history table
    final Handle handle = dbi.open();
    final String tagHistoryString = (String) handle.select("select id from tag_history limit 1").get(0).get("id");
    handle.close();
    for (final AuditLevel level : AuditLevel.values()) {
        final List<AuditLog> auditLogs = auditDao.getAuditLogsForId(TableName.TAG_HISTORY, UUID.fromString(tagHistoryString), level, internalCallContext);
        verifyAuditLogsForTag(auditLogs, level);
    }
}
Also used : AuditLevel(org.killbill.billing.util.api.AuditLevel) AuditLog(org.killbill.billing.util.audit.AuditLog) Handle(org.skife.jdbi.v2.Handle) Test(org.testng.annotations.Test)

Example 5 with AuditLevel

use of org.killbill.billing.util.api.AuditLevel in project killbill by killbill.

the class TestAccountTimeline method verifyPayments.

private void verifyPayments(final UUID accountId, final DateTime startTime, final DateTime endTime, final BigDecimal refundAmount, final BigDecimal chargebackAmount) throws Exception {
    for (final AuditLevel auditLevel : AuditLevel.values()) {
        final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
        Assert.assertEquals(timeline.getPayments().size(), 1);
        final InvoicePayment payment = timeline.getPayments().get(0);
        // Verify payments
        final List<PaymentTransaction> purchaseTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE.toString());
        Assert.assertEquals(purchaseTransactions.size(), 1);
        final PaymentTransaction purchaseTransaction = purchaseTransactions.get(0);
        // Verify refunds
        final List<PaymentTransaction> refundTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.REFUND.toString());
        Assert.assertEquals(refundTransactions.size(), 1);
        final PaymentTransaction refundTransaction = refundTransactions.get(0);
        Assert.assertEquals(refundTransaction.getPaymentId(), payment.getPaymentId());
        Assert.assertEquals(refundTransaction.getAmount().compareTo(refundAmount), 0);
        final List<PaymentTransaction> chargebackTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK.toString());
        Assert.assertEquals(chargebackTransactions.size(), 1);
        final PaymentTransaction chargebackTransaction = chargebackTransactions.get(0);
        Assert.assertEquals(chargebackTransaction.getPaymentId(), payment.getPaymentId());
        Assert.assertEquals(chargebackTransaction.getAmount().compareTo(chargebackAmount), 0);
        // Verify audits
        final List<AuditLog> paymentAuditLogs = purchaseTransaction.getAuditLogs();
        final List<AuditLog> refundAuditLogs = refundTransaction.getAuditLogs();
        final List<AuditLog> chargebackAuditLogs = chargebackTransaction.getAuditLogs();
        if (AuditLevel.NONE.equals(auditLevel)) {
            // Audits for payments
            Assert.assertEquals(paymentAuditLogs.size(), 0);
            // Audits for refunds
            Assert.assertEquals(refundAuditLogs.size(), 0);
            // Audits for chargebacks
            Assert.assertEquals(chargebackAuditLogs.size(), 0);
        } else if (AuditLevel.MINIMAL.equals(auditLevel)) {
            // Audits for payments
            Assert.assertEquals(paymentAuditLogs.size(), 1);
            verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
            // Audits for refunds
            Assert.assertEquals(refundAuditLogs.size(), 1);
            verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            // Audits for chargebacks
            Assert.assertEquals(chargebackAuditLogs.size(), 1);
            verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        } else {
            // Audits for payments
            Assert.assertEquals(paymentAuditLogs.size(), 2);
            verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
            verifyAuditLog(paymentAuditLogs.get(1), ChangeType.UPDATE, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
            // Audits for refunds
            Assert.assertEquals(refundAuditLogs.size(), 2);
            verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            verifyAuditLog(refundAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
            // Audits for chargebacks
            Assert.assertEquals(chargebackAuditLogs.size(), 2);
            verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            verifyAuditLog(chargebackAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
        }
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.AccountTimeline) AuditLog(org.killbill.billing.client.model.AuditLog)

Aggregations

AuditLevel (org.killbill.billing.util.api.AuditLevel)6 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)4 AuditLog (org.killbill.billing.client.model.AuditLog)4 AuditLog (org.killbill.billing.util.audit.AuditLog)2 Test (org.testng.annotations.Test)2 Credit (org.killbill.billing.client.model.Credit)1 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)1 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)1 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)1 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)1 AccountAuditLogsForObjectType (org.killbill.billing.util.audit.AccountAuditLogsForObjectType)1 Handle (org.skife.jdbi.v2.Handle)1