use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestWithTimeZones method testCancellationFrom_PST_to_PDT.
// Same test as previous test but this time going from PST -> PDT (somehow not too interesting in that direction because we start with
// an offset of 8 hours and then go through 7 hours so anyway we would stay in the same day.
@Test(groups = "slow")
public void testCancellationFrom_PST_to_PDT() throws Exception {
clock.setTime(new DateTime("2015-02-01T08:01:01.000Z"));
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUID.randomUUID().toString().substring(1, 8)).phone(UUID.randomUUID().toString().substring(1, 8)).migrated(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).referenceTime(clock.getUTCNow()).timeZone(tz).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "Something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
// Cancel the next month specifying just a LocalDate
final LocalDate cancellationDate = new LocalDate("2015-03-01", tz);
entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
// Verify first entitlement is correctly cancelled on the right date
Assert.assertEquals(entitlement.getEffectiveEndDate(), cancellationDate);
// We now move the clock to the date of the cancellation which match the cancellation day from the client point of view
busHandler.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE, NextEvent.NULL_INVOICE);
clock.setTime(new DateTime("2015-03-01T08:01:02"));
assertListenerStatus();
// Verify second that there was no repair (so the cancellation did correctly happen on the "2015-12-01"
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext);
Assert.assertEquals(invoices.size(), 1);
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestMigrationSubscriptions method testBlockingStatesV3.
@Test(groups = "slow")
public void testBlockingStatesV3() throws Exception {
final DateTimeZone timeZone = DateTimeZone.forID("America/Los_Angeles");
// 2017-03-12 00:01:35 (change to DST happens at 2am on that day)
final DateTime initialDate = new DateTime(2017, 3, 12, 0, 1, 35, 0, timeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
// Account in PDT
final AccountData accountData = new MockAccountBuilder().currency(Currency.USD).timeZone(timeZone).referenceTime(clock.getUTCNow()).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
assertNotNull(account);
busHandler.pushExpectedEvent(NextEvent.TAG);
tagUserApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_INVOICING_OFF.getId(), callContext);
assertListenerStatus();
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();
// Add less than a day between the CREATE and the BLOCK, to verify invoicing behavior
clock.setTime(initialDate.plusHours(23).plusMinutes(30));
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();
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.NULL_INVOICE);
tagUserApi.removeTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_INVOICING_OFF.getId(), 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();
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestIntegration method testWithDayLightSaving.
@Test(groups = "slow")
public void testWithDayLightSaving() throws Exception {
clock.setTime(new DateTime("2015-09-01T08:01:01.000Z"));
final DateTimeZone tz = DateTimeZone.forID("America/Juneau");
final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUID.randomUUID().toString().substring(1, 8)).phone(UUID.randomUUID().toString().substring(1, 8)).migrated(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).referenceTime(clock.getUTCNow()).timeZone(tz).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
//
// CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
//
final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.ANNUAL, 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(2015, 9, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
assertListenerStatus();
//
// ADD ADD_ON ON THE SAME DAY
//
final DefaultEntitlement aoSubscription = addAOEntitlementAndCheckForCompletion(bpSubscription.getBundleId(), "Bullets", ProductCategory.ADD_ON, BillingPeriod.NO_BILLING_PERIOD, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.addDays(30);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2015, 10, 1), new LocalDate(2016, 10, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")), new ExpectedInvoiceItemCheck(new LocalDate(2015, 9, 1), new LocalDate(2015, 10, 1), InvoiceItemType.USAGE, BigDecimal.ZERO));
// 2015-11-1
busHandler.pushExpectedEvent(NextEvent.INVOICE);
clock.addMonths(1);
assertListenerStatus();
// 2015-12-1
busHandler.pushExpectedEvent(NextEvent.INVOICE);
clock.addMonths(1);
assertListenerStatus();
// We sleep to let system creates lots of notification if an infinite loop was indeed happening
Thread.sleep(3000);
// And then we check that we only have the expected number of notifications in the history table.
final Integer countNotifications = dbi.withHandle(new HandleCallback<Integer>() {
@Override
public Integer withHandle(final Handle handle) throws Exception {
List<Map<String, Object>> res = handle.select("select count(*) as count from notifications_history;");
final Integer count = Integer.valueOf(res.get(0).get("count").toString());
return count;
}
});
Assert.assertEquals(countNotifications.intValue(), 4);
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestAccountJson method testFromAccount.
@Test(groups = "fast")
public void testFromAccount() throws Exception {
final MockAccountBuilder accountBuilder = new MockAccountBuilder();
accountBuilder.address1(UUID.randomUUID().toString());
accountBuilder.address2(UUID.randomUUID().toString());
final int bcd = 4;
accountBuilder.billingCycleDayLocal(bcd);
accountBuilder.city(UUID.randomUUID().toString());
accountBuilder.companyName(UUID.randomUUID().toString());
accountBuilder.country(UUID.randomUUID().toString());
accountBuilder.currency(Currency.GBP);
accountBuilder.email(UUID.randomUUID().toString());
accountBuilder.externalKey(UUID.randomUUID().toString());
accountBuilder.firstNameLength(12);
accountBuilder.locale(UUID.randomUUID().toString());
accountBuilder.migrated(true);
accountBuilder.name(UUID.randomUUID().toString());
accountBuilder.paymentMethodId(UUID.randomUUID());
accountBuilder.phone(UUID.randomUUID().toString());
accountBuilder.postalCode(UUID.randomUUID().toString());
accountBuilder.stateOrProvince(UUID.randomUUID().toString());
accountBuilder.timeZone(DateTimeZone.UTC);
accountBuilder.parentAccountId(UUID.randomUUID());
final Account account = accountBuilder.build();
final AccountJson accountJson = new AccountJson(account, null, null, null);
Assert.assertEquals(accountJson.getAddress1(), account.getAddress1());
Assert.assertEquals(accountJson.getAddress2(), account.getAddress2());
Assert.assertEquals(accountJson.getBillCycleDayLocal(), (Integer) bcd);
Assert.assertEquals(accountJson.getCountry(), account.getCountry());
Assert.assertEquals(accountJson.getLocale(), account.getLocale());
Assert.assertEquals(accountJson.getCompany(), account.getCompanyName());
Assert.assertEquals(accountJson.getCity(), account.getCity());
Assert.assertEquals(accountJson.getCurrency(), account.getCurrency());
Assert.assertEquals(accountJson.getEmail(), account.getEmail());
Assert.assertEquals(accountJson.getExternalKey(), account.getExternalKey());
Assert.assertEquals(accountJson.getName(), account.getName());
Assert.assertEquals(accountJson.getPaymentMethodId(), account.getPaymentMethodId());
Assert.assertEquals(accountJson.getPhone(), account.getPhone());
Assert.assertEquals(accountJson.isMigrated(), account.isMigrated());
Assert.assertEquals(accountJson.getState(), account.getStateOrProvince());
Assert.assertEquals(accountJson.getTimeZone(), account.getTimeZone().toString());
Assert.assertEquals(accountJson.getParentAccountId(), account.getParentAccountId());
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class DefaultSubscriptionTestInitializer method initAccountData.
public AccountData initAccountData(final Clock clock) {
final AccountData accountData = new MockAccountBuilder().name(UUIDs.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUIDs.randomUUID().toString().substring(1, 8)).phone(UUIDs.randomUUID().toString().substring(1, 8)).migrated(false).externalKey(UUIDs.randomUUID().toString()).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUIDs.randomUUID()).referenceTime(clock.getUTCNow()).timeZone(DateTimeZone.forID("Europe/Paris")).build();
assertNotNull(accountData);
return accountData;
}
Aggregations