Search in sources :

Example 6 with Account

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

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

the class TestAdmin method testAdminInvoiceEndpoint.

@Test(groups = "slow")
public void testAdminInvoiceEndpoint() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final List<UUID> accounts = new LinkedList<UUID>();
    for (int i = 0; i < 5; i++) {
        final Account accountJson = createAccountWithDefaultPaymentMethod();
        assertNotNull(accountJson);
        accounts.add(accountJson.getAccountId());
        createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
        clock.addDays(2);
        Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
        final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 1);
    }
    // Trigger first non-trial invoice
    for (int i = 0; i < 5; i++) {
        callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    }
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
    for (final UUID accountId : accounts) {
        final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountId, null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 2);
    }
    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final Map<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.invoice.enabled", "false");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
    callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
    tenantApi.uploadPerTenantConfiguration(perTenantConfig, requestOptions);
    callbackServlet.assertListenerStatus();
    // Verify the second invoice isn't generated
    for (int i = 0; i < 5; i++) {
        callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION);
    }
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
    for (final UUID accountId : accounts) {
        final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountId, null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 2);
    }
    // Fix one account
    final Response response = triggerInvoiceGenerationForParkedAccounts(1);
    Assert.assertEquals(response.getResponseBody(), "{\"" + accounts.get(0) + "\":\"OK\"}");
    Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
    // Fix all accounts
    final Response response2 = triggerInvoiceGenerationForParkedAccounts(4);
    final Map<String, String> fixedAccounts = mapper.readValue(response2.getResponseBody(), new TypeReference<Map<String, String>>() {
    });
    Assert.assertEquals(fixedAccounts.size(), 4);
    Assert.assertEquals(fixedAccounts.get(accounts.get(1).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(2).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(3).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(4).toString()), "OK");
    Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 15);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) Response(org.asynchttpclient.Response) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 8 with Account

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

the class TestAccountTimeline method testAccountTimelineWithAudits.

@Test(groups = "slow", description = "Can retrieve the timeline with audits")
public void testAccountTimelineWithAudits() throws Exception {
    final DateTime startTime = clock.getUTCNow();
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final DateTime endTime = clock.getUTCNow();
    // Add credit
    final Invoice invoice = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).get(1);
    final BigDecimal creditAmount = BigDecimal.ONE;
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(accountJson.getAccountId());
    credit.setAmount(creditAmount);
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Add refund
    final Payment postedPayment = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).get(0);
    final BigDecimal refundAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(postedPayment.getPaymentId());
    refund.setAmount(refundAmount);
    invoicePaymentApi.createRefundWithAdjustments(postedPayment.getPaymentId(), refund, accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    // Add chargeback
    final BigDecimal chargebackAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(postedPayment.getPaymentId());
    chargeback.setAmount(chargebackAmount);
    invoicePaymentApi.createChargeback(postedPayment.getPaymentId(), chargeback, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Verify payments
    verifyPayments(accountJson.getAccountId(), startTime, endTime, refundAmount, chargebackAmount);
    // Verify invoices
    verifyInvoices(accountJson.getAccountId(), startTime, endTime);
    // Verify credits
    verifyCredits(accountJson.getAccountId(), startTime, endTime, creditAmount);
    // Verify bundles
    verifyBundles(accountJson.getAccountId(), startTime, endTime);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 9 with Account

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

the class TestCache method testInvalidateCacheByAccount.

@Test(groups = "slow", description = "Can Invalidate (clear) all Account Caches by accountId")
public void testInvalidateCacheByAccount() throws Exception {
    final Account input = createAccountNoPMBundleAndSubscription();
    // get all caches per account level
    final CacheController<String, Long> accountRecordIdCache = cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID);
    final CacheController<Long, ImmutableAccountData> accountImmutableCache = cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_IMMUTABLE);
    final CacheController<UUID, Integer> accountBcdCache = cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_BCD);
    // verify that they are not null and have the accountId stored as a key (the account created before)
    assertTrue(accountRecordIdCache.isKeyInCache(input.getAccountId().toString()));
    final Long accountRecordId = accountRecordIdCache.get(input.getAccountId().toString(), null);
    assertTrue(accountImmutableCache.isKeyInCache(accountRecordId));
    assertTrue(accountBcdCache.isKeyInCache(input.getAccountId()));
    // Make sure all events have been fully processed
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    // invalidate caches per account level by accountId
    adminApi.invalidatesCacheByAccount(input.getAccountId(), requestOptions);
    // verify that now the caches don't have the accountId key stored
    Assert.assertFalse(accountRecordIdCache.isKeyInCache(input.getAccountId().toString()));
    Assert.assertFalse(accountImmutableCache.isKeyInCache(accountRecordId));
    Assert.assertFalse(accountBcdCache.isKeyInCache(input.getAccountId()));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 10 with Account

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

Aggregations

Account (org.killbill.billing.client.model.gen.Account)153 Test (org.testng.annotations.Test)139 DateTime (org.joda.time.DateTime)43 UUID (java.util.UUID)38 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)37 Subscription (org.killbill.billing.client.model.gen.Subscription)34 Invoice (org.killbill.billing.client.model.gen.Invoice)33 BigDecimal (java.math.BigDecimal)29 Payment (org.killbill.billing.client.model.gen.Payment)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)21 KillBillClientException (org.killbill.billing.client.KillBillClientException)19 Invoices (org.killbill.billing.client.model.Invoices)19 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)19 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)19 LocalDate (org.joda.time.LocalDate)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 Tags (org.killbill.billing.client.model.Tags)13 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)12 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)11 Payments (org.killbill.billing.client.model.Payments)10