Search in sources :

Example 1 with MockAccountBuilder

use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.

the class TestConsumableInArrear 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).isNotifiedForInvoices(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).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")));
    // 2015-11-1
    busHandler.pushExpectedEvent(NextEvent.NULL_INVOICE);
    clock.addMonths(1);
    assertListenerStatus();
    // 2015-12-1
    busHandler.pushExpectedEvent(NextEvent.NULL_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);
}
Also used : Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone) BigDecimal(java.math.BigDecimal) UsageApiException(org.killbill.billing.usage.api.UsageApiException) Handle(org.skife.jdbi.v2.Handle) AccountData(org.killbill.billing.account.api.AccountData) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 2 with MockAccountBuilder

use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.

the class DefaultSubscriptionTestInitializer method initAccountData.

public AccountData initAccountData() {
    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).isNotifiedForInvoices(false).externalKey(UUIDs.randomUUID().toString()).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUIDs.randomUUID()).timeZone(DateTimeZone.forID("Europe/Paris")).build();
    assertNotNull(accountData);
    return accountData;
}
Also used : MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) AccountData(org.killbill.billing.account.api.AccountData)

Example 3 with MockAccountBuilder

use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.

the class TestDefaultBillingEvent method createEvent.

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(sub, effectiveDate, true, shotgun, shotgunMonthly, BigDecimal.ZERO, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay, "Test Event 1", totalOrdering, type, DateTimeZone.UTC, null, false);
}
Also used : Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) MockPlan(org.killbill.billing.catalog.MockPlan) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan)

Example 4 with MockAccountBuilder

use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.

the class TestDefaultInvoiceGenerator method beforeClass.

@BeforeClass(groups = "fast")
protected void beforeClass() throws Exception {
    if (hasFailed()) {
        return;
    }
    super.beforeClass();
    final Clock clock = new DefaultClock();
    this.account = 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(31).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).timeZone(DateTimeZone.UTC).build();
}
Also used : MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) DefaultClock(org.killbill.clock.DefaultClock) DefaultClock(org.killbill.clock.DefaultClock) Clock(org.killbill.clock.Clock) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with MockAccountBuilder

use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.

the class TestAccountDao method testUpdate.

@Test(groups = "slow", description = "Test Account DAO: basic update (1)")
public void testUpdate() throws Exception {
    final AccountModelDao account = createTestAccount();
    accountDao.create(account, internalCallContext);
    refreshCallContext(account.getId());
    final AccountModelDao createdAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
    List<AuditLogWithHistory> auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(account.getId(), AuditLevel.FULL, internalCallContext);
    Assert.assertEquals(auditLogsWithHistory.size(), 1);
    final AccountModelDao history1 = (AccountModelDao) auditLogsWithHistory.get(0).getEntity();
    Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT);
    Assert.assertEquals(history1.getAccountRecordId(), createdAccount.getRecordId());
    Assert.assertEquals(history1.getTenantRecordId(), createdAccount.getTenantRecordId());
    Assert.assertEquals(history1.getExternalKey(), createdAccount.getExternalKey());
    Assert.assertEquals(history1.getMigrated(), createdAccount.getMigrated());
    Assert.assertEquals(history1.getTimeZone(), createdAccount.getTimeZone());
    Assert.assertEquals(history1.getLocale(), createdAccount.getLocale());
    final AccountData accountData = new MockAccountBuilder(new DefaultAccount(account)).migrated(false).locale("FR-CA").build();
    final AccountModelDao updatedAccount = new AccountModelDao(account.getId(), accountData);
    accountDao.update(updatedAccount, true, internalCallContext);
    final AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
    checkAccountsEqual(retrievedAccount, updatedAccount);
    auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount.getId(), AuditLevel.FULL, internalCallContext);
    Assert.assertEquals(auditLogsWithHistory.size(), 2);
    final AccountModelDao history2 = (AccountModelDao) auditLogsWithHistory.get(1).getEntity();
    Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT);
    Assert.assertEquals(auditLogsWithHistory.get(1).getChangeType(), ChangeType.UPDATE);
    Assert.assertEquals(history2.getAccountRecordId(), retrievedAccount.getRecordId());
    Assert.assertEquals(history2.getTenantRecordId(), retrievedAccount.getTenantRecordId());
    Assert.assertEquals(history2.getExternalKey(), retrievedAccount.getExternalKey());
    Assert.assertEquals(history2.getMigrated(), retrievedAccount.getMigrated());
    Assert.assertEquals(history2.getTimeZone(), retrievedAccount.getTimeZone());
    Assert.assertEquals(history2.getLocale(), retrievedAccount.getLocale());
    final AccountData accountData2 = new MockAccountBuilder(new DefaultAccount(updatedAccount)).locale("en_US").build();
    final AccountModelDao updatedAccount2 = new AccountModelDao(account.getId(), accountData2);
    accountDao.update(updatedAccount2, true, internalCallContext);
    final AccountModelDao retrievedAccount2 = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
    checkAccountsEqual(retrievedAccount2, updatedAccount2);
    auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount2.getId(), AuditLevel.FULL, internalCallContext);
    Assert.assertEquals(auditLogsWithHistory.size(), 3);
    final AccountModelDao history3 = (AccountModelDao) auditLogsWithHistory.get(2).getEntity();
    Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT);
    Assert.assertEquals(auditLogsWithHistory.get(1).getChangeType(), ChangeType.UPDATE);
    Assert.assertEquals(auditLogsWithHistory.get(2).getChangeType(), ChangeType.UPDATE);
    Assert.assertEquals(history3.getAccountRecordId(), retrievedAccount2.getRecordId());
    Assert.assertEquals(history3.getTenantRecordId(), retrievedAccount2.getTenantRecordId());
    Assert.assertEquals(history3.getExternalKey(), retrievedAccount2.getExternalKey());
    Assert.assertEquals(history3.getMigrated(), retrievedAccount2.getMigrated());
    Assert.assertEquals(history3.getTimeZone(), retrievedAccount2.getTimeZone());
    Assert.assertEquals(history3.getLocale(), retrievedAccount2.getLocale());
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) AuditLogWithHistory(org.killbill.billing.util.audit.AuditLogWithHistory) Test(org.testng.annotations.Test)

Aggregations

MockAccountBuilder (org.killbill.billing.mock.MockAccountBuilder)25 Account (org.killbill.billing.account.api.Account)21 AccountData (org.killbill.billing.account.api.AccountData)14 Test (org.testng.annotations.Test)13 DateTime (org.joda.time.DateTime)11 DateTimeZone (org.joda.time.DateTimeZone)11 LocalDate (org.joda.time.LocalDate)9 BigDecimal (java.math.BigDecimal)6 ArrayList (java.util.ArrayList)6 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)6 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)6 UUID (java.util.UUID)5 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)5 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)5 Entitlement (org.killbill.billing.entitlement.api.Entitlement)3 Invoice (org.killbill.billing.invoice.api.Invoice)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 PluginProperty (org.killbill.billing.payment.api.PluginProperty)2 Handle (org.skife.jdbi.v2.Handle)2