use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestRegessionSubscriptionApi method testRegressionForNew_ENT_STARTED_event.
@Test(groups = "slow", description = "Verify behavior with or without ENT_STARTED event works as expected")
public void testRegressionForNew_ENT_STARTED_event() throws Exception {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
// Start the entitlement yesterday (does not m,ake sense, but we want to check later different of behavior)
final LocalDate entitlementEffectiveDate = initialDate.minusDays(1);
final Account account = createAccount(getAccountData(7));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, UUID.randomUUID().toString(), null, entitlementEffectiveDate, null, false, ImmutableList.<PluginProperty>of(), callContext);
// Because of the BlockingState event ENT_STARTED, the entitlement date should be correctly set
Assert.assertEquals(entitlement.getEffectiveStartDate(), entitlementEffectiveDate);
final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), callContext);
Assert.assertEquals(bundles.size(), 1);
subscriptionBundleChecker(bundles, initialDate, entitlement, 0);
// Let's do some surgery and inactivate the ENT_STARTED BlockingState
final List<BlockingState> blockingStates = blockingStateDao.getBlockingState(entitlement.getId(), BlockingStateType.SUBSCRIPTION, clock.getUTCNow(), internalCallContext);
assertEquals(blockingStates.size(), 1);
assertEquals(blockingStates.get(0).getStateName(), DefaultEntitlementApi.ENT_STATE_START);
blockingStateDao.unactiveBlockingState(blockingStates.get(0).getId(), internalCallContext);
final Entitlement oldSchoolEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
// Because the ENT_STARTED BlockingState has been invalidated, the startDate should now default to the billingDate
Assert.assertEquals(oldSchoolEntitlement.getEffectiveStartDate(), initialDate);
final List<SubscriptionBundle> oldSchoolBundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), callContext);
Assert.assertEquals(oldSchoolBundles.size(), 1);
subscriptionBundleChecker(oldSchoolBundles, initialDate, oldSchoolEntitlement, 0);
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultEntitlementApi method testPauseUnpauseInTheFuture.
@Test(groups = "slow", description = "Test pause / unpause in the future")
public void testPauseUnpauseInTheFuture() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
// Create entitlement
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null);
final Entitlement baseEntitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Get the phase event out of the way
testListener.pushExpectedEvents(NextEvent.PHASE);
clock.setDay(new LocalDate(2013, 9, 7));
assertListenerStatus();
final LocalDate pauseDate = new LocalDate(2013, 9, 17);
entitlementApi.pause(baseEntitlement.getBundleId(), pauseDate, ImmutableList.<PluginProperty>of(), callContext);
// No event yet
assertListenerStatus();
final Entitlement refreshedAfterFuturePause = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
assertEquals(refreshedAfterFuturePause.getState(), EntitlementState.ACTIVE);
final LocalDate resumeDate = new LocalDate(2013, 12, 24);
entitlementApi.resume(baseEntitlement.getBundleId(), resumeDate, ImmutableList.<PluginProperty>of(), callContext);
// No event yet
assertListenerStatus();
// Not worth writing another test in TestDefaultSubscriptionApi just for that subscription call. We want to check that future PAUSE/RESUME events are visible
final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), callContext);
Assert.assertEquals(subscription.getSubscriptionEvents().size(), 7);
Assert.assertEquals(subscription.getSubscriptionEvents().get(0).getServiceName(), "entitlement-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(0).getServiceStateName(), "ENT_STARTED");
Assert.assertNull(subscription.getSubscriptionEvents().get(0).getPrevPhase());
Assert.assertEquals(subscription.getSubscriptionEvents().get(0).getNextPhase().getName(), "shotgun-annual-trial");
Assert.assertEquals(subscription.getSubscriptionEvents().get(1).getServiceName(), "billing-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(1).getServiceStateName(), "START_BILLING");
Assert.assertNull(subscription.getSubscriptionEvents().get(1).getPrevPhase());
Assert.assertEquals(subscription.getSubscriptionEvents().get(1).getNextPhase().getName(), "shotgun-annual-trial");
Assert.assertEquals(subscription.getSubscriptionEvents().get(2).getServiceName(), "entitlement+billing-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(2).getServiceStateName(), "PHASE");
Assert.assertEquals(subscription.getSubscriptionEvents().get(2).getPrevPhase().getName(), "shotgun-annual-trial");
Assert.assertEquals(subscription.getSubscriptionEvents().get(2).getNextPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(3).getServiceName(), "entitlement-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(3).getServiceStateName(), "ENT_BLOCKED");
Assert.assertEquals(subscription.getSubscriptionEvents().get(3).getPrevPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(3).getNextPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(4).getServiceName(), "billing-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(4).getServiceStateName(), "ENT_BLOCKED");
Assert.assertEquals(subscription.getSubscriptionEvents().get(4).getPrevPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(4).getNextPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(5).getServiceName(), "entitlement-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(5).getServiceStateName(), "ENT_CLEAR");
Assert.assertEquals(subscription.getSubscriptionEvents().get(5).getPrevPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(5).getNextPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(6).getServiceName(), "billing-service");
Assert.assertEquals(subscription.getSubscriptionEvents().get(6).getServiceStateName(), "ENT_CLEAR");
Assert.assertEquals(subscription.getSubscriptionEvents().get(6).getPrevPhase().getName(), "shotgun-annual-evergreen");
Assert.assertEquals(subscription.getSubscriptionEvents().get(6).getNextPhase().getName(), "shotgun-annual-evergreen");
testListener.pushExpectedEvents(NextEvent.BLOCK);
clock.setDay(pauseDate);
assertListenerStatus();
// Verify blocking state
final Entitlement baseEntitlementPaused = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
assertEquals(baseEntitlementPaused.getState(), EntitlementState.BLOCKED);
testListener.pushExpectedEvents(NextEvent.BLOCK);
clock.setDay(resumeDate);
assertListenerStatus();
// Verify blocking state
final Entitlement baseEntitlementUnpaused = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
assertEquals(baseEntitlementUnpaused.getState(), EntitlementState.ACTIVE);
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultEntitlementApi method testCreateEntitlementWithCheck.
@Test(groups = "slow")
public void testCreateEntitlementWithCheck() throws AccountApiException, EntitlementApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
// Create entitlement and check each field
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
assertEquals(entitlement.getAccountId(), account.getId());
assertEquals(entitlement.getExternalKey(), account.getExternalKey());
assertEquals(entitlement.getEffectiveStartDate(), initialDate);
assertNull(entitlement.getEffectiveEndDate());
assertEquals(entitlement.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(entitlement.getLastActiveProduct().getName(), "Shotgun");
assertEquals(entitlement.getLastActivePhase().getName(), "shotgun-monthly-trial");
assertEquals(entitlement.getLastActivePlan().getName(), "shotgun-monthly");
assertEquals(entitlement.getLastActiveProductCategory(), ProductCategory.BASE);
assertEquals(entitlement.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE);
assertEquals(entitlement.getLastActivePlan().getName(), "shotgun-monthly");
assertEquals(entitlement.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(entitlement.getLastActiveProduct().getName(), "Shotgun");
assertEquals(entitlement.getLastActiveProductCategory(), ProductCategory.BASE);
assertEquals(entitlement.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE);
// Now retrieve entitlement by id and recheck everything
final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
assertEquals(entitlement2.getAccountId(), account.getId());
assertEquals(entitlement2.getExternalKey(), account.getExternalKey());
assertEquals(entitlement2.getEffectiveStartDate(), initialDate);
assertNull(entitlement2.getEffectiveEndDate());
assertEquals(entitlement2.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(entitlement2.getLastActiveProduct().getName(), "Shotgun");
assertEquals(entitlement2.getLastActivePhase().getName(), "shotgun-monthly-trial");
assertEquals(entitlement2.getLastActivePlan().getName(), "shotgun-monthly");
assertEquals(entitlement2.getLastActiveProductCategory(), ProductCategory.BASE);
assertEquals(entitlement2.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement2.getSourceType(), EntitlementSourceType.NATIVE);
assertEquals(entitlement2.getLastActivePlan().getName(), "shotgun-monthly");
assertEquals(entitlement2.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(entitlement2.getLastActiveProduct().getName(), "Shotgun");
assertEquals(entitlement2.getLastActiveProductCategory(), ProductCategory.BASE);
assertEquals(entitlement2.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement2.getSourceType(), EntitlementSourceType.NATIVE);
// Finally
final List<Entitlement> accountEntitlements = entitlementApi.getAllEntitlementsForAccountId(account.getId(), callContext);
assertEquals(accountEntitlements.size(), 1);
final Entitlement entitlement3 = accountEntitlements.get(0);
assertEquals(entitlement3.getAccountId(), account.getId());
assertEquals(entitlement3.getExternalKey(), account.getExternalKey());
assertEquals(entitlement3.getEffectiveStartDate(), initialDate);
assertNull(entitlement3.getEffectiveEndDate());
assertEquals(entitlement3.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(entitlement3.getLastActiveProduct().getName(), "Shotgun");
assertEquals(entitlement3.getLastActivePhase().getName(), "shotgun-monthly-trial");
assertEquals(entitlement3.getLastActivePlan().getName(), "shotgun-monthly");
assertEquals(entitlement3.getLastActiveProductCategory(), ProductCategory.BASE);
assertEquals(entitlement3.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement3.getSourceType(), EntitlementSourceType.NATIVE);
assertEquals(entitlement3.getLastActivePlan().getName(), "shotgun-monthly");
assertEquals(entitlement3.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(entitlement3.getLastActiveProduct().getName(), "Shotgun");
assertEquals(entitlement3.getLastActiveProductCategory(), ProductCategory.BASE);
assertEquals(entitlement3.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement3.getSourceType(), EntitlementSourceType.NATIVE);
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultEntitlementApi method testAddEntitlementOnPendingBase.
@Test(groups = "slow")
public void testAddEntitlementOnPendingBase() throws AccountApiException, EntitlementApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null);
// Create entitlement and check each field
final LocalDate startDate = initialDate.plusDays(10);
final Entitlement baseEntitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, startDate, startDate, false, ImmutableList.<PluginProperty>of(), callContext);
// Add ADD_ON immediately. Because BASE is PENDING should fail
final PlanPhaseSpecifier spec1 = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
try {
entitlementApi.addEntitlement(baseEntitlement.getBundleId(), spec1, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
fail("Should not succeed to create ADD_On prior BASE is active");
} catch (final EntitlementApiException e) {
assertEquals(e.getCode(), ErrorCode.SUB_GET_NO_SUCH_BASE_SUBSCRIPTION.getCode());
}
// Add ADD_ON with a startDate similar to BASE
final Entitlement telescopicEntitlement = entitlementApi.addEntitlement(baseEntitlement.getBundleId(), spec1, null, startDate, startDate, false, ImmutableList.<PluginProperty>of(), callContext);
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.BLOCK);
clock.addDays(10);
assertListenerStatus();
assertEquals(telescopicEntitlement.getAccountId(), account.getId());
assertEquals(telescopicEntitlement.getExternalKey(), account.getExternalKey());
assertEquals(telescopicEntitlement.getEffectiveStartDate(), startDate);
assertNull(telescopicEntitlement.getEffectiveEndDate());
assertEquals(telescopicEntitlement.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(telescopicEntitlement.getLastActiveProduct().getName(), "Telescopic-Scope");
assertEquals(telescopicEntitlement.getLastActivePhase().getName(), "telescopic-scope-monthly-discount");
assertEquals(telescopicEntitlement.getLastActivePlan().getName(), "telescopic-scope-monthly");
assertEquals(telescopicEntitlement.getLastActiveProductCategory(), ProductCategory.ADD_ON);
List<Entitlement> bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(telescopicEntitlement.getBundleId(), callContext);
assertEquals(bundleEntitlements.size(), 2);
bundleEntitlements = entitlementApi.getAllEntitlementsForAccountIdAndExternalKey(account.getId(), account.getExternalKey(), callContext);
assertEquals(bundleEntitlements.size(), 2);
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultEntitlementApi method testCreateBaseWithBillingInTheFuture.
@Test(groups = "slow")
public void testCreateBaseWithBillingInTheFuture() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
final LocalDate entitlementDate = null;
final LocalDate billingDate = initialDate.plusDays(5);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
testListener.pushExpectedEvents(NextEvent.BLOCK);
final Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, entitlementDate, billingDate, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
assertEquals(entitlement.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement.getEffectiveStartDate(), initialDate);
testListener.pushExpectedEvents(NextEvent.CREATE);
clock.addDays(5);
assertListenerStatus();
}
Aggregations