Search in sources :

Example 1 with MockSubscription

use of org.killbill.billing.mock.MockSubscription in project killbill by killbill.

the class TestBillingApi method testBillingEventsBundleAligned.

@Test(groups = "fast")
public void testBillingEventsBundleAligned() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
    final Plan nextPlan = catalog.findPlan("7-Horn1USD", clock.getUTCNow());
    final PlanPhase nextPhase = nextPlan.getAllPhases()[0];
    final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
    final Account account = createAccount(1);
    catalog.setBillingAlignment(BillingAlignment.BUNDLE);
    ((MockSubscription) subscription).setPlan(catalog.findPlan("3-PickupTrialEvergreen10USD", now));
    final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
    // The expected BCD is when the subscription started
    checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString());
}
Also used : Account(org.killbill.billing.account.api.Account) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockSubscription(org.killbill.billing.mock.MockSubscription) BillingEvent(org.killbill.billing.junction.BillingEvent) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with MockSubscription

use of org.killbill.billing.mock.MockSubscription in project killbill by killbill.

the class TestBillingApi method beforeMethod.

@BeforeMethod(groups = "fast")
public void beforeMethod() throws Exception {
    super.beforeMethod();
    final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class);
    Mockito.when(bundle.getId()).thenReturn(bunId);
    final List<SubscriptionBaseBundle> bundles = ImmutableList.<SubscriptionBaseBundle>of(bundle);
    effectiveSubscriptionTransitions = new LinkedList<EffectiveSubscriptionInternalEvent>();
    final DateTime subscriptionStartDate = clock.getUTCNow().minusDays(3);
    subscription = new MockSubscription(subId, bunId, null, subscriptionStartDate, subscriptionStartDate);
    final List<SubscriptionBase> subscriptions = ImmutableList.<SubscriptionBase>of(subscription);
    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.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.getBillingTransitions(Mockito.<SubscriptionBase>any(), Mockito.<InternalTenantContext>any())).thenReturn(effectiveSubscriptionTransitions);
    Mockito.when(subscriptionInternalApi.getAllTransitions(Mockito.<SubscriptionBase>any(), Mockito.<InternalTenantContext>any())).thenReturn(effectiveSubscriptionTransitions);
    catalog = ((MockCatalog) catalogService.getCurrentCatalog(true, true, internalCallContext));
    // TODO The MockCatalog module returns two different things for full vs current catalog
    Mockito.when(catalogService.getFullCatalog(true, true, internalCallContext)).thenReturn(catalog);
    // Set a default alignment
    catalog.setBillingAlignment(BillingAlignment.ACCOUNT);
    // Cleanup mock daos
    ((MockBlockingStateDao) blockingStateDao).clear();
    ((MockTagDao) tagDao).clear();
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockCatalog(org.killbill.billing.catalog.MockCatalog) MockTagDao(org.killbill.billing.util.tag.dao.MockTagDao) EffectiveSubscriptionInternalEvent(org.killbill.billing.events.EffectiveSubscriptionInternalEvent) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) MockSubscription(org.killbill.billing.mock.MockSubscription) MockBlockingStateDao(org.killbill.billing.entitlement.dao.MockBlockingStateDao) DateTime(org.joda.time.DateTime) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

DateTime (org.joda.time.DateTime)2 MockSubscription (org.killbill.billing.mock.MockSubscription)2 Account (org.killbill.billing.account.api.Account)1 MockCatalog (org.killbill.billing.catalog.MockCatalog)1 Plan (org.killbill.billing.catalog.api.Plan)1 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)1 MockBlockingStateDao (org.killbill.billing.entitlement.dao.MockBlockingStateDao)1 EffectiveSubscriptionInternalEvent (org.killbill.billing.events.EffectiveSubscriptionInternalEvent)1 BillingEvent (org.killbill.billing.junction.BillingEvent)1 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)1 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)1 MockTagDao (org.killbill.billing.util.tag.dao.MockTagDao)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1