use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultSubscriptionApi method testSubscriptionCreationWithExternalKeyOverLimit.
@Test(groups = "slow")
public void testSubscriptionCreationWithExternalKeyOverLimit() throws AccountApiException, SubscriptionApiException, EntitlementApiException {
final String externalKey = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,.";
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);
//2013-08-07
final LocalDate effectiveDate = initialDate.plusMonths(1);
try {
entitlementApi.createBaseEntitlement(account.getId(), spec, externalKey, null, effectiveDate, effectiveDate, false, ImmutableList.<PluginProperty>of(), callContext);
Assert.fail();
} catch (final EntitlementApiException e) {
assertEquals(e.getCode(), ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED.getCode());
}
}
use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.
the class TestDefaultBlockingStateDao method testUnnecessaryEventsAreNotAdded.
@Test(groups = "slow", description = "Verify we don't insert extra add-on events")
public void testUnnecessaryEventsAreNotAdded() throws Exception {
// This is a simple smoke test at the dao level only to make sure we do sane
// things in case there are no future add-on cancellation events to add in the stream.
// See TestEntitlementUtils for a more comprehensive test
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, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final BlockingStateType type = BlockingStateType.SUBSCRIPTION;
final String state = "state";
final String service = "service";
// Verify initial state
Assert.assertEquals(blockingStateDao.getBlockingAllForAccountRecordId(internalCallContext).size(), 1);
// Set a state in the future so no event
final DateTime stateDateTime = new DateTime(2013, 5, 6, 10, 11, 12, DateTimeZone.UTC);
final BlockingState blockingState = new DefaultBlockingState(entitlement.getId(), type, state, service, false, false, false, stateDateTime);
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState, Optional.<UUID>of(entitlement.getBundleId())), internalCallContext);
assertListenerStatus();
Assert.assertEquals(blockingStateDao.getBlockingAllForAccountRecordId(internalCallContext).size(), 2);
}
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);
}
Aggregations