Search in sources :

Example 6 with AuditLog

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

the class TestTag method testGetTagAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testGetTagAuditLogsWithHistory() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final TagDefinition accountTagDefInput = new TagDefinition().setName("tag_name").setDescription("nothing special").setApplicableObjectTypes(ImmutableList.<ObjectType>of(ObjectType.ACCOUNT));
    final TagDefinition accountTagDef = tagDefinitionApi.createTagDefinition(accountTagDefInput, requestOptions);
    accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(accountTagDef.getId()), 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.TAG)) {
            objectId = auditLog.getObjectId();
            break;
        }
    }
    assertNotNull(objectId);
    final List<AuditLog> tagAuditLogWithHistories = tagApi.getTagAuditLogsWithHistory(objectId, requestOptions);
    assertEquals(tagAuditLogWithHistories.size(), 1);
    assertEquals(tagAuditLogWithHistories.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(tagAuditLogWithHistories.get(0).getObjectType(), ObjectType.TAG);
    assertEquals(tagAuditLogWithHistories.get(0).getObjectId(), objectId);
    final LinkedHashMap history1 = (LinkedHashMap) tagAuditLogWithHistories.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("tagDefinitionId"), accountTagDef.getId().toString());
    assertEquals(history1.get("objectId"), accountJson.getAccountId().toString());
    assertEquals(history1.get("objectType"), ObjectType.ACCOUNT.toString());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 7 with AuditLog

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

the class TestInvoiceItem method testTags.

@Test(groups = "slow", description = "Add tags to invoice item")
public void testTags() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Invoices invoicesJson = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    Assert.assertNotNull(invoicesJson);
    Assert.assertEquals(invoicesJson.size(), 2);
    final List<InvoiceItem> invoiceItems = invoicesJson.get(0).getItems();
    Assert.assertNotNull(invoiceItems);
    // Create tag definition
    final TagDefinition input = new TagDefinition(null, false, "tagtest", "invoice item tag test", ImmutableList.<ObjectType>of(ObjectType.INVOICE_ITEM), null);
    final TagDefinition objFromJson = tagDefinitionApi.createTagDefinition(input, requestOptions);
    Assert.assertNotNull(objFromJson);
    Assert.assertEquals(objFromJson.getName(), input.getName());
    Assert.assertEquals(objFromJson.getDescription(), input.getDescription());
    // Add a tag
    final Multimap<String, String> followQueryParams = HashMultimap.create();
    followQueryParams.put(JaxrsResource.QUERY_ACCOUNT_ID, accountJson.getAccountId().toString());
    final RequestOptions followRequestOptions = requestOptions.extend().withQueryParamsForFollow(followQueryParams).build();
    invoiceItemApi.createInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), followRequestOptions);
    // Retrieves all tags
    final List<Tag> tags1 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags1.size(), 1);
    Assert.assertEquals(tags1.get(0).getTagDefinitionId(), objFromJson.getId());
    // Verify adding the same tag a second time doesn't do anything
    invoiceItemApi.createInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), followRequestOptions);
    // Retrieves all tags again
    final List<Tag> tags2 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags2, tags1);
    // Verify audit logs
    Assert.assertEquals(tags2.get(0).getAuditLogs().size(), 1);
    final AuditLog auditLogJson = tags2.get(0).getAuditLogs().get(0);
    Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(auditLogJson.getChangedBy(), createdBy);
    Assert.assertEquals(auditLogJson.getReasonCode(), reason);
    Assert.assertEquals(auditLogJson.getComments(), comment);
    Assert.assertNotNull(auditLogJson.getChangeDate());
    Assert.assertNotNull(auditLogJson.getUserToken());
    // remove it
    invoiceItemApi.deleteInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), requestOptions);
    final List<Tag> tags3 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags3.size(), 0);
    tagDefinitionApi.deleteTagDefinition(objFromJson.getId(), requestOptions);
    List<TagDefinition> objsFromJson = tagDefinitionApi.getTagDefinitions(requestOptions);
    Assert.assertNotNull(objsFromJson);
    Boolean isFound = false;
    for (TagDefinition tagDefinition : objsFromJson) {
        isFound |= tagDefinition.getId().equals(objFromJson.getId());
    }
    Assert.assertFalse(isFound);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) RequestOptions(org.killbill.billing.client.RequestOptions) Invoices(org.killbill.billing.client.model.Invoices) AuditLog(org.killbill.billing.client.model.gen.AuditLog) Tag(org.killbill.billing.client.model.gen.Tag) Test(org.testng.annotations.Test)

