Search in sources :

Example 1 with PhaseEventData

use of org.killbill.billing.subscription.events.phase.PhaseEventData in project killbill by killbill.

the class TestSubscriptionBillingEvents method testWithCancelation_After_EffSubDtV2.

@Test(groups = "fast")
public void testWithCancelation_After_EffSubDtV2() throws Exception {
    final DateTime createDate = new DateTime(2011, 1, 2, 0, 0, DateTimeZone.UTC);
    final DefaultSubscriptionBase subscriptionBase = new DefaultSubscriptionBase(new SubscriptionBuilder().setAlignStartDate(createDate));
    final UUID subscriptionId = UUID.randomUUID();
    final List<SubscriptionBaseEvent> inputEvents = new LinkedList<SubscriptionBaseEvent>();
    inputEvents.add(new ApiEventCreate(new ApiEventBuilder().setApiEventType(CREATE).setEventPlan("gold-monthly").setEventPlanPhase("gold-monthly-trial").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(createDate).setUpdatedDate(createDate).setEffectiveDate(createDate).setTotalOrdering(1).setActive(true)));
    final DateTime evergreenPhaseDate = createDate.plusDays(30);
    inputEvents.add(new PhaseEventData(new PhaseEventBuilder().setPhaseName("gold-monthly-evergreen").setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(evergreenPhaseDate).setUpdatedDate(evergreenPhaseDate).setEffectiveDate(evergreenPhaseDate).setTotalOrdering(2).setActive(true)));
    final DateTime cancelDate = new DateTime(2011, 2, 15, 0, 0, DateTimeZone.UTC);
    inputEvents.add(new ApiEventCancel(new ApiEventBuilder().setApiEventType(ApiEventType.CANCEL).setEventPlan(null).setEventPlanPhase(null).setEventPriceList(null).setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(createDate).setUpdatedDate(null).setEffectiveDate(cancelDate).setTotalOrdering(3).setActive(true)));
    subscriptionBase.rebuildTransitions(inputEvents, catalog);
    final List<SubscriptionBillingEvent> result = subscriptionBase.getSubscriptionBillingEvents(catalog.getCatalog());
    Assert.assertEquals(result.size(), 5);
    Assert.assertEquals(result.get(0).getType(), SubscriptionBaseTransitionType.CREATE);
    Assert.assertEquals(result.get(0).getEffectiveDate().compareTo(createDate), 0);
    Assert.assertEquals(result.get(0).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(0).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    Assert.assertEquals(result.get(1).getType(), SubscriptionBaseTransitionType.PHASE);
    Assert.assertEquals(result.get(1).getEffectiveDate().compareTo(evergreenPhaseDate), 0);
    Assert.assertEquals(result.get(1).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(1).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    // Catalog change event for EFF_SUB_DT_V2
    Assert.assertEquals(result.get(2).getType(), SubscriptionBaseTransitionType.CHANGE);
    Assert.assertEquals(result.get(2).getEffectiveDate().compareTo(EFF_SUB_DT_V2), 0);
    Assert.assertEquals(result.get(2).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(2).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V2), 0);
    // Catalog change event for EFF_SUB_DT_V3
    Assert.assertEquals(result.get(3).getType(), SubscriptionBaseTransitionType.CHANGE);
    Assert.assertEquals(result.get(3).getEffectiveDate().compareTo(EFF_SUB_DT_V3), 0);
    Assert.assertEquals(result.get(3).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(3).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V3), 0);
    // Cancel event
    Assert.assertEquals(result.get(4).getType(), SubscriptionBaseTransitionType.CANCEL);
    Assert.assertEquals(result.get(4).getEffectiveDate().compareTo(cancelDate), 0);
    Assert.assertNull(result.get(4).getPlan());
// Nothing after cancel -> we correctly discarded subsequent catalog update events after the cancel
}
Also used : ApiEventCreate(org.killbill.billing.subscription.events.user.ApiEventCreate) ApiEventCancel(org.killbill.billing.subscription.events.user.ApiEventCancel) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) PhaseEventData(org.killbill.billing.subscription.events.phase.PhaseEventData) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) UUID(java.util.UUID) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) Test(org.testng.annotations.Test)

