Search in sources :

Example 36 with Entitlement

use of org.killbill.billing.entitlement.api.Entitlement in project killbill by killbill.

the class TestBlockingApi method testBlockingAcrossTypes.

@Test(groups = "slow")
public void testBlockingAcrossTypes() throws Exception {
    final String stateNameBlock = "stateBlock";
    final String stateNameUnBlock = "stateUnBlock";
    final String service = "SVC_BLOC_TYPES";
    final boolean blockChange = false;
    final boolean blockEntitlement = true;
    final boolean blockBilling = false;
    final Account account = createAccount(getAccountData(7));
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, stateNameBlock, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
    subscriptionApi.addBlockingState(state1, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    Entitlement baseEntitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    assertEquals(baseEntitlement.getState(), EntitlementState.BLOCKED);
    // Add blocking at bundle level.
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state2 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, stateNameBlock, service, blockChange, blockEntitlement, blockBilling, null);
    subscriptionApi.addBlockingState(state2, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
    assertEquals(baseEntitlement.getState(), EntitlementState.BLOCKED);
    // Remove blocking at account level
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state3 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, stateNameUnBlock, service, false, false, false, clock.getUTCNow());
    subscriptionApi.addBlockingState(state3, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
    assertEquals(baseEntitlement.getState(), EntitlementState.BLOCKED);
    // Remove blocking at bundle level.
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state4 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, stateNameUnBlock, service, false, false, false, null);
    subscriptionApi.addBlockingState(state4, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
    assertEquals(baseEntitlement.getState(), EntitlementState.ACTIVE);
    final List<BlockingState> blockingAll = blockingInternalApi.getBlockingAllForAccount(internalCallContext);
    final List<BlockingState> history = ImmutableList.<BlockingState>copyOf(Collections2.<BlockingState>filter(blockingAll, new Predicate<BlockingState>() {

        @Override
        public boolean apply(final BlockingState input) {
            return input.getService().equals(service);
        }
    }));
    Assert.assertEquals(history.size(), 4);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) Entitlement(org.killbill.billing.entitlement.api.Entitlement) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 37 with Entitlement

use of org.killbill.billing.entitlement.api.Entitlement in project killbill by killbill.

the class TestIntegrationBase method cancelEntitlementAndCheckForCompletion.

protected DefaultEntitlement cancelEntitlementAndCheckForCompletion(final Entitlement entitlement, final LocalDate requestedDate, final NextEvent... events) {
    return (DefaultEntitlement) doCallAndCheckForCompletion(new Function<Void, Entitlement>() {

        @Override
        public Entitlement apply(@Nullable final Void dontcare) {
            try {
                // Need to fetch again to get latest CTD updated from the system
                Entitlement refreshedEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
                refreshedEntitlement = refreshedEntitlement.cancelEntitlementWithDate(requestedDate, false, ImmutableList.<PluginProperty>of(), callContext);
                return refreshedEntitlement;
            } catch (final EntitlementApiException e) {
                fail(e.getMessage());
                return null;
            }
        }
    }, events);
}
Also used : Function(com.google.common.base.Function) PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Nullable(javax.annotation.Nullable)

Example 38 with Entitlement

use of org.killbill.billing.entitlement.api.Entitlement in project killbill by killbill.

the class TestIntegrationWithCatalogUpdate method testBasic.

@Test(groups = "slow")
public void testBasic() throws Exception {
    // Create a per-tenant catalog with one plan
    final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc1, init, testCallContext);
    StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 1);
    final Entitlement baseEntitlement = createEntitlement("foo-monthly", true);
    invoiceChecker.checkInvoice(account.getId(), 1, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, BigDecimal.TEN));
    // Add another Plan in the catalog
    final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("superfoo-monthly", "SuperFoo", ProductCategory.BASE, account.getCurrency(), new BigDecimal("20.00"), BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc2, init, testCallContext);
    catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 2);
    // Change Plan to the newly added Plan and verify correct default rules behavior (IMMEDIATE change)
    busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    baseEntitlement.changePlan(new PlanSpecifier("SuperFoo", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, ImmutableList.<PluginProperty>of(), testCallContext);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 2, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, new BigDecimal("20.00")), new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-10.00")));
    assertListenerStatus();
}
Also used : Entitlement(org.killbill.billing.entitlement.api.Entitlement) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) BigDecimal(java.math.BigDecimal) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 39 with Entitlement

