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