Search in sources :

Example 6 with AccountData

use of org.killbill.billing.account.api.AccountData in project killbill by killbill.

the class TestDefaultAccountUserApi method testCreateAccountWithSameExternalKeyInDifferentTenants.

@Test(groups = "slow", description = "Test Account creation with same External Key in different tenants")
public void testCreateAccountWithSameExternalKeyInDifferentTenants() throws Exception {
    final AccountData accountData = createAccountData();
    final Account account1 = accountUserApi.createAccount(accountData, callContext);
    try {
        // Same tenant
        accountUserApi.createAccount(accountData, callContext);
        Assert.fail();
    } catch (final AccountApiException e) {
        assertEquals(e.getCode(), ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode());
    }
    final TenantSqlDao tenantSqlDao = dbi.onDemand(TenantSqlDao.class);
    final TenantModelDao tenant2 = new TenantModelDao();
    tenantSqlDao.create(tenant2, internalCallContext);
    final CallContext callContext2 = new DefaultCallContext(tenant2.getId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock);
    final Account account2 = accountUserApi.createAccount(accountData, callContext2);
    Assert.assertEquals(account1.getExternalKey(), account2.getExternalKey());
    Assert.assertNotEquals(account1.getId(), account2.getId());
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) AccountTestUtils.createAccountData(org.killbill.billing.account.AccountTestUtils.createAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AccountApiException(org.killbill.billing.account.api.AccountApiException) TenantModelDao(org.killbill.billing.tenant.dao.TenantModelDao) TenantSqlDao(org.killbill.billing.tenant.dao.TenantSqlDao) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) Test(org.testng.annotations.Test)

Example 7 with AccountData

use of org.killbill.billing.account.api.AccountData in project killbill by killbill.

the class TestDefaultAccountUserApi method testCreateChildAccountWithInvalidParent.

@Test(groups = "slow", description = "Test Account create Child with a non existing Parent", expectedExceptions = AccountApiException.class, expectedExceptionsMessageRegExp = "Account does not exist for id .*")
public void testCreateChildAccountWithInvalidParent() throws Exception {
    final AccountModelDao childAccountModel = createTestAccount();
    childAccountModel.setParentAccountId(UUID.randomUUID());
    final AccountData childAccountData = new DefaultAccount(childAccountModel);
    final Account childAccount = accountUserApi.createAccount(childAccountData, callContext);
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) AccountTestUtils.createAccountData(org.killbill.billing.account.AccountTestUtils.createAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) Test(org.testng.annotations.Test)

Example 8 with AccountData

use of org.killbill.billing.account.api.AccountData in project killbill by killbill.

the class TestDefaultAccountUserApi method testCreateAccountWithExternalKeyOverLimit.

@Test(groups = "slow", description = "Test Account creation with External Key over limit")
public void testCreateAccountWithExternalKeyOverLimit() throws Exception {
    AccountModelDao accountModelDao = createTestAccount();
    // Set an externalKey of 256 characters (over limit)
    accountModelDao.setExternalKey("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,.");
    final AccountData accountData = new DefaultAccount(accountModelDao);
    try {
        accountUserApi.createAccount(accountData, callContext);
        Assert.fail();
    } catch (final AccountApiException e) {
        assertEquals(e.getCode(), ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED.getCode());
    }
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) AccountTestUtils.createAccountData(org.killbill.billing.account.AccountTestUtils.createAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) AccountApiException(org.killbill.billing.account.api.AccountApiException) Test(org.testng.annotations.Test)

Example 9 with AccountData

use of org.killbill.billing.account.api.AccountData in project killbill by killbill.

the class TestWithTimeZones method testWithDayLightSaving.

// Verify that recurring invoice items are correctly computed although we went through and out of daylight saving transitions
@Test(groups = "slow")
public void testWithDayLightSaving() throws Exception {
    // Start with a date in daylight saving period  and make sure we use a time of 8 hour so that we we reach standard time
    // the next month where the difference is 9 hours, a transformation from DateTime to LocalDate with the account time zone would bring us a day earlier
    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);
    final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
    final TestDryRunArguments dryRun = new TestDryRunArguments(DryRunType.SUBSCRIPTION_ACTION, "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, null, null, SubscriptionEventType.START_BILLING, null, null, null, null);
    final Invoice dryRunInvoice = invoiceUserApi.triggerInvoiceGeneration(account.getId(), clock.getUTCToday(), dryRun, callContext);
    expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 9, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
    invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, callContext, expectedInvoices);
    final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, 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, expectedInvoices);
    expectedInvoices.clear();
    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(2015, 10, 1), new LocalDate(2015, 11, 1), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
    LocalDate startDate = new LocalDate(2015, 11, 1);
    // We loop 18 times to go over a year and transitions several times between winter and summer (daylight saving)
    for (int i = 0; i < 18; i++) {
        final LocalDate endDate = startDate.plusMonths(1);
        busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
        clock.addMonths(1);
        assertListenerStatus();
        invoiceChecker.checkInvoice(account.getId(), i + 3, callContext, new ExpectedInvoiceItemCheck(startDate, endDate, InvoiceItemType.RECURRING, new BigDecimal("249.95")));
        startDate = endDate;
    }
}
Also used : Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) Invoice(org.killbill.billing.invoice.api.Invoice) ArrayList(java.util.ArrayList) 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) AccountData(org.killbill.billing.account.api.AccountData) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Test(org.testng.annotations.Test)

