Search in sources :

Example 36 with SubscriptionBaseBundle

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);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 37 with SubscriptionBaseBundle

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);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 38 with SubscriptionBaseBundle

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();
}
Also used : EffectiveSubscriptionInternalEvent(org.killbill.billing.events.EffectiveSubscriptionInternalEvent) MockSubscription(org.killbill.billing.mock.MockSubscription) MockBlockingStateDao(org.killbill.billing.entitlement.dao.MockBlockingStateDao) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) MockTagDao(org.killbill.billing.util.tag.dao.MockTagDao) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) SubscriptionBillingEvent(org.killbill.billing.subscription.api.user.SubscriptionBillingEvent) DefaultSubscriptionBillingEvent(org.killbill.billing.subscription.api.user.DefaultSubscriptionBillingEvent) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)38 DateTime (org.joda.time.DateTime)23 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)20 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)16 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)14 UUID (java.util.UUID)13 DefaultSubscriptionBaseBundle (org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle)12 Test (org.testng.annotations.Test)12 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)8 Plan (org.killbill.billing.catalog.api.Plan)8 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 ImmutableAccountData (org.killbill.billing.account.api.ImmutableAccountData)6 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)6 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)5 HashMap (java.util.HashMap)4 AccountApiException (org.killbill.billing.account.api.AccountApiException)4