Search in sources :

Example 11 with MockAccountBuilder

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

the class TestWithTimeZones method testIntoDaylightSavingTransition3.

@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();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) AccountData(org.killbill.billing.account.api.AccountData) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 12 with MockAccountBuilder

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

the class TestPaymentHelper method addTestPaymentMethod.

public Account addTestPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo, final Iterable<PluginProperty> pluginProperties) throws Exception {
    final UUID paymentMethodId = paymentApi.addPaymentMethod(account, paymentMethodInfo.getExternalPaymentMethodId(), MockPaymentProviderPlugin.PLUGIN_NAME, true, paymentMethodInfo, pluginProperties, context);
    if (isFastTest()) {
        final Account account1 = new MockAccountBuilder(account).paymentMethodId(paymentMethodId).build();
        accountApi.updateAccount(account, context);
        return account1;
    } else {
        // To reflect the payment method id change
        return accountApi.getAccountById(account.getId(), context);
    }
}
Also used : Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) UUID(java.util.UUID)

Example 13 with MockAccountBuilder

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

the class TestInvoiceHelper method createAccount.

public Account createAccount(final CallContext callContext) throws AccountApiException {
    final Account 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(31).currency(accountCurrency).paymentMethodId(UUID.randomUUID()).timeZone(DateTimeZone.UTC).createdDate(clock.getUTCNow()).build();
    final MutableCallContext mutableCallContext = new MutableCallContext(internalCallContext);
    final Account account;
    if (isFastTest()) {
        account = GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountUserApi, accountApi, immutableAccountApi, nonEntityDao, clock, internalCallContextFactory, mutableCallContext, internalCallContext);
    } else {
        account = accountUserApi.createAccount(accountData, callContext);
    }
    GuicyKillbillTestSuite.refreshCallContext(account.getId(), clock, internalCallContextFactory, mutableCallContext, internalCallContext);
    return account;
}
Also used : Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) MutableCallContext(org.killbill.billing.callcontext.MutableCallContext)

Example 14 with MockAccountBuilder

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

the class TestEntitlementDateHelper method createAccount.

private void createAccount(final DateTimeZone dateTimeZone, final DateTime referenceDateTime) throws AccountApiException {
    final Account accountData = new MockAccountBuilder().externalKey(UUID.randomUUID().toString()).timeZone(dateTimeZone).referenceTime(referenceDateTime).createdDate(referenceDateTime).build();
    GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountUserApi, accountInternalApi, immutableAccountInternalApi, nonEntityDao, clock, internalCallContextFactory, callContext, internalCallContext);
}
Also used : Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder)

Example 15 with MockAccountBuilder

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

the class TestWithTimeZones method testCancellationFrom_PDT_to_PST.

// Verify cancellation logic when we exit daylight saving period
@Test(groups = "slow")
public void testCancellationFrom_PDT_to_PST() throws Exception {
    // Start with a date in daylight saving period (PDT) and make sure we use a time of 7 hour so that we we reach standard time (PST)
    // the next month where the difference is 8 hours, a transformation from DateTime to LocalDate with the account time zone would bring us a day earlier
    // (e.g new LocalDate("2015-12-01T07:01:01.000Z", tz) -> "2015-11-30.
    clock.setTime(new DateTime("2015-11-01T07: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-12-01", tz);
    entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // 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.NULL_INVOICE, NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
    clock.setTime(new DateTime("2015-12-01T07:01:02Z"));
    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);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) Invoice(org.killbill.billing.invoice.api.Invoice) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) PluginProperty(org.killbill.billing.payment.api.PluginProperty) AccountData(org.killbill.billing.account.api.AccountData) UUID(java.util.UUID) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) 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