public static MockPlan createBicycleNoTrialEvergreen1USD() { return new MockPlan("BicycleNoTrialEvergreen1USD", MockProduct.createBicycle(), new DefaultPlanPhase[]{}, MockPlanPhase.createUSDMonthlyEvergreen("1.0", null), -1); }
public static MockPlan createHornMonthlyNoTrial1USD() { return new MockPlan("Horn1USD", MockProduct.createHorn(), new DefaultPlanPhase[]{}, MockPlanPhase.create1USDMonthlyEvergreen(), -1); }
protected BillingEvent createRealEvent(final DateTime effectiveDate, final SubscriptionBase subscription, final SubscriptionBaseTransitionType type) { final Account account = this.account; final Integer billCycleDay = 1; final PlanPhase planPhase = new MockPlanPhase(); final Plan plan = new MockPlan(); final BigDecimal fixedPrice = BigDecimal.TEN; final BigDecimal recurringPrice = BigDecimal.TEN; final Currency currency = Currency.USD; final String description = ""; final BillingModeType billingModeType = BillingModeType.IN_ADVANCE; final BillingPeriod billingPeriod = BillingPeriod.MONTHLY; final Long totalOrdering = 0L; final DateTimeZone tz = DateTimeZone.UTC; return new DefaultBillingEvent(account, subscription, effectiveDate, plan, planPhase, fixedPrice, recurringPrice, currency, billingPeriod, billCycleDay, billingModeType, description, totalOrdering, type, tz); }
@Test(groups = "fast") public void testZeroDollarEvents() throws InvoiceApiException, CatalogApiException { final Plan plan = new MockPlan(); final PlanPhase planPhase = createMockMonthlyPlanPhase(ZERO); final BillingEventSet events = new MockBillingEventSet(); final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1); events.add(createBillingEvent(UUID.randomUUID(), UUID.randomUUID(), targetDate, plan, planPhase, 1)); final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, targetDate, Currency.USD); assertEquals(invoice.getNumberOfItems(), 1); }
public static MockPlan createBicycleTrialEvergreen1USD() { return new MockPlan("BicycleTrialEvergreen1USD", MockProduct.createBicycle(), new DefaultPlanPhase[]{MockPlanPhase.create30DayTrial()}, MockPlanPhase.create1USDMonthlyEvergreen(), -1); }
public static MockPlan createPickupTrialEvergreen10USD() { return new MockPlan("PickupTrialEvergreen10USD", MockProduct.createPickup(), new DefaultPlanPhase[]{MockPlanPhase.create30DayTrial()}, MockPlanPhase.createUSDMonthlyEvergreen("10.00", null), -1); }
public static MockPlan createBicycleTrialEvergreen1USD(final int trialDurationInDays) { return new MockPlan("BicycleTrialEvergreen1USD", MockProduct.createBicycle(), new DefaultPlanPhase[]{MockPlanPhase.createTrial(trialDurationInDays)}, MockPlanPhase.create1USDMonthlyEvergreen(), -1); }
public static MockPlan createSportsCarTrialEvergreen100USD() { return new MockPlan("SportsCarTrialEvergreen100USD", MockProduct.createSportsCar(), new DefaultPlanPhase[]{MockPlanPhase.create30DayTrial()}, MockPlanPhase.createUSDMonthlyEvergreen("100.00", null), -1); }
public static MockPlan createJetTrialEvergreen1000USD() { return new MockPlan("JetTrialEvergreen1000USD", MockProduct.createJet(), new DefaultPlanPhase[]{MockPlanPhase.create30DayTrial()}, MockPlanPhase.create1USDMonthlyEvergreen(), -1); }
@Test(groups = "fast", expectedExceptions = {InvoiceApiException.class}) public void testTargetDateRestrictionFailure() throws InvoiceApiException, CatalogApiException { final LocalDate targetDate = clock.getUTCToday().plusMonths(60); final BillingEventSet events = new MockBillingEventSet(); final Plan plan1 = new MockPlan(); final PlanPhase phase1 = createMockMonthlyPlanPhase(null, ZERO, PhaseType.TRIAL); events.add(createBillingEvent(UUID.randomUUID(), UUID.randomUUID(), clock.getUTCToday(), plan1, phase1, 1)); generator.generateInvoice(UUID.randomUUID(), events, null, targetDate, Currency.USD); }
@Test(groups = "fast") public void testWithSingleMonthlyEventWithLeadingProRation() throws InvoiceApiException, CatalogApiException { final BillingEventSet events = new MockBillingEventSet(); final SubscriptionBase sub = createSubscription(); final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1); final Plan plan = new MockPlan(); final BigDecimal rate = TEN; final PlanPhase phase = createMockMonthlyPlanPhase(rate); final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 15); events.add(event); final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3); final UUID accountId = UUID.randomUUID(); final Invoice invoice = generator.generateInvoice(accountId, events, null, targetDate, Currency.USD); assertNotNull(invoice); assertEquals(invoice.getNumberOfItems(), 2); final BigDecimal expectedNumberOfBillingCycles; expectedNumberOfBillingCycles = ONE.add(FOURTEEN.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD)); final BigDecimal expectedAmount = expectedNumberOfBillingCycles.multiply(rate).setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD); assertEquals(invoice.getBalance(), expectedAmount); }
@Test(groups = "fast") public void testEndDateIsCorrect() throws InvoiceApiException, CatalogApiException { final Plan plan = new MockPlan(); final PlanPhase planPhase = createMockMonthlyPlanPhase(ZERO); final BillingEventSet events = new MockBillingEventSet(); final LocalDate startDate = clock.getUTCToday().minusDays(1); final LocalDate targetDate = startDate.plusDays(1); events.add(createBillingEvent(UUID.randomUUID(), UUID.randomUUID(), startDate, plan, planPhase, startDate.getDayOfMonth())); final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, targetDate, Currency.USD); final RecurringInvoiceItem item = (RecurringInvoiceItem) invoice.getInvoiceItems().get(0); // end date of the invoice item should be equal to exactly one month later (rounded) assertEquals(item.getEndDate(), startDate.plusMonths(1)); }
public static MockPlan createJetTrialFixedTermEvergreen1000USD() { return new MockPlan("JetTrialEvergreen1000USD", MockProduct.createJet(), new DefaultPlanPhase[]{MockPlanPhase.create30DayTrial(), MockPlanPhase.createUSDMonthlyFixedTerm("500.00", null, 6)}, MockPlanPhase.create1USDMonthlyEvergreen(), -1); }
private BillingEvent createEvent(final SubscriptionBase sub, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final long totalOrdering) { final int billCycleDay = 1; final Plan shotgun = new MockPlan(); final PlanPhase shotgunMonthly = createMockMonthlyPlanPhase(null, BigDecimal.ZERO, PhaseType.TRIAL); final Account account = new MockAccountBuilder().build(); return new DefaultBillingEvent(account, sub, effectiveDate, shotgun, shotgunMonthly, BigDecimal.ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay, BillingModeType.IN_ADVANCE, "Test Event 1", totalOrdering, type, DateTimeZone.UTC); }
public MockPlanPhase(@Nullable final MockInternationalPrice recurringPrice, @Nullable final MockInternationalPrice fixedPrice, final BillingPeriod billingPeriod, final PhaseType phaseType) { setBillingPeriod(billingPeriod); setPhaseType(phaseType); setDuration(new DefaultDuration().setNumber(-1).setUnit(TimeUnit.UNLIMITED)); setRecurringPrice(recurringPrice); setFixedPrice(fixedPrice); setPlan(new MockPlan(this)); }
@Test(groups = "fast") public void testSimpleWithSingleDiscountEvent() throws Exception { final UUID accountId = UUID.randomUUID(); final SubscriptionBase sub = createSubscription(); final Plan plan = new MockPlan("Plan with a single discount phase"); final PlanPhase phaseEvergreen = createMockMonthlyPlanPhase(EIGHT, PhaseType.DISCOUNT); final int bcdLocal = 16; final LocalDate startDate = invoiceUtil.buildDate(2012, 7, 16); final BillingEventSet events = new MockBillingEventSet(); events.add(createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phaseEvergreen, bcdLocal)); // Set a target date of today (start date) final LocalDate targetDate = startDate; final Invoice invoice = generator.generateInvoice(accountId, events, null, targetDate, Currency.USD); assertNotNull(invoice); assertEquals(invoice.getNumberOfItems(), 1); assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), invoiceUtil.buildDate(2012, 7, 16)); assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), invoiceUtil.buildDate(2012, 8, 16)); }
@Test(groups = "fast") public void testTwoMonthlySubscriptionsWithAlignedBillingDates() throws InvoiceApiException, CatalogApiException { final BillingEventSet events = new MockBillingEventSet(); final Plan plan1 = new MockPlan(); final BigDecimal rate1 = FIVE; final PlanPhase phase1 = createMockMonthlyPlanPhase(rate1); final Plan plan2 = new MockPlan(); final BigDecimal rate2 = TEN; final PlanPhase phase2 = createMockMonthlyPlanPhase(rate2); final SubscriptionBase sub = createSubscription(); final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 9, 1), plan1, phase1, 1); events.add(event1); final BillingEvent event2 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 10, 1), plan2, phase2, 1); events.add(event2); final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3); final UUID accountId = UUID.randomUUID(); final Invoice invoice = generator.generateInvoice(accountId, events, null, targetDate, Currency.USD); assertNotNull(invoice); assertEquals(invoice.getNumberOfItems(), 2); assertEquals(invoice.getBalance(), rate1.add(rate2).setScale(NUMBER_OF_DECIMALS)); }
@Test(groups = "fast") public void testSingleEventWithExistingInvoice() throws InvoiceApiException, CatalogApiException { final BillingEventSet events = new MockBillingEventSet(); final SubscriptionBase sub = createSubscription(); final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1); final Plan plan1 = new MockPlan(); final BigDecimal rate = FIVE; final PlanPhase phase1 = createMockMonthlyPlanPhase(rate); final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan1, phase1, 1); events.add(event1); LocalDate targetDate = invoiceUtil.buildDate(2011, 12, 1); final UUID accountId = UUID.randomUUID(); final Invoice invoice1 = generator.generateInvoice(accountId, events, null, targetDate, Currency.USD); final List<Invoice> existingInvoices = new ArrayList<Invoice>(); existingInvoices.add(invoice1); targetDate = invoiceUtil.buildDate(2011, 12, 3); final Invoice invoice2 = generator.generateInvoice(accountId, events, existingInvoices, targetDate, Currency.USD); assertNull(invoice2); }
@Test(groups = "fast") public void testAutoInvoiceOffAccount() throws Exception { final MockBillingEventSet events = new MockBillingEventSet(); events.setAccountInvoiceOff(true); final SubscriptionBase sub = createSubscription(); final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1); final Plan plan = new MockPlan(); final BigDecimal rate1 = TEN; final PlanPhase phase = createMockMonthlyPlanPhase(rate1); final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 1); events.add(event); final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3); final UUID accountId = UUID.randomUUID(); final Invoice invoice = generator.generateInvoice(accountId, events, null, targetDate, Currency.USD); assertNull(invoice); }
@Test(groups = "slow") public void testInvoiceForFreeTrial() throws InvoiceApiException, CatalogApiException { final Currency currency = Currency.USD; final DefaultPrice price = new DefaultPrice(BigDecimal.ZERO, Currency.USD); final MockInternationalPrice recurringPrice = new MockInternationalPrice(price); final MockPlanPhase phase = new MockPlanPhase(recurringPrice, null); final MockPlan plan = new MockPlan(phase); final SubscriptionBase subscription = getZombieSubscription(); final DateTime effectiveDate = invoiceUtil.buildDate(2011, 1, 1).toDateTimeAtStartOfDay(); final BillingEvent event = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate, plan, phase, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 15, BillingModeType.IN_ADVANCE, "testEvent", 1L, SubscriptionBaseTransitionType.CREATE); final BillingEventSet events = new MockBillingEventSet(); events.add(event); final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 15); final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, targetDate, Currency.USD); // expect one pro-ration item and one full-period item assertEquals(invoice.getNumberOfItems(), 2); assertEquals(invoice.getBalance().compareTo(ZERO), 0); }