Example 10 with AccountData

use of org.killbill.billing.account.api.AccountData in project killbill by killbill.

the class TestWithTimeZones method testReferenceTimeInDSTGap.

@Test(groups = "slow")
public void testReferenceTimeInDSTGap() throws Exception {
    final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
    clock.setTime(new DateTime(2015, 3, 7, 2, 0, 0, tz));
    final AccountData accountData = new MockAccountBuilder().currency(Currency.USD).timeZone(tz).build();
    final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
    accountChecker.checkAccount(account.getId(), accountData, callContext);
    Assert.assertEquals(account.getTimeZone(), tz);
    Assert.assertEquals(account.getFixedOffsetTimeZone(), DateTimeZone.forOffsetHours(-8));
    // Note the gap: 2015-03-07T02:00:00.000-08:00 to 2015-03-08T03:00:00.000-07:00
    clock.addDays(1);
    try {
        // See TimeAwareContext#toUTCDateTime (which uses account.getFixedOffsetTimeZone() instead)
        new DateTime(clock.getUTCToday().getYear(), clock.getUTCToday().getMonthOfYear(), clock.getUTCToday().getDayOfMonth(), account.getReferenceTime().toDateTime(tz).getHourOfDay(), account.getReferenceTime().toDateTime(tz).getMinuteOfHour(), account.getReferenceTime().toDateTime(tz).getSecondOfMinute(), account.getTimeZone());
        Assert.fail();
    } catch (final IllegalInstantException e) {
    // Illegal instant due to time zone offset transition (daylight savings time 'gap'): 2015-03-08T10:00:00.000 (America/Los_Angeles)
    }
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
    // Pass a date of today, to trigger TimeAwareContext#toUTCDateTime
    final Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, "Something", ImmutableList.<PlanPhasePriceOverride>of(), clock.getUTCToday(), clock.getUTCToday(), false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    Assert.assertEquals(entitlement.getEffectiveStartDate().compareTo(new LocalDate("2015-03-08")), 0);
    Assert.assertEquals(((DefaultEntitlement) entitlement).getBasePlanSubscriptionBase().getStartDate().compareTo(new DateTime("2015-03-08T02:00:00.000-08:00")), 0);
    invoiceChecker.checkChargedThroughDate(entitlement.getId(), new LocalDate("2015-04-08"), callContext);
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addDays(31);
    assertListenerStatus();
    invoiceChecker.checkChargedThroughDate(entitlement.getId(), new LocalDate("2015-05-08"), callContext);
    for (int i = 0; i < 25; i++) {
        busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
        clock.addMonths(1);
        assertListenerStatus();
        invoiceChecker.checkChargedThroughDate(entitlement.getId(), new LocalDate("2015-03-08").plusMonths(3 + i), callContext);
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) AccountData(org.killbill.billing.account.api.AccountData) IllegalInstantException(org.joda.time.IllegalInstantException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

AccountData (org.killbill.billing.account.api.AccountData)54 Test (org.testng.annotations.Test)49 Account (org.killbill.billing.account.api.Account)47 LocalDate (org.joda.time.LocalDate)38 BigDecimal (java.math.BigDecimal)33 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)30 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)26 Invoice (org.killbill.billing.invoice.api.Invoice)19 ArrayList (java.util.ArrayList)17 Payment (org.killbill.billing.payment.api.Payment)14 DateTime (org.joda.time.DateTime)11 MutableAccountData (org.killbill.billing.account.api.MutableAccountData)9 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)8 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 Entitlement (org.killbill.billing.entitlement.api.Entitlement)8 ExpectedPaymentCheck (org.killbill.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck)7 MockAccountBuilder (org.killbill.billing.mock.MockAccountBuilder)7 DateTimeZone (org.joda.time.DateTimeZone)6 AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)6