Example 8 with AuditLog

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

the class TestAccount method testTags.

@Test(groups = "slow", description = "Add tags to account")
public void testTags() throws Exception {
    final Account input = createAccount();
    // Use tag definition for AUTO_PAY_OFF
    final UUID autoPayOffId = new UUID(0, 1);
    // Add a tag
    accountApi.createAccountTags(input.getAccountId(), ImmutableList.<UUID>of(autoPayOffId), requestOptions);
    // Retrieves all tags
    final List<Tag> tags1 = accountApi.getAccountTags(input.getAccountId(), false, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags1.size(), 1);
    Assert.assertEquals(tags1.get(0).getTagDefinitionId(), autoPayOffId);
    // Verify adding the same tag a second time doesn't do anything
    accountApi.createAccountTags(input.getAccountId(), ImmutableList.<UUID>of(autoPayOffId), requestOptions);
    // Retrieves all tags again
    accountApi.createAccountTags(input.getAccountId(), ImmutableList.<UUID>of(autoPayOffId), requestOptions);
    final List<Tag> tags2 = accountApi.getAccountTags(input.getAccountId(), true, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags2, tags1);
    // Verify audit logs
    Assert.assertEquals(tags2.get(0).getAuditLogs().size(), 1);
    final AuditLog auditLogJson = tags2.get(0).getAuditLogs().get(0);
    Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(auditLogJson.getChangedBy(), createdBy);
    Assert.assertEquals(auditLogJson.getReasonCode(), reason);
    Assert.assertEquals(auditLogJson.getComments(), comment);
    Assert.assertNotNull(auditLogJson.getChangeDate());
    Assert.assertNotNull(auditLogJson.getUserToken());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Tag(org.killbill.billing.client.model.gen.Tag) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) Test(org.testng.annotations.Test)

Example 9 with AuditLog

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

the class TestAccount method testGetAccountAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testGetAccountAuditLogsWithHistory() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // Update Account
    final Account newInput = new Account().setAccountId(accountJson.getAccountId()).setExternalKey(accountJson.getExternalKey()).setName("zozo");
    accountApi.updateAccount(accountJson.getAccountId(), newInput, requestOptions);
    final List<AuditLog> auditLogWithHistories = accountApi.getAccountAuditLogsWithHistory(accountJson.getAccountId(), requestOptions);
    assertEquals(auditLogWithHistories.size(), 2);
    assertEquals(auditLogWithHistories.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogWithHistories.get(0).getObjectType(), ObjectType.ACCOUNT);
    assertEquals(auditLogWithHistories.get(0).getObjectId(), accountJson.getAccountId());
    final LinkedHashMap<String, Object> history1 = (LinkedHashMap<String, Object>) auditLogWithHistories.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("externalKey"), accountJson.getExternalKey());
    assertEquals(history1.get("name"), accountJson.getName());
    final LinkedHashMap history2 = (LinkedHashMap) auditLogWithHistories.get(1).getHistory();
    assertNotNull(history2);
    assertEquals(history2.get("externalKey"), accountJson.getExternalKey());
    assertNotEquals(history2.get("name"), accountJson.getName());
    assertEquals(history2.get("name"), "zozo");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 10 with AuditLog

use of org.killbill.billing.client.model.gen.AuditLog 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 = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE);
        Assert.assertEquals(purchaseTransactions.size(), 1);
        final PaymentTransaction purchaseTransaction = purchaseTransactions.get(0);
        // Verify refunds
        final List<PaymentTransaction> refundTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.REFUND);
        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 = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK);
        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 : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) 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