use of org.killbill.billing.entitlement.api.Entitlement in project killbill by killbill.

the class TestIntegrationWithCatalogUpdate method testWithWeeklyTrials.

@Test(groups = "slow")
public void testWithWeeklyTrials() throws Exception {
    // Create a per-tenant catalog with one plan
    final SimplePlanDescriptor simplePlanDescriptor = new DefaultSimplePlanDescriptor("hello-monthly", "Hello", ProductCategory.BASE, account.getCurrency(), BigDecimal.ONE, BillingPeriod.MONTHLY, 1, TimeUnit.WEEKS, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(simplePlanDescriptor, init, testCallContext);
    StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 1);
    final PlanPhaseSpecifier planPhaseSpec = new PlanPhaseSpecifier("hello-monthly", null);
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    final Entitlement baseEntitlement = entitlementApi.createBaseEntitlement(account.getId(), planPhaseSpec, UUID.randomUUID().toString(), ImmutableList.<PlanPhasePriceOverride>of(), null, null, false, ImmutableList.<PluginProperty>of(), testCallContext);
    assertListenerStatus();
    Subscription refreshedBaseEntitlement = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), testCallContext);
    assertEquals(refreshedBaseEntitlement.getChargedThroughDate(), new LocalDate(2016, 6, 1));
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addWeeks(1);
    assertListenerStatus();
    refreshedBaseEntitlement = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), testCallContext);
    assertEquals(refreshedBaseEntitlement.getChargedThroughDate(), new LocalDate(2016, 7, 8));
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    refreshedBaseEntitlement = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), testCallContext);
    assertEquals(refreshedBaseEntitlement.getChargedThroughDate(), new LocalDate(2016, 8, 8));
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Subscription(org.killbill.billing.entitlement.api.Subscription) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) LocalDate(org.joda.time.LocalDate) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) Test(org.testng.annotations.Test)

Example 40 with Entitlement

use of org.killbill.billing.entitlement.api.Entitlement in project killbill by killbill.

the class TestIntegrationWithCatalogUpdate method testWithMultiplePlansForOneProduct.

@Test(groups = "slow")
public void testWithMultiplePlansForOneProduct() throws CatalogApiException, EntitlementApiException {
    // Create a per-tenant catalog with one plan
    final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("xxx-monthly", "XXX", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc1, init, testCallContext);
    StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentProducts().size(), 1);
    assertEquals(catalog.getCurrentPlans().size(), 1);
    final Entitlement baseEntitlement1 = createEntitlement("xxx-monthly", true);
    // Add a second plan for same product but with a 14 days trial
    final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("xxx-14-monthly", "XXX", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc2, init, testCallContext);
    catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentProducts().size(), 1);
    assertEquals(catalog.getCurrentPlans().size(), 2);
    final Entitlement baseEntitlement2 = createEntitlement("xxx-14-monthly", false);
    // Add a second plan for same product but with a 30 days trial
    final SimplePlanDescriptor desc3 = new DefaultSimplePlanDescriptor("xxx-30-monthly", "XXX", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc3, init, testCallContext);
    catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentProducts().size(), 1);
    assertEquals(catalog.getCurrentPlans().size(), 3);
    final Entitlement baseEntitlement3 = createEntitlement("xxx-30-monthly", false);
    // Move clock 14 days
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addDays(14);
    assertListenerStatus();
    // Move clock 16 days
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.NULL_INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addDays(16);
    assertListenerStatus();
}
Also used : Entitlement(org.killbill.billing.entitlement.api.Entitlement) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) Test(org.testng.annotations.Test)

Aggregations

Entitlement (org.killbill.billing.entitlement.api.Entitlement)47 LocalDate (org.joda.time.LocalDate)32 Test (org.testng.annotations.Test)30 Account (org.killbill.billing.account.api.Account)28 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)27 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)23 ArrayList (java.util.ArrayList)12 DateTime (org.joda.time.DateTime)12 BigDecimal (java.math.BigDecimal)10 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)10 PluginProperty (org.killbill.billing.payment.api.PluginProperty)10 UUID (java.util.UUID)9 CallContext (org.killbill.billing.util.callcontext.CallContext)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Produces (javax.ws.rs.Produces)8 AccountData (org.killbill.billing.account.api.AccountData)8 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)8 Subscription (org.killbill.billing.entitlement.api.Subscription)8 Invoice (org.killbill.billing.invoice.api.Invoice)8