Example 2 with PhaseEventData

use of org.killbill.billing.subscription.events.phase.PhaseEventData in project killbill by killbill.

the class TestSubscriptionBillingEvents method testWithChange_Before_EffSubDtV2.

@Test(groups = "fast")
public void testWithChange_Before_EffSubDtV2() throws Exception {
    final DateTime createDate = new DateTime(2011, 1, 2, 0, 0, DateTimeZone.UTC);
    final DefaultSubscriptionBase subscriptionBase = new DefaultSubscriptionBase(new SubscriptionBuilder().setAlignStartDate(createDate));
    final UUID subscriptionId = UUID.randomUUID();
    final List<SubscriptionBaseEvent> inputEvents = new LinkedList<SubscriptionBaseEvent>();
    inputEvents.add(new ApiEventCreate(new ApiEventBuilder().setApiEventType(CREATE).setEventPlan("gold-monthly").setEventPlanPhase("gold-monthly-trial").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(createDate).setUpdatedDate(createDate).setEffectiveDate(createDate).setTotalOrdering(1).setActive(true)));
    final DateTime evergreenPhaseDate = createDate.plusDays(30);
    inputEvents.add(new PhaseEventData(new PhaseEventBuilder().setPhaseName("gold-monthly-evergreen").setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(evergreenPhaseDate).setUpdatedDate(evergreenPhaseDate).setEffectiveDate(evergreenPhaseDate).setTotalOrdering(2).setActive(true)));
    final DateTime changeDate = new DateTime(2011, 2, 13, 0, 0, DateTimeZone.UTC);
    inputEvents.add(new ApiEventChange(new ApiEventBuilder().setApiEventType(ApiEventType.CHANGE).setEventPlan("silver-monthly").setEventPlanPhase("silver-monthly-evergreen").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(changeDate).setUpdatedDate(null).setEffectiveDate(changeDate).setTotalOrdering(3).setActive(true)));
    subscriptionBase.rebuildTransitions(inputEvents, catalog);
    final List<SubscriptionBillingEvent> result = subscriptionBase.getSubscriptionBillingEvents(catalog.getCatalog());
    Assert.assertEquals(result.size(), 3);
    Assert.assertEquals(result.get(0).getType(), SubscriptionBaseTransitionType.CREATE);
    Assert.assertEquals(result.get(0).getEffectiveDate().compareTo(createDate), 0);
    Assert.assertEquals(result.get(0).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(0).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    Assert.assertEquals(result.get(1).getType(), SubscriptionBaseTransitionType.PHASE);
    Assert.assertEquals(result.get(1).getEffectiveDate().compareTo(evergreenPhaseDate), 0);
    Assert.assertEquals(result.get(1).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(1).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    // User CHANGE event
    Assert.assertEquals(result.get(2).getType(), SubscriptionBaseTransitionType.CHANGE);
    Assert.assertEquals(result.get(2).getEffectiveDate().compareTo(changeDate), 0);
    Assert.assertEquals(result.get(2).getPlan().getName().compareTo("silver-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(2).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V3), 0);
// We should not see any catalog CHANGE events
}
Also used : ApiEventCreate(org.killbill.billing.subscription.events.user.ApiEventCreate) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) PhaseEventData(org.killbill.billing.subscription.events.phase.PhaseEventData) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) UUID(java.util.UUID) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) ApiEventChange(org.killbill.billing.subscription.events.user.ApiEventChange) Test(org.testng.annotations.Test)

Example 3 with PhaseEventData

use of org.killbill.billing.subscription.events.phase.PhaseEventData in project killbill by killbill.

the class TestSubscriptionBillingEvents method testWithCancelation_Before_EffSubDtV2.

@Test(groups = "fast")
public void testWithCancelation_Before_EffSubDtV2() throws Exception {
    final DateTime createDate = new DateTime(2011, 1, 2, 0, 0, DateTimeZone.UTC);
    final DefaultSubscriptionBase subscriptionBase = new DefaultSubscriptionBase(new SubscriptionBuilder().setAlignStartDate(createDate));
    final UUID subscriptionId = UUID.randomUUID();
    final List<SubscriptionBaseEvent> inputEvents = new LinkedList<SubscriptionBaseEvent>();
    inputEvents.add(new ApiEventCreate(new ApiEventBuilder().setApiEventType(CREATE).setEventPlan("gold-monthly").setEventPlanPhase("gold-monthly-trial").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(createDate).setUpdatedDate(createDate).setEffectiveDate(createDate).setTotalOrdering(1).setActive(true)));
    final DateTime evergreenPhaseDate = createDate.plusDays(30);
    inputEvents.add(new PhaseEventData(new PhaseEventBuilder().setPhaseName("gold-monthly-evergreen").setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(evergreenPhaseDate).setUpdatedDate(evergreenPhaseDate).setEffectiveDate(evergreenPhaseDate).setTotalOrdering(1).setActive(true)));
    final DateTime cancelDate = new DateTime(2011, 2, 13, 0, 0, DateTimeZone.UTC);
    inputEvents.add(new ApiEventCancel(new ApiEventBuilder().setApiEventType(ApiEventType.CANCEL).setEventPlan(null).setEventPlanPhase(null).setEventPriceList(null).setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(createDate).setUpdatedDate(null).setEffectiveDate(cancelDate).setTotalOrdering(2).setActive(true)));
    subscriptionBase.rebuildTransitions(inputEvents, catalog);
    final List<SubscriptionBillingEvent> result = subscriptionBase.getSubscriptionBillingEvents(catalog.getCatalog());
    Assert.assertEquals(result.size(), 3);
    Assert.assertEquals(result.get(0).getType(), SubscriptionBaseTransitionType.CREATE);
    Assert.assertEquals(result.get(0).getEffectiveDate().compareTo(createDate), 0);
    Assert.assertEquals(result.get(0).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(0).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    Assert.assertEquals(result.get(1).getType(), SubscriptionBaseTransitionType.PHASE);
    Assert.assertEquals(result.get(1).getEffectiveDate().compareTo(evergreenPhaseDate), 0);
    Assert.assertEquals(result.get(1).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(1).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    // Cancel event
    Assert.assertEquals(result.get(2).getType(), SubscriptionBaseTransitionType.CANCEL);
    Assert.assertEquals(result.get(2).getEffectiveDate().compareTo(cancelDate), 0);
    Assert.assertNull(result.get(2).getPlan());
// Nothing after cancel -> we correctly discarded subsequent catalog update events after the cancel
}
Also used : ApiEventCreate(org.killbill.billing.subscription.events.user.ApiEventCreate) ApiEventCancel(org.killbill.billing.subscription.events.user.ApiEventCancel) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) PhaseEventData(org.killbill.billing.subscription.events.phase.PhaseEventData) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) UUID(java.util.UUID) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) Test(org.testng.annotations.Test)

