Search in sources :

Example 56 with PlanPhaseSpecifier

use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.

the class TestDefaultEntitlementApi method testCreateBaseWithEntitlementInTheFuture.

@Test(groups = "slow")
public void testCreateBaseWithEntitlementInTheFuture() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
    final LocalDate initialDate = new LocalDate(2013, 8, 7);
    clock.setDay(initialDate);
    final Account account = createAccount(getAccountData(7));
    final LocalDate entitlementDate = initialDate.plusDays(3);
    final LocalDate billingDate = null;
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    testListener.pushExpectedEvents(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.PENDING);
    assertEquals(entitlement.getEffectiveStartDate(), entitlementDate);
    testListener.pushExpectedEvents(NextEvent.BLOCK);
    clock.addDays(3);
    assertListenerStatus();
    final Entitlement entitlementActive = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlementActive.getState(), EntitlementState.ACTIVE);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 57 with PlanPhaseSpecifier

use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.

the class TestDefaultEntitlement method testCancelWithEntitlementDate.

@Test(groups = "slow")
public void testCancelWithEntitlementDate() throws AccountApiException, EntitlementApiException {
    final LocalDate initialDate = new LocalDate(2013, 8, 7);
    clock.setDay(initialDate);
    final Account account = createAccount(getAccountData(7));
    final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    // Create entitlement and check each field
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(planPhaseSpecifier), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    assertEquals(entitlement.getState(), EntitlementState.ACTIVE);
    assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE);
    clock.addDays(5);
    testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK);
    entitlement.cancelEntitlementWithDate(null, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlement2.getState(), EntitlementState.CANCELLED);
    assertEquals(entitlement2.getEffectiveEndDate(), clock.getUTCToday());
    assertEquals(entitlement2.getSourceType(), EntitlementSourceType.NATIVE);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 58 with PlanPhaseSpecifier

use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.

the class TestDefaultEntitlement method testEntitlementChangePlanOnPendingEntitlement.

@Test(groups = "slow")
public void testEntitlementChangePlanOnPendingEntitlement() throws AccountApiException, EntitlementApiException {
    final LocalDate initialDate = new LocalDate(2013, 8, 7);
    clock.setDay(initialDate);
    final LocalDate startDate = initialDate.plusDays(10);
    final Account account = accountApi.createAccount(getAccountData(7), callContext);
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    // Create entitlement and check each field
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), startDate, startDate, false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    assertEquals(entitlement.getState(), EntitlementState.PENDING);
    final PlanPhaseSpecifier spec2 = new PlanPhaseSpecifier("pistol-monthly", null);
    try {
        entitlement.changePlan(new DefaultEntitlementSpecifier(spec2), ImmutableList.<PluginProperty>of(), callContext);
        fail("Changing plan immediately prior the subscription is active is not allowed");
    } catch (EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_NON_ACTIVE.getCode());
    }
    try {
        entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), startDate.minusDays(1), ImmutableList.<PluginProperty>of(), callContext);
        fail("Changing plan immediately prior the subscription is active is not allowed");
    } catch (EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_NON_ACTIVE.getCode());
    }
    entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), startDate, ImmutableList.<PluginProperty>of(), callContext);
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    clock.addDays(10);
    assertListenerStatus();
    final Entitlement entitlement1 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlement1.getState(), EntitlementState.ACTIVE);
    assertEquals(entitlement1.getLastActiveProduct().getName(), "Pistol");
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 59 with PlanPhaseSpecifier

use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.

the class TestDefaultEntitlement method testUncancelEntitlementFor_STANDALONE_Product.

@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/840")
public void testUncancelEntitlementFor_STANDALONE_Product() 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("Knife", BillingPeriod.MONTHLY, "notrial", null);
    // Create entitlement and check each field
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    assertEquals(entitlement.getState(), EntitlementState.ACTIVE);
    clock.addDays(5);
    final LocalDate cancelDate = new LocalDate(clock.getUTCToday().plusDays(1));
    entitlement.cancelEntitlementWithDate(cancelDate, true, ImmutableList.<PluginProperty>of(), callContext);
    final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlement2.getState(), EntitlementState.ACTIVE);
    assertEquals(entitlement2.getEffectiveEndDate(), cancelDate);
    testListener.pushExpectedEvents(NextEvent.UNCANCEL);
    entitlement2.uncancelEntitlement(ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    clock.addDays(1);
    final Entitlement entitlement3 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlement3.getState(), EntitlementState.ACTIVE);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 60 with PlanPhaseSpecifier

use of org.killbill.billing.catalog.api.PlanPhaseSpecifier in project killbill by killbill.

the class TestDefaultEntitlement method testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange.

@Test(groups = "slow")
public void testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange() throws AccountApiException, EntitlementApiException, SubscriptionApiException, InterruptedException {
    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 UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    // Make sure CHANGE does not collide with CREATE
    clock.addDeltaFromReality(1000);
    assertListenerStatus();
    // Immediate change during trial
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
    entitlement.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Verify the change is immediate
    final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlement2.getLastActivePlan().getProduct().getName(), "Assault-Rifle");
    testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK);
    final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithPolicy(EntitlementActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    assertEquals(cancelledEntitlement.getState(), EntitlementState.CANCELLED);
    assertEquals(cancelledEntitlement.getEffectiveEndDate(), initialDate);
    // Entitlement started in trial on 2013-08-07, which is when we want the billing cancellation date to occur
    final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(entitlement.getBaseEntitlementId(), callContext);
    assertEquals(subscription.getBillingEndDate(), new LocalDate(2013, 8, 7));
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)220 Test (org.testng.annotations.Test)181 LocalDate (org.joda.time.LocalDate)153 Account (org.killbill.billing.account.api.Account)144 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)140 UUID (java.util.UUID)129 DateTime (org.joda.time.DateTime)79 Entitlement (org.killbill.billing.entitlement.api.Entitlement)68 BigDecimal (java.math.BigDecimal)63 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)61 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)59 Invoice (org.killbill.billing.invoice.api.Invoice)42 ArrayList (java.util.ArrayList)30 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)29 AccountData (org.killbill.billing.account.api.AccountData)23 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)22 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)19 EntitlementSpecifier (org.killbill.billing.entitlement.api.EntitlementSpecifier)18 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)17 Plan (org.killbill.billing.catalog.api.Plan)16