@Test(groups = "fast") public void testBalanceFormatting() throws Exception { final BillingState billingState = new BillingState(UUID.randomUUID(), 2, BigDecimal.TEN, new LocalDate(), UUID.randomUUID(), null, null); final DefaultBillingStateFormatter formatter = new DefaultBillingStateFormatter(billingState); Assert.assertEquals(formatter.getFormattedBalanceOfUnpaidInvoices(), "10.00"); } }
@Test(groups = "fast") public void testTotalUnpaidInvoiceBalanceEqualsOrExceeds() throws Exception { final String xml = "<condition>" + " <totalUnpaidInvoiceBalanceEqualsOrExceeds>100.00</totalUnpaidInvoiceBalanceEqualsOrExceeds>" + "</condition>"; final InputStream is = new ByteArrayInputStream(xml.getBytes()); final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class); final UUID unpaidInvoiceId = UUID.randomUUID(); final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, new LocalDate(), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), new LocalDate(), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), new LocalDate(), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); Assert.assertTrue(!c.evaluate(state0, new LocalDate())); Assert.assertTrue(c.evaluate(state1, new LocalDate())); Assert.assertTrue(c.evaluate(state2, new LocalDate())); }
@Test(groups = "fast") public void testProRationAfterLastBillingCycleDate() throws Exception { final LocalDate endDate = new LocalDate("2012-06-02"); final LocalDate previousBillThroughDate = new LocalDate("2012-03-02"); final BigDecimal proration = InvoiceDateUtils.calculateProRationAfterLastBillingCycleDate(endDate, previousBillThroughDate, BillingPeriod.MONTHLY); Assert.assertEquals(proration, new BigDecimal("2.967741935")); }
public BillingStateCalculator createBSCalc() { now = new LocalDate(); final Collection<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(createInvoice(now, BigDecimal.ZERO, null)); invoices.add(createInvoice(now.plusDays(1), BigDecimal.TEN, null)); invoices.add(createInvoice(now.plusDays(2), new BigDecimal("100.0"), null)); Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); return new BillingStateCalculator(invoiceApi, clock, tagInternalApi) { @Override public BillingState calculateBillingState(final ImmutableAccountData overdueable, final InternalCallContext context) { return null; } }; }
@Test(groups = "fast") public void testNumberOfUnpaidInvoicesEqualsOrExceeds() throws Exception { final String xml = "<condition>" + " <numberOfUnpaidInvoicesEqualsOrExceeds>1</numberOfUnpaidInvoicesEqualsOrExceeds>" + "</condition>"; final InputStream is = new ByteArrayInputStream(xml.getBytes()); final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class); final UUID unpaidInvoiceId = UUID.randomUUID(); final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, new LocalDate(), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, BigDecimal.ZERO, new LocalDate(), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state2 = new BillingState(new UUID(0L, 1L), 2, BigDecimal.ZERO, new LocalDate(), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); Assert.assertTrue(!c.evaluate(state0, new LocalDate())); Assert.assertTrue(c.evaluate(state1, new LocalDate())); Assert.assertTrue(c.evaluate(state2, new LocalDate())); }
@Test @SuppressWarnings("resource") public void formatFieldForValueInjection() { AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(); ac.registerBeanDefinition("valueBean", new RootBeanDefinition(ValueBean.class)); ac.registerBeanDefinition("conversionService", new RootBeanDefinition(FormattingConversionServiceFactoryBean.class)); ac.refresh(); ValueBean valueBean = ac.getBean(ValueBean.class); assertEquals(new LocalDate(2009, 10, 31), new LocalDate(valueBean.date)); }
@Test(groups = "fast") public void testProRationAfterLastBillingCycleDate() throws Exception { final LocalDate endDate = new LocalDate("2012-06-02"); final LocalDate previousBillThroughDate = new LocalDate("2012-03-02"); final BigDecimal proration = InvoiceDateUtils.calculateProRationAfterLastBillingCycleDate(endDate, previousBillThroughDate, BillingPeriod.MONTHLY); Assert.assertEquals(proration, new BigDecimal("2.9677")); }
@Test(groups = "fast") public void testTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds() throws Exception { final String xml = "<condition>" + " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds><unit>DAYS</unit><number>10</number></timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" + "</condition>"; final InputStream is = new ByteArrayInputStream(xml.getBytes()); final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class); final UUID unpaidInvoiceId = UUID.randomUUID(); final LocalDate now = new LocalDate(); final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, null, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); Assert.assertTrue(!c.evaluate(state0, now)); Assert.assertTrue(c.evaluate(state1, now)); Assert.assertTrue(c.evaluate(state2, now)); }
@Test(groups = "slow") public void testNoEntries() { final UUID subscriptionId = UUID.randomUUID(); final String unitType = "foo"; final LocalDate startDate = new LocalDate(2013, 1, 1); final LocalDate endDate = new LocalDate(2013, 2, 1); RolledUpUsageModelDao usage1 = new RolledUpUsageModelDao(subscriptionId, unitType, endDate, 9L, UUID.randomUUID().toString()); List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>(); usages.add(usage1); rolledUpUsageDao.record(usages, internalCallContext); final List<RolledUpUsageModelDao> result = rolledUpUsageDao.getUsageForSubscription(subscriptionId, startDate, endDate, unitType, internalCallContext); assertEquals(result.size(), 0); }
public Money fine(double fineRate, Money amount, DateTime when) { LocalDate whenPaying = new LocalDate(when.getYear(), when.monthOfYear().get(), when.dayOfMonth().get()); LocalDate lastPaymentDay = new LocalDate(when.getYear(), getMonthLastPayment(), getDayLastPayment()); if (whenPaying.isAfter(lastPaymentDay)) { int monthsOut = when.getMonthOfYear() - lastPaymentDay.getMonthOfYear(); // if is in the same month, and a day has passed, at least it // counts for one month if (monthsOut == 0) { monthsOut = 1; } return new Money(amount.getAmount().multiply(new BigDecimal(fineRate * monthsOut))); } else { return new Money(0); } }
@Test(groups = "fast") public void testComputeUTCDateTimeFromLocalDateC() { final DateTime effectiveDateTime = DATE_TIME_FORMATTER.parseDateTime(effectiveDateTimeC); final DateTimeZone timeZone = DateTimeZone.forOffsetHours(8); refreshCallContext(effectiveDateTime, timeZone); final LocalDate endDate = new LocalDate(2013, 01, 20); final DateTime endDateTimeInUTC = internalCallContext.toUTCDateTime(endDate); assertTrue(endDateTimeInUTC.compareTo(effectiveDateTime.plusYears(1)) == 0); }
@Test @SuppressWarnings("resource") public void formatFieldForValueInjectionUsingMetaAnnotations() { AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(); RootBeanDefinition bd = new RootBeanDefinition(MetaValueBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); ac.registerBeanDefinition("valueBean", bd); ac.registerBeanDefinition("conversionService", new RootBeanDefinition(FormattingConversionServiceFactoryBean.class)); ac.registerBeanDefinition("ppc", new RootBeanDefinition(PropertyPlaceholderConfigurer.class)); ac.refresh(); System.setProperty("myDate", "10-31-09"); System.setProperty("myNumber", "99.99%"); try { MetaValueBean valueBean = ac.getBean(MetaValueBean.class); assertEquals(new LocalDate(2009, 10, 31), new LocalDate(valueBean.date)); assertEquals(Double.valueOf(0.9999), valueBean.number); } finally { System.clearProperty("myDate"); System.clearProperty("myNumber"); } }
@Test(groups = "fast") public void testType() { final InvoiceItem invoiceItem = new ItemAdjInvoiceItem(UUID.randomUUID(), null, UUID.randomUUID(), UUID.randomUUID(), new LocalDate(2010, 1, 1), null, new BigDecimal("7.00"), Currency.USD, UUID.randomUUID(), null); Assert.assertEquals(invoiceItem.getInvoiceItemType(), InvoiceItemType.ITEM_ADJ); } }
@Test(groups = "fast") public void testResponseForLastFailedPaymentIn() throws Exception { final String xml = "<condition>" + " <responseForLastFailedPaymentIn><response>INSUFFICIENT_FUNDS</response><response>DO_NOT_HONOR</response></responseForLastFailedPaymentIn>" + "</condition>"; final InputStream is = new ByteArrayInputStream(xml.getBytes()); final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class); final UUID unpaidInvoiceId = UUID.randomUUID(); final LocalDate now = new LocalDate(); final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, null, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[]{}); final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20), unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[]{}); Assert.assertTrue(!c.evaluate(state0, now)); Assert.assertTrue(c.evaluate(state1, now)); Assert.assertTrue(c.evaluate(state2, now)); }
@Test(groups = "fast") public void testFutureEffectiveDateWithBCDEqualsComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 3; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 7, 3); // newBCD == ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-07-03"))); }
public BillingStateCalculator createBSCalc() { now = new LocalDate(); final Collection<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(createInvoice(now, BigDecimal.ZERO, null)); invoices.add(createInvoice(now.plusDays(1), BigDecimal.TEN, null)); invoices.add(createInvoice(now.plusDays(2), new BigDecimal("100.0"), null)); Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); return new BillingStateCalculator(invoiceApi, clock) { @Override public BillingState calculateBillingState(final Account overdueable, final InternalTenantContext context) { return null; } }; }
@Test(groups = "fast") public void testComputeUTCDateTimeFromLocalDate3() { final DateTime effectiveDateTime = DATE_TIME_FORMATTER.parseDateTime(effectiveDateTime3); final DateTimeZone timeZone = DateTimeZone.forOffsetHours(-8); refreshCallContext(effectiveDateTime, timeZone); final LocalDate endDate = new LocalDate(2013, 01, 20); final DateTime endDateTimeInUTC = internalCallContext.toUTCDateTime(endDate); assertTrue(endDateTimeInUTC.compareTo(effectiveDateTime.plusYears(1)) == 0); }
@Test public void testFormatDateTimePartial() { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("America/Chicago")); cal.set(1985, 10, 27, 0, 0, 0); long millis = cal.getTimeInMillis(); LocalDate localDate = new LocalDate(1985, 11, 27); Context ctx = InstrumentationRegistry.getContext(); for (int a = 0; a < FORMAT_DATE_RANGE_FLAGS.length; a++) { int flags = FORMAT_DATE_RANGE_FLAGS[a]; assertEquals(android.text.format.DateUtils.formatDateTime(ctx, millis, flags), DateUtils.formatDateTime(ctx, localDate, flags)); } }
@Test(groups = "fast") public void testType() throws Exception { final InvoiceItem invoiceItem = new ItemAdjInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new LocalDate(2010, 1, 1), new BigDecimal("7.00"), Currency.USD, UUID.randomUUID()); Assert.assertEquals(invoiceItem.getInvoiceItemType(), InvoiceItemType.ITEM_ADJ); } }