Refine search
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account externalKey throws an exception") public void testShouldntBeAbleToUpdateExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setExternalKey(UUID.randomUUID().toString()); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext); }
@Test(groups = "slow", description = "Test Account update with null values") public void testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(null, null, null, 0, null, null, false, 0, null, clock.getUTCNow(), null, null, null, null, null, null, null, null, null, null, null, false); final String newAddress1 = UUID.randomUUID().toString(); mutableAccountData.setAddress1(newAddress1); accountUserApi.updateAccount(account.getId(), mutableAccountData, callContext); final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext); Assert.assertEquals(retrievedAccount.getAddress1(), newAddress1); Assert.assertEquals(retrievedAccount.getAddress2(), account.getAddress2()); Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency()); Assert.assertEquals(retrievedAccount.getExternalKey(), account.getExternalKey()); Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal()); }
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException { final UUID accountId = UUID.randomUUID(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final Invoice invoice = Mockito.mock(Invoice.class); Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice); Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN); Mockito.when(invoice.getStatus()).thenReturn(InvoiceStatus.COMMITTED); Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID()); final InvoiceItem item = Mockito.mock(InvoiceItem.class); final List<InvoiceItem> items = new ArrayList<InvoiceItem>(); items.add(item); Mockito.when(invoice.getInvoiceItems()).thenReturn(items); final List<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(invoice); Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); final Tag tag = Mockito.mock(Tag.class); Mockito.when(tag.getObjectId()).thenReturn(accountId); Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT); Mockito.when(tag.getTagDefinitionId()).thenReturn(ControlTagType.TEST.getId()); final List<Tag> tags = new ArrayList<Tag>(); tags.add(tag); Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())) .thenReturn(tags); return account; }
public DefaultImmutableAccountData(final Account account) { this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone(), AccountDateTimeUtils.getFixedOffsetTimeZone(account), account.getReferenceTime()); }
public static DateTimeZone getFixedOffsetTimeZone(final Account account) { return getFixedOffsetTimeZone(account.getTimeZone(), account.getReferenceTime()); }
currentAccount.getExternalKey() != null && !currentAccount.getExternalKey().equals(externalKey)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account external key yet: new=%s, current=%s", externalKey, currentAccount.getExternalKey())); currentAccount.getCurrency() != null && !currentAccount.getCurrency().equals(currency)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account currency yet: new=%s, current=%s", currency, currentAccount.getCurrency())); currentAccount.getBillCycleDayLocal() != DEFAULT_BILLING_CYCLE_DAY_LOCAL && // There is already a BCD set !currentAccount.getBillCycleDayLocal().equals(billCycleDayLocal)) { // and it does not match we we have throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account BCD yet: new=%s, current=%s", billCycleDayLocal, currentAccount.getBillCycleDayLocal())); currentAccount.getTimeZone() != null && !currentAccount.getTimeZone().equals(timeZone)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account timeZone yet: new=%s, current=%s", timeZone, currentAccount.getTimeZone())); if (referenceTime != null && currentAccount.getReferenceTime().withMillisOfDay(0).compareTo(referenceTime.withMillisOfDay(0)) != 0) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account referenceTime yet: new=%s, current=%s", referenceTime, currentAccount.getReferenceTime()));
@Test(groups = "slow") public void testAccountBalanceWithNoInvoiceItems() throws EntityPersistenceException { final UUID accountId = account.getId(); final LocalDate targetDate1 = new LocalDate(2011, 10, 6); final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD); invoiceUtil.createInvoice(invoice1, context); final BigDecimal payment1 = new BigDecimal("48.0"); final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD, Currency.USD, null, true); invoiceUtil.createPayment(payment, context); final BigDecimal balance = invoiceDao.getAccountBalance(accountId, context); assertEquals(balance.compareTo(BigDecimal.ZERO.subtract(payment1)), 0); }
@Test(groups = "slow") public void testSimpleAuthCaptureWithInvalidPaymentId() throws Exception { final BigDecimal requestedAmount = new BigDecimal("80.0091"); final Payment initialPayment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); try { paymentApi.createCapture(account, UUID.randomUUID(), requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Expected capture to fail..."); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_NO_SUCH_PAYMENT.getCode()); final Payment latestPayment = paymentApi.getPayment(initialPayment.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(latestPayment, initialPayment); } }
@Test(groups = "slow") public void testGetInvoiceItemsBySubscriptionId() throws EntityPersistenceException { final UUID accountId = account.getId(); final UUID subscriptionId = UUID.randomUUID(); final UUID bundleId = UUID.randomUUID(); final LocalDate startDate = new LocalDate(2011, 3, 1); final BigDecimal rate = new BigDecimal("20.00"); for (int i = 0; i < 3; i++) { final UUID invoiceId = UUID.randomUUID(); final RecurringInvoiceItem item = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test plan", "test phase", startDate.plusMonths(i), startDate.plusMonths(i + 1), rate, rate, Currency.USD); invoiceUtil.createInvoiceItem(item, context); } final List<InvoiceItemModelDao> items = invoiceUtil.getInvoiceItemBySubscriptionId(subscriptionId, context); assertEquals(items.size(), 3); }
@Test(groups = "slow") public void testInvoicePayment() throws InvoiceApiException, EntityPersistenceException { final UUID accountId = account.getId(); final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD); final UUID invoiceId = invoice.getId(); final UUID subscriptionId = UUID.randomUUID(); final UUID bundleId = UUID.randomUUID(); final LocalDate startDate = new LocalDate(2010, 1, 1); final LocalDate endDate = new LocalDate(2010, 4, 1); final InvoiceItem invoiceItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test plan", "test phase", startDate, endDate, new BigDecimal("21.00"), new BigDecimal("7.00"), Currency.USD); invoice.addInvoiceItem(invoiceItem); invoiceUtil.createInvoice(invoice, context); final InvoiceModelDao savedInvoice = invoiceDao.getById(invoiceId, context); assertNotNull(savedInvoice); assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(savedInvoice).compareTo(new BigDecimal("21.00")), 0); assertEquals(savedInvoice.getInvoiceItems().size(), 1); final BigDecimal paymentAmount = new BigDecimal("11.00"); final UUID paymentId = UUID.randomUUID(); final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, clock.getUTCNow().plusDays(12), paymentAmount, Currency.USD, Currency.USD, "cookie", true); invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), context); final InvoiceModelDao retrievedInvoice = invoiceDao.getById(invoiceId, context); assertNotNull(retrievedInvoice); assertEquals(retrievedInvoice.getInvoiceItems().size(), 1); assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(retrievedInvoice).compareTo(new BigDecimal("10.00")), 0); }
@Test(groups = "fast", description = "Test Account BCD merge") public void testBCDMerges() throws Exception { final UUID accountId = UUID.randomUUID(); final Currency currency = Currency.BRL; final String externalKey = UUID.randomUUID().toString(); Assert.assertEquals(accountWithNullBCD.getBillCycleDayLocal(), (Integer) 0); final Account accountWithZeroBCD = new DefaultAccount(accountId, accountDataWithZeroBCD); Assert.assertEquals(accountWithNullBCD.mergeWithDelegate(accountWithZeroBCD).getBillCycleDayLocal(), (Integer) 0); final Account accountWithRealBCD = new DefaultAccount(accountId, accountDataWithRealBCD); Assert.assertEquals(accountWithNullBCD.mergeWithDelegate(accountWithRealBCD).getBillCycleDayLocal(), (Integer) 12); final Account accountWithAnotherBCD = new DefaultAccount(accountId, accountDataWithAnotherRealBCD); Assert.assertEquals(accountWithAnotherBCD.mergeWithDelegate(accountWithAnotherBCD).getBillCycleDayLocal(), (Integer) 20); try { Assert.assertEquals(accountWithAnotherBCD.mergeWithDelegate(accountWithRealBCD).getBillCycleDayLocal(), (Integer) 20); Assert.fail(); } catch (final IllegalArgumentException e) {
private void createAndVerifyExternalCharge(final BigDecimal amount, final Currency currency) throws EntityPersistenceException { final InvoiceItem externalChargeInvoiceItem = new ExternalChargeInvoiceItem(UUID.randomUUID(), account.getId(), UUID.randomUUID(), UUID.randomUUID().toString(), new LocalDate(2012, 4, 1), new LocalDate(2012, 5, 1), amount, currency, null); invoiceUtil.createInvoiceItem(externalChargeInvoiceItem, context); final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(externalChargeInvoiceItem.getId(), context); assertSameInvoiceItem(externalChargeInvoiceItem, savedItem); Assert.assertEquals(externalChargeInvoiceItem.getAmount().compareTo(amount), 0); }
@Test(groups = "fast") public void testPaymentMethodExternalKeySetByPluginIfNonSpecified() throws Exception { final Account account = Mockito.mock(Account.class); final UUID accountId = UUID.randomUUID(); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(account.getExternalKey()).thenReturn(accountId.toString()); final PaymentMethodPlugin paymentMethodPlugin = Mockito.mock(PaymentMethodPlugin.class); final Iterable<PluginProperty> properties = ImmutableList.<PluginProperty>of(); // By default, the external payment plugin sets the external payment method id to "unknown" final UUID paymentMethodId2 = paymentMethodProcessor.addPaymentMethod(null, "__EXTERNAL_PAYMENT__", account, false, paymentMethodPlugin, properties, callContext, internalCallContext); final PaymentMethod paymentMethod2 = paymentMethodProcessor.getPaymentMethodById(paymentMethodId2, false, false, properties, callContext, internalCallContext); Assert.assertEquals(paymentMethod2.getExternalKey(), "unknown"); }
public static Account buildAccount(final Currency currency, final String address1, final String address2, final String city, final String stateOrProvince, final String postalCode, final String country) { final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getExternalKey()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getFirstNameLength()).thenReturn(4); Mockito.when(account.getEmail()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getBillCycleDayLocal()).thenReturn(2); Mockito.when(account.getCurrency()).thenReturn(currency); Mockito.when(account.getPaymentMethodId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.getDefault()); // Return language tag to be able to use Locale.forLanguageTag Mockito.when(account.getLocale()).thenReturn("en-US"); Mockito.when(account.getAddress1()).thenReturn(address1); Mockito.when(account.getAddress2()).thenReturn(address2); Mockito.when(account.getCompanyName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getCity()).thenReturn(city); Mockito.when(account.getStateOrProvince()).thenReturn(stateOrProvince); Mockito.when(account.getPostalCode()).thenReturn(postalCode); Mockito.when(account.getCountry()).thenReturn(country); Mockito.when(account.getPhone()).thenReturn(UUID.randomUUID().toString().substring(0, 25)); Mockito.when(account.isMigrated()).thenReturn(true); Mockito.when(account.getCreatedDate()).thenReturn(new DateTime(2016, 1, 22, 10, 56, 47, DateTimeZone.UTC)); Mockito.when(account.getUpdatedDate()).thenReturn(new DateTime(2016, 1, 22, 10, 56, 48, DateTimeZone.UTC)); return account; }
public Account createTestAccount(final String email, final boolean addPaymentMethod) throws Exception { final String name = "First" + UUID.randomUUID().toString() + " " + "Last" + UUID.randomUUID().toString(); final String externalKey = UUID.randomUUID().toString(); Mockito.when(accountData.getId()).thenReturn(UUID.randomUUID()); Mockito.when(accountData.getExternalKey()).thenReturn(externalKey); Mockito.when(accountData.getName()).thenReturn(name); Mockito.when(accountData.getFirstNameLength()).thenReturn(10); Mockito.when(accountData.getPhone()).thenReturn("123-456-7890"); Mockito.when(accountData.getEmail()).thenReturn(email); Mockito.when(accountData.getCurrency()).thenReturn(Currency.USD); Mockito.when(accountData.getBillCycleDayLocal()).thenReturn(1); Mockito.when(accountData.isMigrated()).thenReturn(false); Mockito.when(accountData.getTimeZone()).thenReturn(DateTimeZone.UTC); final DateTime utcNow = clock.getUTCNow(); Mockito.when(accountData.getCreatedDate()).thenReturn(utcNow); Mockito.when(accountData.getReferenceTime()).thenReturn(utcNow); GuicyKillbillTestSuite.refreshCallContext(account.getId(), clock, internalCallContextFactory, mutableCallContext, internalCallContext);
@Test(groups = "slow") public void testShouldntInsertMultipleNotificationsPerOverdueable() throws Exception { final UUID accountId = UUID.randomUUID(); final Account overdueable = Mockito.mock(Account.class); Mockito.when(overdueable.getId()).thenReturn(accountId); insertOverdueCheckAndVerifyQueueContent(overdueable, 10, 10); insertOverdueCheckAndVerifyQueueContent(overdueable, 5, 5); insertOverdueCheckAndVerifyQueueContent(overdueable, 15, 5); // Verify the final content of the queue Assert.assertEquals(Iterables.size(overdueQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId())), 1); }
@Test(groups = "fast") public void testProcessFixedBillingEventsWithCancellationOnNextDay() throws InvoiceApiException { final LocalDate targetDate = new LocalDate("2016-01-08"); final UUID invoiceId = UUID.randomUUID(); final BillingEventSet events = new MockBillingEventSet(); final BigDecimal fixedPriceAmount = BigDecimal.TEN; final MockInternationalPrice fixedPrice = new MockInternationalPrice(new DefaultPrice(fixedPriceAmount, Currency.USD)); final Plan plan = new MockPlan("my-plan"); final PlanPhase phase = new MockPlanPhase(null, fixedPrice, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL); final BillingEvent event1 = invoiceUtil.createMockBillingEvent(account, subscription, new DateTime("2016-01-08"), plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE); events.add(event1); final BillingEvent event2 = invoiceUtil.createMockBillingEvent(account, subscription, new DateTime("2016-01-09"), plan, phase, null, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 2L, SubscriptionBaseTransitionType.CANCEL); events.add(event2); final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>(); fixedAndRecurringInvoiceItemGenerator.processFixedBillingEvents(invoiceId, account.getId(), events, targetDate, Currency.USD, proposedItems, internalCallContext); assertEquals(proposedItems.size(), 1); assertEquals(proposedItems.get(0).getInvoiceItemType(), InvoiceItemType.FIXED); assertEquals(proposedItems.get(0).getAmount().compareTo(fixedPriceAmount), 0); }
@Test(groups = "slow") public void testGetByInvoiceItemId() throws EntityPersistenceException, InvoiceApiException { final Invoice invoice1 = new DefaultInvoice(account.getId(), clock.getUTCToday(), clock.getUTCToday(), Currency.USD); invoiceUtil.createInvoice(invoice1, context); final UUID invoiceId1 = invoice1.getId(); LocalDate startDate = new LocalDate(2011, 3, 1); LocalDate endDate = startDate.plusMonths(1); final RecurringInvoiceItem recurringItem1 = new RecurringInvoiceItem(invoiceId1, account.getId(), UUID.randomUUID(), UUID.randomUUID(), "test product", "test plan", "test A", startDate, endDate, BigDecimal.ONE, BigDecimal.ONE, Currency.USD); invoiceUtil.createInvoiceItem(recurringItem1, context); final InvoiceModelDao targetInvoice = invoiceDao.getByInvoiceItem(recurringItem1.getId(), internalCallContext); assertNotNull(targetInvoice); assertEquals(targetInvoice.getId(), invoiceId1); assertEquals(targetInvoice.getInvoiceItems().size(), 1); assertEquals(targetInvoice.getInvoiceItems().get(0).getId(), recurringItem1.getId()); }
public void clear(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), overdueable.getId().toString(), MAX_LOCK_RETRIES); clearWithLock(effectiveDate, context); } catch (final LockFailedException e) { log.warn("Failed to clear overdue for accountId='{}'", overdueable.getId(), e); } finally { if (lock != null) { lock.release(); } } }
@Test(groups = "slow") public void testCreateParentInvoice() throws InvoiceApiException { final UUID parentAccountId = UUID.randomUUID(); final UUID childAccountId = UUID.randomUUID(); final DateTime today = clock.getNow(account.getTimeZone()); InvoiceModelDao parentInvoice = new InvoiceModelDao(parentAccountId, today.toLocalDate(), account.getCurrency(), InvoiceStatus.DRAFT, true); InvoiceItem parentInvoiceItem = new ParentInvoiceItem(UUID.randomUUID(), today, parentInvoice.getId(), parentAccountId, childAccountId, BigDecimal.TEN, account.getCurrency(), ""); parentInvoice.addInvoiceItem(new InvoiceItemModelDao(parentInvoiceItem)); invoiceDao.createInvoices(ImmutableList.<InvoiceModelDao>of(parentInvoice), ImmutableSet.of(), context); final InvoiceModelDao parentDraftInvoice = invoiceDao.getParentDraftInvoice(parentAccountId, context); assertNotNull(parentDraftInvoice); assertEquals(parentDraftInvoice.getStatus(), InvoiceStatus.DRAFT); assertEquals(parentDraftInvoice.getInvoiceItems().size(), 1); }