Search in sources :

Example 1 with BlockingState

use of org.killbill.billing.client.model.gen.BlockingState 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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BlockingStates(org.killbill.billing.client.model.BlockingStates) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Bundle(org.killbill.billing.client.model.gen.Bundle) BlockingState(org.killbill.billing.client.model.gen.BlockingState) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Aggregations

DateTime (org.joda.time.DateTime)1 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)1 BlockingStates (org.killbill.billing.client.model.BlockingStates)1 Bundles (org.killbill.billing.client.model.Bundles)1 Account (org.killbill.billing.client.model.gen.Account)1 BlockingState (org.killbill.billing.client.model.gen.BlockingState)1 Bundle (org.killbill.billing.client.model.gen.Bundle)1 Subscription (org.killbill.billing.client.model.gen.Subscription)1 Test (org.testng.annotations.Test)1