@Test(groups = "slow", retryAnalyzer = FlakyRetryAnalyzer.class) public void testFixUp() throws Exception { testListener.throwRetryableException = true; final DateTime startTime = clock.getUTCNow(); testListener.handleEvent(event); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); List<NotificationEventWithMetadata> futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(0))), 0); clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(1))), 0); testListener.throwRetryableException = false; clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 1); Assert.assertEquals(getFutureRetryableEvents().size(), 0); }
@Test(groups = "slow", retryAnalyzer = FlakyRetryAnalyzer.class) public void testGiveUp() throws Exception { testListener.throwRetryableException = true; final DateTime startTime = clock.getUTCNow(); testListener.handleEvent(event); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); List<NotificationEventWithMetadata> futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(0))), 0); clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(1))), 0); clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); // Give up Assert.assertEquals(getFutureRetryableEvents().size(), 0); }
@Test(groups = "slow") public void testChangePlanRightAfterCreate() throws SubscriptionBaseApiException { final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); clock.setTime(clock.getUTCNow().plusSeconds(1)); // CHANGE PLAN ALMOST IMMEDIATELY testListener.pushExpectedEvent(NextEvent.CHANGE); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); subscription.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), callContext); assertListenerStatus(); checkChangePlan(subscription, "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, PhaseType.TRIAL); final SubscriptionBase refreshedSubscription = subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(refreshedSubscription.getAllTransitions().size(), 3); assertEquals(refreshedSubscription.getAllTransitions().get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(refreshedSubscription.getAllTransitions().get(1).getTransitionType(), SubscriptionBaseTransitionType.CHANGE); assertEquals(refreshedSubscription.getAllTransitions().get(2).getTransitionType(), SubscriptionBaseTransitionType.PHASE); }
@Test(groups = "slow") public void testUndoChangePlan() throws SubscriptionBaseApiException { final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); clock.setTime(clock.getUTCNow().plusSeconds(1)); // Change plan in the future final DateTime targetDate = clock.getUTCNow().plusDays(3); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); subscription.changePlanWithDate(new DefaultEntitlementSpecifier(planPhaseSpecifier), targetDate, callContext);assertListenerStatus(); DefaultSubscriptionBase refreshedSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(refreshedSubscription.getAllTransitions().size(), 3); assertEquals(refreshedSubscription.getAllTransitions().get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(refreshedSubscription.getAllTransitions().get(1).getTransitionType(), SubscriptionBaseTransitionType.CHANGE); assertEquals(refreshedSubscription.getAllTransitions().get(2).getTransitionType(), SubscriptionBaseTransitionType.PHASE); clock.addDays(1); testListener.pushExpectedEvent(NextEvent.UNDO_CHANGE); subscription.undoChangePlan(callContext); assertListenerStatus(); // No CHANGE_PLAN clock.addDays(3); assertListenerStatus(); // Verify PHASE event for Shotgun is active testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDays(26); assertListenerStatus(); refreshedSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(refreshedSubscription.getAllTransitions().size(), 2); assertEquals(refreshedSubscription.getAllTransitions().get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(refreshedSubscription.getAllTransitions().get(1).getTransitionType(), SubscriptionBaseTransitionType.PHASE); }
@Override public Void apply(@Nullable final Void dontcare) { //final Interval it = new Interval(clock.getUTCNow(), date); //final int days = it.toPeriod().toStandardDays().getDays(); clock.setTime(date); return null; } }, events);
@POST @Path("/clock") @Produces(APPLICATION_JSON) @ApiOperation(value = "Set the current time", response = ClockResource.class) @ApiResponses(value = {/* @ApiResponse(code = 200, message = "Successful"), */ @ApiResponse(code = 400, message = "Invalid time or timezone supplied")}) public Response setTestClockTime(@QueryParam(QUERY_REQUESTED_DT) final String requestedClockDate, @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 (requestedClockDate == null) { testClock.resetDeltaFromReality(); } else { final DateTime newTime = DATE_TIME_FORMATTER.parseDateTime(requestedClockDate).toDateTime(DateTimeZone.UTC); testClock.setTime(newTime); } waitForNotificationToComplete(request, timeoutSec); return getCurrentTime(timeZoneStr); }
@Test(groups = "fast") public void testIsBeforeOrEqualsToday() throws AccountApiException { clock.setTime(new DateTime(2013, 8, 7, 3, 28, 10, 0, DateTimeZone.UTC)); final DateTimeZone timeZoneUtcMinus8 = DateTimeZone.forOffsetHours(-8); createAccount(timeZoneUtcMinus8, clock.getUTCNow()); final DateTime inputDateEquals = new DateTime(2013, 8, 6, 23, 28, 10, 0, timeZoneUtcMinus8); // Check that our input date is greater than now assertTrue(inputDateEquals.compareTo(clock.getUTCNow()) > 0); // And yet since the LocalDate match the function returns true assertTrue(isBeforeOrEqualsToday(inputDateEquals, timeZoneUtcMinus8, internalCallContext)); }
@Test(groups = "slow", expectedExceptions = InvoiceApiException.class, expectedExceptionsMessageRegExp = ".* does not have a Parent Account associated") public void testParentInvoiceTransferCreditAccountNoParent() throws Exception { final int billingDay = 14; final DateTime initialCreationDate = new DateTime(2014, 5, 15, 0, 0, 0, 0, testTimeZone); // set clock to the initial start date clock.setTime(initialCreationDate); final Account account = createAccountWithNonOsgiPaymentMethod(getChildAccountData(billingDay, null, true)); BigDecimal childAccountCBA = invoiceUserApi.getAccountCBA(account.getId(), callContext); assertEquals(childAccountCBA.compareTo(BigDecimal.ZERO), 0); invoiceUserApi.transferChildCreditToParent(account.getId(), callContext); }
@Test(groups = "slow", retryAnalyzer = FlakyRetryAnalyzer.class) public void testFixUp() throws Exception { testListener.throwRetryableException = true; final DateTime startTime = clock.getUTCNow(); testListener.handleEvent(event); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); List<NotificationEventWithMetadata> futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(0))), 0); clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(1))), 0); testListener.throwRetryableException = false; clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 1); Assert.assertEquals(getFutureRetryableEvents().size(), 0); }
@Test(groups = "slow") public void testDryRunTargetDateWithLeadingProration() throws Exception { final DateTime initialCreationDate = new DateTime(2014, 1, 2, 0, 0, 0, 0, testTimeZone); clock.setTime(initialCreationDate); // billing date for the monthly final int billingDay = 14; final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay)); // Create the monthly createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>(); expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2014, 2, 1), new LocalDate(2014, 2, 14), InvoiceItemType.RECURRING, new BigDecimal("104.82"))); Invoice dryRunInvoice = invoiceUserApi.triggerDryRunInvoiceGeneration(account.getId(), new LocalDate(2014, 2, 13), DRY_RUN_TARGET_DATE_ARG, callContext); assertEquals(dryRunInvoice.getTargetDate(), new LocalDate(2014, 2, 1)); invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, expectedInvoices); expectedInvoices.clear(); expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2014, 2, 14), new LocalDate(2014, 3, 14), InvoiceItemType.RECURRING, new BigDecimal("249.95"))); dryRunInvoice = invoiceUserApi.triggerDryRunInvoiceGeneration(account.getId(), new LocalDate(2014, 2, 14), DRY_RUN_TARGET_DATE_ARG, callContext); assertEquals(dryRunInvoice.getTargetDate(), new LocalDate(2014, 2, 14)); invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, expectedInvoices); expectedInvoices.clear(); }
@Test(groups = "slow", retryAnalyzer = FlakyRetryAnalyzer.class) public void testGiveUp() throws Exception { testListener.throwRetryableException = true; final DateTime startTime = clock.getUTCNow(); testListener.handleEvent(event); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); List<NotificationEventWithMetadata> futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(0))), 0); clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); futureRetryableEvents = getFutureRetryableEvents(); Assert.assertEquals(futureRetryableEvents.size(), 1); Assert.assertEquals(futureRetryableEvents.get(0).getEffectiveDate().compareTo(startTime.plus(RETRY_SCHEDULE.get(1))), 0); clock.setTime(futureRetryableEvents.get(0).getEffectiveDate()); assertListenerStatus(); Assert.assertEquals(testListener.eventsSeen.size(), 0); // Give up Assert.assertEquals(getFutureRetryableEvents().size(), 0); }
@Test(groups = "slow") public void testPaginationForPaymentByStatesAcrossTenants() throws Exception { final DateTime createdDate1 = clock.getUTCNow().minusHours(1); clock.setTime(createdDate1); final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final int NB_ENTRIES = 30; for (int i = 0; i < NB_ENTRIES; i++) { final PaymentModelDao paymentModelDao1 = new PaymentModelDao(createdDate1, createdDate1, account.getId(), account.getPaymentMethodId(), UUID.randomUUID().toString()); final PaymentTransactionModelDao transaction1 = new PaymentTransactionModelDao(createdDate1, createdDate1, null, UUID.randomUUID().toString(), paymentModelDao1.getId(), TransactionType.AUTHORIZE, createdDate1, TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED, "unknown", ""); paymentDao.insertPaymentWithFirstTransaction(paymentModelDao1, transaction1, internalCallContext); } clock.setTime(createdDate1.plusHours(1)); final Pagination<PaymentTransactionModelDao> result = paymentDao.getByTransactionStatusAcrossTenants(ImmutableList.of(TransactionStatus.UNKNOWN), clock.getUTCNow(), createdDate1, 0L, (long) NB_ENTRIES); Assert.assertEquals(result.getTotalNbRecords(), new Long(NB_ENTRIES)); final Iterator<PaymentTransactionModelDao> iterator = result.iterator(); for (int i = 0; i < NB_ENTRIES; i++) { Assert.assertTrue(iterator.hasNext()); final PaymentTransactionModelDao nextEntry = iterator.next(); Assert.assertEquals(nextEntry.getTransactionStatus(), TransactionStatus.UNKNOWN); } }
@Test(groups = "slow") public void testWithBusEvents() throws Exception { final DateTime initialDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone); clock.setTime(initialDate); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(2)); assertNotNull(account); final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); assertNotNull(bpEntitlement); await().atMost(10, SECONDS) .until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { // Expecting ACCOUNT_CREATE, ACCOUNT_CHANGE, SUBSCRIPTION_CREATION (2), ENTITLEMENT_CREATE INVOICE_CREATION return externalBusCount.get() == 6; } }); }
@Test(groups = "slow") public void testPaymentAttemptsByStateAcrossTenants() throws Exception { final String externalKey1 = "gfhfg"; final String transactionExternalKey1 = "sadas"; final String externalKey2 = "asdwqeqw"; final String transactionExternalKey2 = "fghfg"; final DateTime createdAfterDate = clock.getUTCNow().minusDays(10); final DateTime createdBeforeDate = clock.getUTCNow().minusDays(1); final String stateName = "FOO"; final String pluginName = "miraculous"; clock.setTime(createdAfterDate); Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final PaymentAttemptModelDao attempt1 = new PaymentAttemptModelDao(account.getId(), account.getPaymentMethodId(), createdAfterDate, createdAfterDate, externalKey1, UUID.randomUUID(), transactionExternalKey1, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD, ImmutableList.<String>of(pluginName), null); paymentDao.insertPaymentAttemptWithProperties(attempt1, internalCallContext); account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final PaymentAttemptModelDao attempt2 = new PaymentAttemptModelDao(account.getId(), account.getPaymentMethodId(), createdAfterDate, createdAfterDate, externalKey2, UUID.randomUUID(), transactionExternalKey2, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD, ImmutableList.<String>of(pluginName), null); paymentDao.insertPaymentAttemptWithProperties(attempt2, internalCallContext); final Pagination<PaymentAttemptModelDao> result = paymentDao.getPaymentAttemptsByStateAcrossTenants(stateName, createdBeforeDate, 0L, 2L); Assert.assertEquals(result.getTotalNbRecords().longValue(), 2L); }
@Test(groups = "slow", expectedExceptions = InvoiceApiException.class, expectedExceptionsMessageRegExp = ".* does not have credit") public void testParentInvoiceTransferCreditAccountWithoutCredit() throws Exception { final int billingDay = 14; final DateTime initialCreationDate = new DateTime(2014, 5, 15, 0, 0, 0, 0, testTimeZone); // set clock to the initial start date clock.setTime(initialCreationDate); final Account parentAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay)); final Account childAccount = createAccountWithNonOsgiPaymentMethod(getChildAccountData(billingDay, parentAccount.getId(), true)); BigDecimal childAccountCBA = invoiceUserApi.getAccountCBA(childAccount.getId(), callContext); assertEquals(childAccountCBA.compareTo(BigDecimal.ZERO), 0); BigDecimal parentAccountCBA = invoiceUserApi.getAccountCBA(parentAccount.getId(), callContext); assertEquals(parentAccountCBA.compareTo(BigDecimal.ZERO), 0); invoiceUserApi.transferChildCreditToParent(childAccount.getId(), callContext); }
@Test(groups = "slow") public void testOutOfDaylightSavingTransition1() throws Exception { // Transition out of daylight saving is set for Nov 5 // // Because we use 30 days trial, we start a bit before and that way we can check that computation of BCD crossing out of of daylight saving works as expected. // final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles"); clock.setTime(new DateTime(2017, 11, 1, 00, 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); createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); final Account accountWithBCD = accountUserApi.getAccountById(account.getId(), callContext); assertEquals(accountWithBCD.getBillCycleDayLocal().intValue(), 1); busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); clock.addDays(30); assertListenerStatus(); final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>(); expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2017, 12, 1), new LocalDate(2018, 1, 1), InvoiceItemType.RECURRING, new BigDecimal("29.95"))); invoiceChecker.checkInvoice(account.getId(), 2, callContext, expectedInvoices); expectedInvoices.clear(); }
@Test(groups = "slow") public void testChangePlanRightAfterCreate() throws SubscriptionBaseApiException { final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); clock.setTime(clock.getUTCNow().plusSeconds(1)); // CHANGE PLAN ALMOST IMMEDIATELY testListener.pushExpectedEvent(NextEvent.CHANGE); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); subscription.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), callContext); assertListenerStatus(); checkChangePlan(subscription, "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, PhaseType.TRIAL); final SubscriptionBase refreshedSubscription = subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(refreshedSubscription.getAllTransitions().size(), 3); assertEquals(refreshedSubscription.getAllTransitions().get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(refreshedSubscription.getAllTransitions().get(1).getTransitionType(), SubscriptionBaseTransitionType.CHANGE); assertEquals(refreshedSubscription.getAllTransitions().get(2).getTransitionType(), SubscriptionBaseTransitionType.PHASE); }
@Test(groups = "slow") public void testWithWrittenOffInvoice() throws Exception { clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0)); // Put the account in AUTO_PAY_OFF to make sure payment system does not try to pay initial invoices add_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT); // set next invoice to fail and create network final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); assertNotNull(bpEntitlement); List<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 1); busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE); clock.addDays(31); assertListenerStatus(); invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 2); // Tag non $0 invoice with WRITTEN_OFF and remove AUTO_PAY_OFF => System should still not pay anything add_WRITTEN_OFF_Tag(invoices.get(1).getId(), ObjectType.INVOICE); remove_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT); assertListenerStatus(); List<Payment> accountPayments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(accountPayments.size(), 0); }
@Test(groups = "slow") public void testAutoInvoiceOffAccount() throws Exception { clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0)); add_AUTO_INVOICING_OFF_Tag(account.getId(), ObjectType.ACCOUNT); // set next invoice to fail and create network final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK); assertNotNull(bpEntitlement); Collection<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 0); clock.addDays(10); // DAY 10 still in trial assertListenerStatus(); invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 0); busHandler.pushExpectedEvents(NextEvent.PHASE); clock.addDays(30); // DAY 40 out of trial assertListenerStatus(); invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 0); remove_AUTO_INVOICING_OFF_Tag(account.getId(), ObjectType.ACCOUNT, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 1); }
@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(); }