Search in sources :

Example 26 with ApiEventBuilder

use of org.killbill.billing.subscription.events.user.ApiEventBuilder in project killbill by killbill.

the class TestPlanAligner method createSubscriptionEvent.

private SubscriptionBaseEvent createSubscriptionEvent(final DateTime effectiveDate, final String productName, final PhaseType phaseType, final ApiEventType apiEventType) {
    final ApiEventBuilder eventBuilder = new ApiEventBuilder();
    eventBuilder.setEffectiveDate(effectiveDate);
    eventBuilder.setEventPlan(productName);
    eventBuilder.setEventPlanPhase(productName + "-" + phaseType.toString().toLowerCase());
    eventBuilder.setEventPriceList(priceList);
    // We don't really use the following but the code path requires it
    eventBuilder.setFromDisk(true);
    return new ApiEventBase(eventBuilder.setApiEventType(apiEventType));
}
Also used : ApiEventBase(org.killbill.billing.subscription.events.user.ApiEventBase) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder)

Example 27 with ApiEventBuilder

use of org.killbill.billing.subscription.events.user.ApiEventBuilder 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

ApiEventBuilder (org.killbill.billing.subscription.events.user.ApiEventBuilder)27 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)26 ArrayList (java.util.ArrayList)13 DateTime (org.joda.time.DateTime)13 ApiEventCancel (org.killbill.billing.subscription.events.user.ApiEventCancel)12 ApiEventCreate (org.killbill.billing.subscription.events.user.ApiEventCreate)11 LinkedList (java.util.LinkedList)10 ApiEventChange (org.killbill.billing.subscription.events.user.ApiEventChange)8 PhaseEventBuilder (org.killbill.billing.subscription.events.phase.PhaseEventBuilder)7 Test (org.testng.annotations.Test)7 UUID (java.util.UUID)6 TimedPhase (org.killbill.billing.subscription.alignment.TimedPhase)6 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)6 PhaseEvent (org.killbill.billing.subscription.events.phase.PhaseEvent)6 Product (org.killbill.billing.catalog.api.Product)5 PhaseEventData (org.killbill.billing.subscription.events.phase.PhaseEventData)5 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)4 Plan (org.killbill.billing.catalog.api.Plan)4 SubscriptionBuilder (org.killbill.billing.subscription.api.user.SubscriptionBuilder)4 BCDEventBuilder (org.killbill.billing.subscription.events.bcd.BCDEventBuilder)4