use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultSubscriptionApi method testCancelFutureSubscription.
@Test(groups = "slow")
public void testCancelFutureSubscription() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
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);
final LocalDate futureDate = new LocalDate(2013, 9, 1);
// No CREATE event as this is set in the future
final UUID createdEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), futureDate, futureDate, false, true, ImmutableList.<PluginProperty>of(), callContext);
final Entitlement createdEntitlement = entitlementApi.getEntitlementForId(createdEntitlementId, callContext);
assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0);
assertEquals(createdEntitlement.getEffectiveEndDate(), null);
final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(createdEntitlement.getId(), callContext);
assertEquals(baseEntitlement.getEffectiveStartDate().compareTo(futureDate), 0);
assertEquals(baseEntitlement.getEffectiveEndDate(), null);
final Entitlement cancelledEntitlement = baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, null, callContext);
assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0);
final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(cancelledEntitlement.getId(), callContext);
assertEquals(subscription.getEffectiveEndDate().compareTo(futureDate), 0);
assertListenerStatus();
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultSubscriptionApi method testCancellationEntitlementDifferentThanBilling.
@Test(groups = "slow")
public void testCancellationEntitlementDifferentThanBilling() 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 UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext);
// 2013-08-10 : Stay in TRIAL to ensure IMMEDIATE billing policy is used
clock.addDays(3);
assertListenerStatus();
final LocalDate cancelDate = new LocalDate(2013, 8, 14);
testListener.pushExpectedEvents(NextEvent.CANCEL);
baseEntitlement.cancelEntitlementWithDate(cancelDate, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Subscription result1 = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), callContext);
assertEquals(result1.getBillingEndDate().compareTo(new LocalDate(2013, 8, 10)), 0);
assertEquals(result1.getEffectiveEndDate().compareTo(new LocalDate(2013, 8, 14)), 0);
assertEquals(result1.getLastActiveProduct().getName(), "Shotgun");
assertEquals(result1.getState(), EntitlementState.ACTIVE);
// 2013-08-14: entitlement cancelDate
testListener.pushExpectedEvents(NextEvent.BLOCK);
clock.addDays(4);
assertListenerStatus();
final Subscription result2 = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), callContext);
assertEquals(result2.getBillingEndDate().compareTo(new LocalDate(2013, 8, 10)), 0);
assertEquals(result2.getEffectiveEndDate().compareTo(new LocalDate(2013, 8, 14)), 0);
assertEquals(result2.getLastActiveProduct().getName(), "Shotgun");
assertEquals(result2.getState(), EntitlementState.CANCELLED);
}
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 planPhaseSpecifier = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
final EntitlementSpecifier spec = new DefaultEntitlementSpecifier(planPhaseSpecifier);
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), spec, UUID.randomUUID().toString(), entitlementEffectiveDate, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, 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 testAddOnCreationTiming.
@Test(groups = "slow")
public void testAddOnCreationTiming() throws AccountApiException, EntitlementApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final String bundleExternalKey = UUID.randomUUID().toString();
final String bpExternalKey = UUID.randomUUID().toString();
final String aoExternalKey = UUID.randomUUID().toString();
final Account account = createAccount(getAccountData(7));
// Reference time of 2013-08-07T00:00:00.000
Assert.assertEquals(account.getReferenceTime().compareTo(new DateTime(2013, 8, 7, 0, 0, 0, DateTimeZone.UTC)), 0);
// Add 5 seconds
clock.addDeltaFromReality(5000);
// Create base entitlement (null LocalDate will map to now(), i.e. 2013-08-07T00:00:05.000Z)
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final PlanPhaseSpecifier baseSpec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
final UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(baseSpec, null, bpExternalKey, null), bundleExternalKey, null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final DefaultEntitlement baseEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlementId, callContext);
Assert.assertEquals(baseEntitlement.getSubscriptionBase().getStartDate().compareTo(account.getReferenceTime().plusSeconds(5)), 0);
Assert.assertEquals(baseEntitlement.getBundleExternalKey(), bundleExternalKey);
Assert.assertEquals(baseEntitlement.getExternalKey(), bpExternalKey);
// Add ADD_ON (verify date passed, i.e. initialDate, won't map to 2013-08-07T00:00:00.000Z)
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
final UUID addOnEntitlementId = entitlementApi.addEntitlement(baseEntitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec, null, aoExternalKey, null), initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final DefaultEntitlement addOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlementId, callContext);
Assert.assertEquals(addOnEntitlement.getSubscriptionBase().getStartDate().compareTo(baseEntitlement.getSubscriptionBase().getStartDate()), 0);
Assert.assertEquals(addOnEntitlement.getBundleExternalKey(), bundleExternalKey);
Assert.assertEquals(addOnEntitlement.getExternalKey(), aoExternalKey);
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultEntitlementApi method testCreateBaseWithBillingInThePast.
@Test(groups = "slow")
public void testCreateBaseWithBillingInThePast() 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.minusDays(5);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), entitlementDate, billingDate, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
assertEquals(entitlement.getState(), EntitlementState.ACTIVE);
assertEquals(entitlement.getEffectiveStartDate(), initialDate);
}
Aggregations