Search in sources :

Example 1 with DefaultControlTag

use of org.killbill.billing.util.tag.DefaultControlTag in project killbill by killbill.

the class TestCondition method testHasControlTag.

@Test(groups = "fast")
public void testHasControlTag() throws Exception {
    final String xml = "<condition>" + "	<controlTagInclusion>OVERDUE_ENFORCEMENT_OFF</controlTagInclusion>" + "</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 ObjectType objectType = ObjectType.BUNDLE;
    final UUID objectId = new UUID(0L, 1L);
    final BillingState state0 = new BillingState(objectId, 0, BigDecimal.ZERO, null, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[] { new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
    final BillingState state1 = new BillingState(objectId, 1, new BigDecimal("100.00"), now.minusDays(10), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()) });
    final BillingState state2 = new BillingState(objectId, 1, new BigDecimal("200.00"), now.minusDays(20), unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()), new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
    Assert.assertTrue(!c.evaluate(state0, now));
    Assert.assertTrue(c.evaluate(state1, now));
    Assert.assertTrue(c.evaluate(state2, now));
}
Also used : ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with DefaultControlTag

use of org.killbill.billing.util.tag.DefaultControlTag in project killbill by killbill.

the class TestInvoiceDaoHelper method testPopulateChildrenWith_WRITTEN_OFF.

@Test(groups = "slow")
public void testPopulateChildrenWith_WRITTEN_OFF() throws Exception {
    final UUID accountId = account.getId();
    final Invoice inputInvoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final InvoiceItem invoiceItem = new RecurringInvoiceItem(inputInvoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test", "test-plan", "test-phase", null, today, today, BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
    inputInvoice.addInvoiceItem(invoiceItem);
    invoiceUtil.createInvoice(inputInvoice, internalAccountContext);
    final List<Tag> tags = ImmutableList.of(new DefaultControlTag(ControlTagType.WRITTEN_OFF, ObjectType.INVOICE, inputInvoice.getId(), clock.getUTCNow()));
    final InvoiceModelDao invoice1 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
    populateChildrenByInvoiceId(invoice1, tags);
    final InvoiceModelDao invoice2 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
    populateChildrenByAccountRecordId(invoice2, tags);
    Assert.assertEquals(invoice1, invoice2);
    Assert.assertEquals((new DefaultInvoice(invoice1)).getBalance().compareTo(BigDecimal.ZERO), 0);
    Assert.assertEquals((new DefaultInvoice(invoice2)).getBalance().compareTo(BigDecimal.ZERO), 0);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ParentInvoiceItem(org.killbill.billing.invoice.model.ParentInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) Tag(org.killbill.billing.util.tag.Tag) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Test(org.testng.annotations.Test)

Aggregations

UUID (java.util.UUID)2 DefaultControlTag (org.killbill.billing.util.tag.DefaultControlTag)2 Test (org.testng.annotations.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 LocalDate (org.joda.time.LocalDate)1 ObjectType (org.killbill.billing.ObjectType)1 Invoice (org.killbill.billing.invoice.api.Invoice)1 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)1 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)1 ParentInvoiceItem (org.killbill.billing.invoice.model.ParentInvoiceItem)1 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)1 BillingState (org.killbill.billing.overdue.config.api.BillingState)1 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)1 Tag (org.killbill.billing.util.tag.Tag)1