use of org.killbill.billing.subscription.api.user.SubscriptionBaseBundle in project killbill by killbill.
the class TestTransfer method testTransferWithUncancel.
@Test(groups = "slow")
public void testTransferWithUncancel() throws Exception {
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
testListener.pushExpectedEvent(NextEvent.PHASE);
clock.addDays(30);
assertListenerStatus();
// SET CTD TO TRIGGER CANCELLATION EOT
final DateTime ctd = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
setChargedThroughDate(baseSubscription.getId(), ctd, internalCallContext);
// CANCEL BP
baseSubscription = subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
baseSubscription.cancel(callContext);
// MOVE CLOCK one day AHEAD AND UNCANCEL BP
clock.addDays(1);
testListener.pushExpectedEvent(NextEvent.UNCANCEL);
baseSubscription.uncancel(callContext);
assertListenerStatus();
// MOVE CLOCK one day AHEAD AND UNCANCEL BP
clock.addDays(1);
final DateTime transferRequestedDate = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.TRANSFER);
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext);
assertListenerStatus();
final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext);
assertEquals(bundlesForAccountAndKey.size(), 1);
final SubscriptionBaseBundle newBundle = bundlesForAccountAndKey.get(0);
final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), null, internalCallContext);
assertEquals(subscriptions.size(), 1);
}
use of org.killbill.billing.subscription.api.user.SubscriptionBaseBundle in project killbill by killbill.
the class TestTransfer method testTransferBPInTrialWithNoCTD.
@Test(groups = "slow")
public void testTransferBPInTrialWithNoCTD() throws Exception {
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final DateTime evergreenPhaseDate = ((DefaultSubscriptionBase) baseSubscription).getPendingTransition().getEffectiveTransitionTime();
// MOVE A LITTLE, STILL IN TRIAL
clock.addDays(20);
final DateTime beforeTransferDate = clock.getUTCNow();
final DateTime transferRequestedDate = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.TRANSFER);
testListener.pushExpectedEvent(NextEvent.CANCEL);
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext);
assertListenerStatus();
final DateTime afterTransferDate = clock.getUTCNow();
// CHECK OLD BASE IS CANCEL AT THE TRANSFER DATE
final SubscriptionBase oldBaseSubscription = subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
assertNotNull(oldBaseSubscription.getEndDate());
testUtil.assertDateWithin(oldBaseSubscription.getEndDate(), beforeTransferDate, afterTransferDate);
assertTrue(oldBaseSubscription.getEndDate().compareTo(transferRequestedDate) == 0);
// CHECK NEW BUNDLE EXIST, WITH ONE SUBSCRIPTION STARTING ON TRANSFER_DATE
final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext);
assertEquals(bundlesForAccountAndKey.size(), 1);
final SubscriptionBaseBundle newBundle = bundlesForAccountAndKey.get(0);
final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), null, internalCallContext);
assertEquals(subscriptions.size(), 1);
final SubscriptionBase newBaseSubscription = subscriptions.get(0);
assertTrue(((DefaultSubscriptionBase) newBaseSubscription).getAlignStartDate().compareTo(((DefaultSubscriptionBase) oldBaseSubscription).getAlignStartDate()) == 0);
// CHECK NEXT PENDING PHASE IS ALIGNED WITH OLD SUBSCRIPTION START DATE
assertEquals(subscriptionInternalApi.getAllTransitions(newBaseSubscription, internalCallContext).size(), 2);
assertTrue(subscriptionInternalApi.getAllTransitions(newBaseSubscription, internalCallContext).get(1).getEffectiveTransitionTime().compareTo(evergreenPhaseDate) == 0);
final Plan newPlan = newBaseSubscription.getCurrentPlan();
assertEquals(newPlan.getProduct().getName(), baseProduct);
assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL);
}
use of org.killbill.billing.subscription.api.user.SubscriptionBaseBundle in project killbill by killbill.
the class TestBillingApi method beforeMethod.
@BeforeMethod(groups = "fast")
public void beforeMethod() throws Exception {
if (hasFailed()) {
return;
}
super.beforeMethod();
final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class);
Mockito.when(bundle.getId()).thenReturn(bunId);
final List<SubscriptionBaseBundle> bundles = ImmutableList.<SubscriptionBaseBundle>of(bundle);
billingTransitions = new LinkedList<SubscriptionBillingEvent>();
effectiveSubscriptionTransitions = new LinkedList<EffectiveSubscriptionInternalEvent>();
final DateTime subscriptionStartDate = clock.getUTCNow().minusDays(3);
subscription = new MockSubscription(subId, bunId, null, null, subscriptionStartDate, subscriptionStartDate);
final List<SubscriptionBase> subscriptions = ImmutableList.<SubscriptionBase>of(subscription);
// Mockito.when(subscription.getBillingAlignment(Mockito.<PlanPhaseSpecifier>any(), Mockito.<DateTime>any(), Mockito.<Catalog>any())).thenReturn(BillingAlignment.ACCOUNT);
Mockito.when(subscriptionInternalApi.getBundlesForAccount(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(bundles);
Mockito.when(subscriptionInternalApi.getSubscriptionsForBundle(Mockito.<UUID>any(), Mockito.<DryRunArguments>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscriptions);
Mockito.when(subscriptionInternalApi.getSubscriptionsForAccount(Mockito.<VersionedCatalog>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(ImmutableMap.<UUID, List<SubscriptionBase>>builder().put(bunId, subscriptions).build());
Mockito.when(subscriptionInternalApi.getSubscriptionFromId(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscription);
Mockito.when(subscriptionInternalApi.getBundleFromId(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(bundle);
Mockito.when(subscriptionInternalApi.getBaseSubscription(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscription);
Mockito.when(subscriptionInternalApi.getSubscriptionBillingEvents(Mockito.<VersionedCatalog>any(), Mockito.<SubscriptionBase>any(), Mockito.<InternalTenantContext>any())).thenReturn(billingTransitions);
Mockito.when(subscriptionInternalApi.getAllTransitions(Mockito.<SubscriptionBase>any(), Mockito.<InternalTenantContext>any())).thenReturn(effectiveSubscriptionTransitions);
final VersionedCatalog versionedCatalog = catalogService.getFullCatalog(true, true, internalCallContext);
catalog = (MockCatalog) Iterables.getLast(versionedCatalog.getVersions());
Mockito.when(catalogService.getFullCatalog(true, true, internalCallContext)).thenReturn(versionedCatalog);
// Set a default alignment
((MockSubscription) subscription).setBillingAlignment(BillingAlignment.ACCOUNT);
// Cleanup mock daos
((MockBlockingStateDao) blockingStateDao).clear();
((MockTagDao) tagDao).clear();
}
Aggregations