@Test(groups = "fast") public void testNullEffectiveDateWithBCDAfterComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z => New time = 2012-06-07T00:03:42.000Z (and june only has 30 days) clock.addMonths(1); int newBCD = 31; // effectiveDate = 2012-06-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = null; // newBCD > 30 (max day in June) final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-06-30"))); }
@Test(groups = "fast") public void testEquals() throws Exception { final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY; final long recordId = Long.MAX_VALUE; final ChangeType changeType = ChangeType.DELETE; final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null); final UUID accountId = UUID.randomUUID(); final UUID tenantId = UUID.randomUUID(); final String userName = UUID.randomUUID().toString(); final CallOrigin callOrigin = CallOrigin.EXTERNAL; final UserType userType = UserType.CUSTOMER; final UUID userToken = UUID.randomUUID(); final DefaultCallContext callContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao auditLog = new AuditLogModelDao(entityAudit, callContext); Assert.assertEquals(auditLog, auditLog); final AuditLogModelDao sameAuditLog = new AuditLogModelDao(entityAudit, callContext); Assert.assertEquals(sameAuditLog, auditLog); clock.addMonths(1); final DefaultCallContext otherCallContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext); Assert.assertNotEquals(otherAuditLog, auditLog); } }
@Test(groups = "fast", description = "Verify Mockito setup in GuicyKillbillTestSuite") public void testSpy() { clock.setDay(new LocalDate("2012-08-01")); Assert.assertEquals(clock.getUTCToday().toString(), "2012-08-01"); Assert.assertEquals(theRealClock.getUTCToday().toString(), "2012-08-01"); clock.addMonths(1); Assert.assertEquals(clock.getUTCToday().toString(), "2012-09-01"); Assert.assertEquals(theRealClock.getUTCToday().toString(), "2012-09-01"); clock.addDays(30); Assert.assertEquals(clock.getUTCToday().toString(), "2012-10-01"); Assert.assertEquals(theRealClock.getUTCToday().toString(), "2012-10-01"); } }
@Test(groups = "slow") public void testCancelUncancelFutureSubscription() throws SubscriptionBaseApiException { final LocalDate init = clock.getUTCToday(); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate futureCreationDate = init.plusDays(10); DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, futureCreationDate); assertListenerStatus(); assertNotNull(subscription); assertEquals(subscription.getState(), EntitlementState.PENDING); // Cancel / Uncancel a few times to make sure this works and we end up on a stable state for (int i = 0; i < 3; i++) { subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription.getState(), EntitlementState.PENDING); testListener.pushExpectedEvents(NextEvent.UNCANCEL); subscription.uncancel(callContext); assertListenerStatus(); } // Now check we are on the right state (as if nothing had happened) testListener.pushExpectedEvents(NextEvent.CREATE); clock.addDays(10); assertListenerStatus(); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription.getState(), EntitlementState.ACTIVE); testListener.pushExpectedEvent(NextEvent.PHASE); clock.addMonths(1); assertListenerStatus(); }
testListener.pushExpectedEvent(NextEvent.CANCEL); testListener.pushExpectedEvent(NextEvent.CANCEL); clock.addMonths(1); assertListenerStatus();
@Override public Void apply(@Nullable final Void dontcare) { clock.addMonths(nbMonth); return null; } }, events);
@PUT @Path("/clock") @Produces(APPLICATION_JSON) @ApiOperation(value = "Move the current time", response = ClockResource.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid timezone supplied")}) public Response updateTestClockTime(@QueryParam("days") final Integer addDays, @QueryParam("weeks") final Integer addWeeks, @QueryParam("months") final Integer addMonths, @QueryParam("years") final Integer addYears, @QueryParam("timeZone") final String timeZoneStr, @QueryParam("timeoutSec") @DefaultValue("5") final Long timeoutSec, @javax.ws.rs.core.Context final HttpServletRequest request) { final ClockMock testClock = getClockMock(); if (addDays != null) { testClock.addDays(addDays); } else if (addWeeks != null) { testClock.addWeeks(addWeeks); } else if (addMonths != null) { testClock.addMonths(addMonths); } else if (addYears != null) { testClock.addYears(addYears); } waitForNotificationToComplete(request, timeoutSec); return getCurrentTime(timeZoneStr); }
@Test(groups = "fast") public void testNullEffectiveDateWithBCDAfterComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z => New time = 2012-06-07T00:03:42.000Z (and june only has 30 days) clock.addMonths(1); int newBCD = 31; // effectiveDate = 2012-06-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = null; // newBCD > 30 (max day in June) final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-06-30"))); }
@Test(groups = "fast") public void testEquals() throws Exception { final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY; final long recordId = Long.MAX_VALUE; final ChangeType changeType = ChangeType.DELETE; final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null); final UUID accountId = UUID.randomUUID(); final UUID tenantId = UUID.randomUUID(); final String userName = UUID.randomUUID().toString(); final CallOrigin callOrigin = CallOrigin.EXTERNAL; final UserType userType = UserType.CUSTOMER; final UUID userToken = UUID.randomUUID(); final DefaultCallContext callContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao auditLog = new AuditLogModelDao(entityAudit, callContext); Assert.assertEquals(auditLog, auditLog); final AuditLogModelDao sameAuditLog = new AuditLogModelDao(entityAudit, callContext); Assert.assertEquals(sameAuditLog, auditLog); clock.addMonths(1); final DefaultCallContext otherCallContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext); Assert.assertNotEquals(otherAuditLog, auditLog); } }
@Test(groups = "fast", description = "Verify Mockito setup in GuicyKillbillTestSuite") public void testSpy() { clock.setDay(new LocalDate("2012-08-01")); Assert.assertEquals(clock.getUTCToday().toString(), "2012-08-01"); Assert.assertEquals(theRealClock.getUTCToday().toString(), "2012-08-01"); clock.addMonths(1); Assert.assertEquals(clock.getUTCToday().toString(), "2012-09-01"); Assert.assertEquals(theRealClock.getUTCToday().toString(), "2012-09-01"); clock.addDays(30); Assert.assertEquals(clock.getUTCToday().toString(), "2012-10-01"); Assert.assertEquals(theRealClock.getUTCToday().toString(), "2012-10-01"); } }
@Test(groups = "slow") public void testWithPriceOverride() throws Exception { // Create a per-tenant catalog with one plan final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("bar-monthly", "Bar", 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 Plan plan = catalog.getCurrentPlans().iterator().next(); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("bar-monthly", null); final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>(); overrides.add(new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), account.getCurrency(), null, BigDecimal.ONE, null)); final Entitlement baseEntitlement = createEntitlement(spec, overrides, true); List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, testCallContext); assertEquals(invoices.size(), 1); assertEquals(invoices.get(0).getChargedAmount().compareTo(BigDecimal.ONE), 0); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, testCallContext); assertEquals(invoices.size(), 2); assertEquals(invoices.get(1).getChargedAmount().compareTo(BigDecimal.ONE), 0); // Change plan to original (non overridden plan) busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); baseEntitlement.changePlan( new DefaultEntitlementSpecifier(spec), ImmutableList.<PluginProperty>of(), testCallContext); assertListenerStatus(); invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, testCallContext); assertEquals(invoices.size(), 3); assertEquals(invoices.get(2).getChargedAmount().compareTo(new BigDecimal("9.00")), 0); // 10 (recurring) - 1 (repair) }
@Test(groups = "slow") public void testCreateWithRecurringPriceOverride() throws Exception { // We take april as it has 30 days (easier to play with BCD) // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC clock.setDay(new LocalDate(2012, 4, 1)); final AccountData accountData = getAccountData(1); final Account account = createAccountWithNonOsgiPaymentMethod(accountData); accountChecker.checkAccount(account.getId(), accountData, callContext); final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>(); 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.BLOCK, NextEvent.INVOICE); // Check bundle after BP got created otherwise we get an error from auditApi. subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext); invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.FIXED, new BigDecimal("0"))); busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); clock.addDays(30); assertListenerStatus(); invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, BigDecimal.TEN)); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); clock.addMonths(1); assertListenerStatus(); invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.RECURRING, BigDecimal.TEN)); }
@Test(groups = "slow", description = "See https://github.com/killbill/killbill/issues/127#issuecomment-292445089") public void testIntegrationWithBCDLargerThanEndMonth() throws Exception { final int billingDay = 31; final DateTime initialCreationDate = new DateTime(2017, 01, 31, 0, 0, 0, 0, testTimeZone); // set clock to the initial start date clock.setTime(initialCreationDate); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null); busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); // 2017-02-28 busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); // 2017-03-31 busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); clock.addDays(3); assertListenerStatus(); // 2017-04-30 busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); }
@Test(groups = "slow") public void testBlockingStatesV2() throws Exception { final DateTime initialDate = new DateTime(2017, 3, 1, 0, 1, 35, 0, DateTimeZone.UTC); clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis()); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0)); assertNotNull(account); final BlockingState blockingState1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state1", "Service", false, false, true, null); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null); // Unlike the previous scenario, we create the subscription and set the blocking state at the same time busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE, NextEvent.BLOCK); subscriptionApi.addBlockingState(blockingState1, null, ImmutableList.<PluginProperty>of(), callContext); entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addMonths(1); busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); final BlockingState blockingState2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state2", "Service", false, false, false, null); subscriptionApi.addBlockingState(blockingState2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); }
@Test(groups = "slow") public void testCreateSubscriptionWithEntitlementPlugin() throws Exception { // We take april as it has 30 days (easier to play with BCD) // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC clock.setDay(new LocalDate(2012, 4, 1)); final AccountData accountData = getAccountData(1); final Account account = createAccountWithNonOsgiPaymentMethod(accountData); accountChecker.checkAccount(account.getId(), accountData, callContext); final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>(); overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-evergreen", account.getCurrency(), null, BigDecimal.TEN, null)); testEntitlementPluginApi.setPlanPhasePriceOverride(overrides); // // Create original subscription (Trial PHASE) -> $0 invoice. final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.FIXED, new BigDecimal("0"))); subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext); busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); clock.addDays(30); assertListenerStatus(); invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, BigDecimal.TEN)); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); clock.addMonths(1); assertListenerStatus(); invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.RECURRING, BigDecimal.TEN)); }
@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 UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(planPhaseSpec), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), testCallContext); assertListenerStatus(); final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlementId, testCallContext); 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)); }
@Test(groups = "slow") public void testBlockingStatesV1() throws Exception { final DateTime initialDate = new DateTime(2017, 3, 1, 0, 1, 35, 0, DateTimeZone.UTC); clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis()); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0)); assertNotNull(account); busHandler.pushExpectedEvents(NextEvent.BLOCK); final BlockingState blockingState1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state1", "Service", false, false, true, null); subscriptionApi.addBlockingState(blockingState1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addDays(1); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null); busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addMonths(1); busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); final BlockingState blockingState2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state2", "Service", false, false, false, null); subscriptionApi.addBlockingState(blockingState2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); }
@Test(groups = "slow") public void testCancelFutureSubscriptionWithPolicy() throws Exception { final LocalDate initialDate = new LocalDate(2015, 9, 1); clock.setDay(initialDate); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null); final LocalDate futureDate = new LocalDate(2015, 10, 1); // No CREATE event as this is set in the future final UUID createdEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), futureDate, futureDate, false, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement createdEntitlement = entitlementApi.getEntitlementForId(createdEntitlementId, callContext); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); assertListenerStatus(); final Entitlement cancelledEntitlement = createdEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, null, callContext); assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0); assertListenerStatus(); // Move off trial and reach start/cancellation date busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.NULL_INVOICE, NextEvent.NULL_INVOICE); clock.addDays(30); assertListenerStatus(); // Just to make sure we really don't invoice for anything move to next month clock.addMonths(1); assertListenerStatus(); }
@Test(groups = "slow") public void testIntoDaylightSavingTransition3() throws Exception { final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles"); clock.setTime(new DateTime(2017, 3, 1, 23, 30, 0, tz)); final AccountData accountData = new MockAccountBuilder().currency(Currency.USD) .timeZone(tz) .referenceTime(clock.getUTCNow()) .build(); // Create account with non BCD to force junction BCD logic to activate final Account account = createAccountWithNonOsgiPaymentMethod(accountData); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial",null); busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); // Technically, we should see the invoice at the end of day in the account timezone, but this is not the case, the invoice comes slightly after (30') // clock.setTime(new DateTime(2017, 4, 1, 23, 59, 0, tz)); // // But this is really not very important as long as invoicing is correct clock.addMonths(1); // Add one hour to hit the notification date of 2017-04-02T07:30:00.000Z clock.addDeltaFromReality(3600 * 1000); assertListenerStatus(); }