Skip to content

Commit

Permalink
Unit Price Override -Code refactoring and also modifying few existing…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
sruthipendyala committed Oct 27, 2016
1 parent bd4d80e commit 3c64441
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 231 deletions.
Expand Up @@ -103,7 +103,7 @@ public void testCreateSubscriptionWithEntitlementPlugin() throws Exception {
clock.setDay(new LocalDate(2012, 4, 1));

final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, BigDecimal.TEN));
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, BigDecimal.TEN, null));

testEntitlementPluginApi.setPlanPhasePriceOverride(overrides);

Expand Down
Expand Up @@ -57,7 +57,7 @@ public void testCreatWithFixedPriceOverride() throws Exception {
clock.setDay(new LocalDate(2012, 4, 1));

final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-trial", account.getCurrency(), BigDecimal.ONE, null));
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-trial", account.getCurrency(), BigDecimal.ONE, null, null));

final DefaultEntitlement bpSubscription = createBaseEntitlementWithPriceOverrideAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, overrides, NextEvent.CREATE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
// Check bundle after BP got created otherwise we get an error from auditApi.
Expand All @@ -77,7 +77,7 @@ public void testCreateWithRecurringPriceOverride() throws Exception {
clock.setDay(new LocalDate(2012, 4, 1));

final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, BigDecimal.TEN));
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, BigDecimal.TEN, null));

final DefaultEntitlement bpSubscription = createBaseEntitlementWithPriceOverrideAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, overrides, NextEvent.CREATE, NextEvent.INVOICE);
// Check bundle after BP got created otherwise we get an error from auditApi.
Expand Down Expand Up @@ -120,7 +120,7 @@ public void testChangePlanWithRecurringPriceOverride() throws Exception {
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("249.95")));

final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, new BigDecimal("279.95")));
overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, new BigDecimal("279.95"), null));

busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
bpSubscription.changePlanOverrideBillingPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, overrides, new LocalDate(2012, 5, 1), BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext);
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testChangePlanWithRecurringPriceOverrideAndSamePlan() throws Excepti
clock.addDays(4);

final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
overrides.add(new DefaultPlanPhasePriceOverride("telescopic-scope-monthly-evergreen", account.getCurrency(), null, new BigDecimal("1200.00")));
overrides.add(new DefaultPlanPhasePriceOverride("telescopic-scope-monthly-evergreen", account.getCurrency(), null, new BigDecimal("1200.00"), null));

busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
aoEntitlement.changePlanOverrideBillingPolicy("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, overrides, new LocalDate(2012, 5, 5), BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext);
Expand Down
Expand Up @@ -91,7 +91,7 @@ public ValidationErrors validate(final StandaloneCatalog catalog, final Validati
}


public DefaultBlock(final DefaultUnit unit, final Double size,final DefaultInternationalPrice prices, final BigDecimal overriddenPrice, Currency currency) {
public DefaultBlock(final DefaultUnit unit, final Double size, final DefaultInternationalPrice prices, final BigDecimal overriddenPrice, Currency currency) {

this.unit = unit;
this.size = size;
Expand Down
Expand Up @@ -62,7 +62,6 @@ public DefaultInternationalPrice(final DefaultInternationalPrice in, final PlanP

public DefaultInternationalPrice(final DefaultInternationalPrice in, final BigDecimal overriddenPrice, final Currency currency) {
this.prices = in.getPrices() != null ? new DefaultPrice[in.getPrices().length] : null;
// There is a question on whether we keep the other prices that were not overridden or only have one entry for the overridden price on that currency.
for (int i = 0; i < in.getPrices().length; i++) {
final DefaultPrice curPrice = (DefaultPrice) in.getPrices()[i];
if (curPrice.getCurrency().equals(currency)){
Expand Down
Expand Up @@ -83,6 +83,7 @@ public DefaultUsage() {
public DefaultUsage(final Usage in, UsagePriceOverride override, Currency currency) {
this.name = in.getName();
this.usageType = in.getUsageType();
this.billingPeriod = in.getBillingPeriod();
this.billingMode = in.getBillingMode();
this.limits = (DefaultLimit[]) in.getLimits();
this.blocks = (DefaultBlock[]) in.getBlocks();
Expand Down

0 comments on commit 3c64441

Please sign in to comment.