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);
}
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);
}
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);
}
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()));
}
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");
}
Aggregations