Example 4 with PhaseEventData

use of org.killbill.billing.subscription.events.phase.PhaseEventData in project killbill by killbill.

the class TestSubscriptionBillingEvents method testWithChange_After_EffSubDtV3.

@Test(groups = "fast")
public void testWithChange_After_EffSubDtV3() throws Exception {
    final DateTime createDate = new DateTime(2011, 1, 2, 0, 0, DateTimeZone.UTC);
    final DefaultSubscriptionBase subscriptionBase = new DefaultSubscriptionBase(new SubscriptionBuilder().setAlignStartDate(createDate));
    final UUID subscriptionId = UUID.randomUUID();
    final List<SubscriptionBaseEvent> inputEvents = new LinkedList<SubscriptionBaseEvent>();
    inputEvents.add(new ApiEventCreate(new ApiEventBuilder().setApiEventType(CREATE).setEventPlan("gold-monthly").setEventPlanPhase("gold-monthly-trial").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(createDate).setUpdatedDate(createDate).setEffectiveDate(createDate).setTotalOrdering(1).setActive(true)));
    final DateTime evergreenPhaseDate = createDate.plusDays(30);
    inputEvents.add(new PhaseEventData(new PhaseEventBuilder().setPhaseName("gold-monthly-evergreen").setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(evergreenPhaseDate).setUpdatedDate(evergreenPhaseDate).setEffectiveDate(evergreenPhaseDate).setTotalOrdering(2).setActive(true)));
    final DateTime changeDate = new DateTime(2011, 2, 15, 0, 0, DateTimeZone.UTC);
    inputEvents.add(new ApiEventChange(new ApiEventBuilder().setApiEventType(ApiEventType.CHANGE).setEventPlan("silver-monthly").setEventPlanPhase("silver-monthly-evergreen").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(changeDate).setUpdatedDate(null).setEffectiveDate(changeDate).setTotalOrdering(3).setActive(true)));
    subscriptionBase.rebuildTransitions(inputEvents, catalog);
    final List<SubscriptionBillingEvent> result = subscriptionBase.getSubscriptionBillingEvents(catalog.getCatalog());
    Assert.assertEquals(result.size(), 5);
    Assert.assertEquals(result.get(0).getType(), SubscriptionBaseTransitionType.CREATE);
    Assert.assertEquals(result.get(0).getEffectiveDate().compareTo(createDate), 0);
    Assert.assertEquals(result.get(0).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(0).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    Assert.assertEquals(result.get(1).getType(), SubscriptionBaseTransitionType.PHASE);
    Assert.assertEquals(result.get(1).getEffectiveDate().compareTo(evergreenPhaseDate), 0);
    Assert.assertEquals(result.get(1).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(1).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V1), 0);
    // Catalog change event for EFF_SUB_DT_V2
    Assert.assertEquals(result.get(2).getType(), SubscriptionBaseTransitionType.CHANGE);
    Assert.assertEquals(result.get(2).getEffectiveDate().compareTo(EFF_SUB_DT_V2), 0);
    Assert.assertEquals(result.get(2).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(2).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V2), 0);
    // Catalog change event for EFF_SUB_DT_V3
    Assert.assertEquals(result.get(3).getType(), SubscriptionBaseTransitionType.CHANGE);
    Assert.assertEquals(result.get(3).getEffectiveDate().compareTo(EFF_SUB_DT_V3), 0);
    Assert.assertEquals(result.get(3).getPlan().getName().compareTo("gold-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(3).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V3), 0);
    // User CHANGE event
    Assert.assertEquals(result.get(4).getType(), SubscriptionBaseTransitionType.CHANGE);
    Assert.assertEquals(result.get(4).getEffectiveDate().compareTo(changeDate), 0);
    Assert.assertEquals(result.get(4).getPlan().getName().compareTo("silver-monthly"), 0);
    Assert.assertEquals(toDateTime(result.get(4).getPlan().getCatalog().getEffectiveDate()).compareTo(EFF_V3), 0);
// We should not see any more catalog CHANGE events
}
Also used : ApiEventCreate(org.killbill.billing.subscription.events.user.ApiEventCreate) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) PhaseEventData(org.killbill.billing.subscription.events.phase.PhaseEventData) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) UUID(java.util.UUID) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) ApiEventChange(org.killbill.billing.subscription.events.user.ApiEventChange) Test(org.testng.annotations.Test)

