@Test(groups = "slow") public void testExternalChargeInvoiceSqlDao() throws Exception { final UUID invoiceId = UUID.randomUUID(); final UUID accountId = account.getId(); final UUID bundleId = UUID.randomUUID(); final String description = UUID.randomUUID().toString(); final LocalDate startDate = new LocalDate(2012, 4, 1); final InvoiceItem externalChargeInvoiceItem = new ExternalChargeInvoiceItem(invoiceId, accountId, bundleId, description, startDate, TEN, Currency.USD); invoiceUtil.createInvoiceItem(externalChargeInvoiceItem, context); final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(externalChargeInvoiceItem.getId(), context); assertSameInvoiceItem(externalChargeInvoiceItem, savedItem); }
final BigDecimal amount = BigDecimal.TEN; final Currency currency = Currency.GBP; final ExternalChargeInvoiceItem item = new ExternalChargeInvoiceItem(id, invoiceId, accountId, bundleId, description, effectiveDate, amount, currency); Assert.assertEquals(item.getAccountId(), accountId); final ExternalChargeInvoiceItem otherItem = new ExternalChargeInvoiceItem(id, invoiceId, UUID.randomUUID(), bundleId, description, effectiveDate, amount, currency); Assert.assertNotEquals(otherItem, item); final ExternalChargeInvoiceItem itemBefore = new ExternalChargeInvoiceItem(id, invoiceId, accountId, bundleId, description, effectiveDate.minusDays(1), amount, currency); Assert.assertFalse(itemBefore.matches(item)); final ExternalChargeInvoiceItem itemAfter = new ExternalChargeInvoiceItem(id, invoiceId, accountId, bundleId, description, effectiveDate.plusDays(1), amount, currency); Assert.assertFalse(itemAfter.matches(item));
@Override public InvoiceItem getExternalChargeById(final UUID externalChargeId, final TenantContext context) throws InvoiceApiException { final InvoiceItem externalChargeItem = InvoiceItemFactory.fromModelDao(dao.getExternalChargeById(externalChargeId, internalCallContextFactory.createInternalTenantContext(externalChargeId, ObjectType.INVOICE_ITEM, context))); if (externalChargeItem == null) { throw new InvoiceApiException(ErrorCode.INVOICE_NO_SUCH_EXTERNAL_CHARGE, externalChargeId); } return new ExternalChargeInvoiceItem(externalChargeItem.getId(), externalChargeItem.getInvoiceId(), externalChargeItem.getAccountId(), externalChargeItem.getPlanName(), externalChargeItem.getStartDate(), externalChargeItem.getAmount(), externalChargeItem.getCurrency()); }
switch (type) { case EXTERNAL_CHARGE: item = new ExternalChargeInvoiceItem(id, createdDate, invoiceId, accountId, bundleId, planName, startDate, amount, currency); break; case FIXED: