Search in sources :

Example 6 with BillingState

use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.

the class TestCondition method testResponseForLastFailedPaymentIn.

@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, DateTimeZone.UTC, 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), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
    final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20), DateTimeZone.UTC, 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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 7 with BillingState

use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.

the class TestCondition method testTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds.

@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, DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
    final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
    final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
    Assert.assertTrue(!c.evaluate(state0, now));
    Assert.assertTrue(c.evaluate(state1, now));
    Assert.assertTrue(c.evaluate(state2, now));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 8 with BillingState

use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.

the class TestCondition method testTotalUnpaidInvoiceBalanceEqualsOrExceeds.

@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(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
    final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), new LocalDate(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
    final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), new LocalDate(), DateTimeZone.UTC, 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()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

BillingState (org.killbill.billing.overdue.config.api.BillingState)8 LocalDate (org.joda.time.LocalDate)7 UUID (java.util.UUID)6 Test (org.testng.annotations.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 BigDecimal (java.math.BigDecimal)5 ObjectType (org.killbill.billing.ObjectType)1 BlockingState (org.killbill.billing.entitlement.api.BlockingState)1 Invoice (org.killbill.billing.invoice.api.Invoice)1 OverdueState (org.killbill.billing.overdue.api.OverdueState)1 PaymentResponse (org.killbill.billing.payment.api.PaymentResponse)1 DefaultControlTag (org.killbill.billing.util.tag.DefaultControlTag)1 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)1 Tag (org.killbill.billing.util.tag.Tag)1