Example 5 with PhaseEventData

use of org.killbill.billing.subscription.events.phase.PhaseEventData in project killbill by killbill.

the class TestDefaultSubscriptionBase method testFutureCancelBeforePhase.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/897")
public void testFutureCancelBeforePhase() throws Exception {
    final DateTime startDate = new DateTime(2012, 5, 1, 0, 0, DateTimeZone.UTC);
    final DefaultSubscriptionBase subscriptionBase = new DefaultSubscriptionBase(new SubscriptionBuilder().setAlignStartDate(startDate));
    final UUID subscriptionId = UUID.randomUUID();
    final List<SubscriptionBaseEvent> inputEvents = new LinkedList<SubscriptionBaseEvent>();
    inputEvents.add(new ApiEventCreate(new ApiEventBuilder().setApiEventType(CREATE).setEventPlan("laser-scope-monthly").setEventPlanPhase("laser-scope-monthly-discount").setEventPriceList("DEFAULT").setFromDisk(true).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(startDate).setUpdatedDate(startDate).setEffectiveDate(startDate).setTotalOrdering(3).setActive(true)));
    inputEvents.add(new PhaseEventData(new PhaseEventBuilder().setPhaseName("laser-scope-monthly-evergreen").setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(startDate).setUpdatedDate(startDate).setEffectiveDate(new DateTime(2012, 6, 1, 0, 0, DateTimeZone.UTC)).setTotalOrdering(4).setActive(true)));
    inputEvents.add(new ApiEventCancel(new ApiEventBuilder().setApiEventType(ApiEventType.CANCEL).setEventPlan(null).setEventPlanPhase(null).setEventPriceList(null).setFromDisk(false).setUuid(UUID.randomUUID()).setSubscriptionId(subscriptionId).setCreatedDate(startDate).setUpdatedDate(null).setEffectiveDate(new DateTime(2012, 6, 1, 0, 0, DateTimeZone.UTC)).setTotalOrdering(// In-memory event
    0).setActive(true)));
    subscriptionBase.rebuildTransitions(inputEvents, catalog);
    Assert.assertEquals(subscriptionBase.getAllTransitions().size(), 2);
    Assert.assertNull(subscriptionBase.getAllTransitions().get(0).getPreviousState());
    Assert.assertEquals(subscriptionBase.getAllTransitions().get(0).getNextState(), EntitlementState.ACTIVE);
    Assert.assertEquals(subscriptionBase.getAllTransitions().get(0).getEffectiveTransitionTime(), startDate);
    Assert.assertEquals(subscriptionBase.getAllTransitions().get(1).getPreviousState(), EntitlementState.ACTIVE);
    Assert.assertEquals(subscriptionBase.getAllTransitions().get(1).getNextState(), EntitlementState.CANCELLED);
    Assert.assertEquals(subscriptionBase.getAllTransitions().get(1).getEffectiveTransitionTime(), new DateTime(2012, 6, 1, 0, 0, DateTimeZone.UTC));
}
Also used : ApiEventCreate(org.killbill.billing.subscription.events.user.ApiEventCreate) PhaseEventData(org.killbill.billing.subscription.events.phase.PhaseEventData) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) ApiEventCancel(org.killbill.billing.subscription.events.user.ApiEventCancel) UUID(java.util.UUID) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Aggregations

LinkedList (java.util.LinkedList)5 UUID (java.util.UUID)5 DateTime (org.joda.time.DateTime)5 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)5 PhaseEventBuilder (org.killbill.billing.subscription.events.phase.PhaseEventBuilder)5 PhaseEventData (org.killbill.billing.subscription.events.phase.PhaseEventData)5 ApiEventBuilder (org.killbill.billing.subscription.events.user.ApiEventBuilder)5 ApiEventCreate (org.killbill.billing.subscription.events.user.ApiEventCreate)5 Test (org.testng.annotations.Test)5 ApiEventCancel (org.killbill.billing.subscription.events.user.ApiEventCancel)3 ApiEventChange (org.killbill.billing.subscription.events.user.ApiEventChange)2