use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestBundle method testBundlesPagination.
@Test(groups = "slow", description = "Can paginate and search through all bundles")
public void testBundlesPagination() throws Exception {
final Account accountJson = createAccount();
for (int i = 0; i < 5; i++) {
createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
}
final Bundles allBundles = bundleApi.getBundles(requestOptions);
Assert.assertEquals(allBundles.size(), 5);
for (final Bundle bundle : allBundles) {
Assert.assertEquals(bundleApi.searchBundles(bundle.getBundleId().toString(), requestOptions).size(), 1);
Assert.assertEquals(bundleApi.searchBundles(bundle.getAccountId().toString(), requestOptions).size(), 5);
Assert.assertEquals(bundleApi.searchBundles(bundle.getExternalKey(), requestOptions).size(), 1);
}
Bundles page = bundleApi.getBundles(0L, 1L, AuditLevel.NONE, requestOptions);
for (int i = 0; i < 5; i++) {
Assert.assertNotNull(page);
Assert.assertEquals(page.size(), 1);
Assert.assertEquals(page.get(0), allBundles.get(i));
page = page.getNext();
}
Assert.assertNull(page);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestBundle method testBundleNonExistent.
@Test(groups = "slow", description = "Can handle non existent bundle")
public void testBundleNonExistent() throws Exception {
final Account accountJson = createAccount();
// ID
Assert.assertNull(bundleApi.getBundle(UUID.randomUUID(), requestOptions));
// External Key
Assert.assertTrue(bundleApi.getBundleByKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
Assert.assertTrue(bundleApi.getBundleByKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
// Account Id
Assert.assertTrue(accountApi.getAccountBundles(accountJson.getAccountId(), "98374982743892", null, requestOptions).isEmpty());
Assert.assertTrue(accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions).isEmpty());
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestBundle method testBlockBundle.
@Test(groups = "slow", description = "Block a bundle")
public void testBlockBundle() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithDefaultPaymentMethod();
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String bundleExternalKey = "93199";
final Subscription entitlement = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
assertEquals(existingBundles.size(), 1);
final Bundle bundle = existingBundles.get(0);
assertEquals(bundle.getAccountId(), accountJson.getAccountId());
assertEquals(bundle.getExternalKey(), bundleExternalKey);
final BlockingState blockingState = new BlockingState(bundle.getBundleId(), "block", "service", false, true, true, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
bundleApi.addBundleBlockingState(bundle.getBundleId(), blockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
final Subscription subscription = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
assertEquals(subscription.getState(), EntitlementState.BLOCKED);
clock.addDays(1);
final BlockingState unblockingState = new BlockingState(bundle.getBundleId(), "unblock", "service", false, false, false, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
bundleApi.addBundleBlockingState(bundle.getBundleId(), unblockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
final Subscription subscription2 = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
assertEquals(subscription2.getState(), EntitlementState.ACTIVE);
final BlockingStates blockingStates = accountApi.getBlockingStates(accountJson.getAccountId(), null, ImmutableList.<String>of("service"), AuditLevel.FULL, requestOptions);
Assert.assertEquals(blockingStates.size(), 2);
final BlockingStates blockingStates2 = accountApi.getBlockingStates(accountJson.getAccountId(), ImmutableList.<BlockingStateType>of(BlockingStateType.SUBSCRIPTION_BUNDLE), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(blockingStates2.size(), 2);
final BlockingStates blockingStates3 = accountApi.getBlockingStates(accountJson.getAccountId(), null, null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(blockingStates3.size(), 3);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestBundle method testBundleTransfer.
@Test(groups = "slow", description = "Can transfer bundle")
public void testBundleTransfer() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithDefaultPaymentMethod();
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String bundleExternalKey = "93199";
final Subscription entitlementJsonNoEvents = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
assertEquals(existingBundles.size(), 1);
Bundle originalBundle = existingBundles.get(0);
existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
assertEquals(existingBundles.size(), 1);
originalBundle = existingBundles.get(0);
assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
assertEquals(originalBundle.getExternalKey(), bundleExternalKey);
final Account newAccount = createAccountWithDefaultPaymentMethod();
final Bundle bundle = new Bundle();
bundle.setAccountId(newAccount.getAccountId());
bundle.setBundleId(entitlementJsonNoEvents.getBundleId());
bundleApi.transferBundle(entitlementJsonNoEvents.getBundleId(), bundle, null, NULL_PLUGIN_PROPERTIES, requestOptions);
existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
assertEquals(existingBundles.size(), 1);
final Bundle newBundle = existingBundles.get(0);
assertNotEquals(newBundle.getBundleId(), originalBundle.getBundleId());
assertEquals(newBundle.getExternalKey(), originalBundle.getExternalKey());
assertEquals(newBundle.getAccountId(), newAccount.getAccountId());
final Bundles bundles = bundleApi.getBundleByKey(bundleExternalKey, true, AuditLevel.NONE, requestOptions);
assertEquals(bundles.size(), 2);
assertSubscriptionState(bundles, originalBundle.getBundleId(), EntitlementState.CANCELLED);
assertSubscriptionState(bundles, newBundle.getBundleId(), EntitlementState.ACTIVE);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestExceptions method testExceptionMapping.
@Test(groups = "slow", enabled = false)
public void testExceptionMapping() throws Exception {
final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
final List<InvoicePayment> payments = accountApi.getInvoicePayments(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(payments.get(0).getPaymentId());
input.setAmount(BigDecimal.TEN.negate());
try {
invoicePaymentApi.createChargeback(payments.get(0).getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
fail();
} catch (final KillBillClientException e) {
Assert.assertEquals(e.getBillingException().getClassName(), InvoiceApiException.class.getName());
Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.CHARGE_BACK_AMOUNT_IS_NEGATIVE.getCode());
Assert.assertFalse(e.getBillingException().getStackTrace().isEmpty());
}
}
Aggregations