@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())); }
@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(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, BigDecimal.ZERO, new LocalDate(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{}); final BillingState state2 = new BillingState(new UUID(0L, 1L), 2, BigDecimal.ZERO, 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())); }
@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)); }
@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)); }
@Test(groups = "slow") public void testWrapperNoConfig() throws Exception { overdueWrapperFactory.setOverdueConfig(null); final Account account; final OverdueWrapper wrapper; final OverdueState state; final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); state = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); final OverdueState result = wrapper.refresh(internalCallContext); Assert.assertEquals(result.getName(), state.getName()); Assert.assertEquals(result.blockChanges(), state.blockChanges()); Assert.assertEquals(result.disableEntitlementAndChangesBlocked(), state.disableEntitlementAndChangesBlocked()); } }
"</condition>"; final InputStream is = new ByteArrayInputStream(xml.getBytes()); final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class); final UUID unpaidInvoiceId = UUID.randomUUID();
"</overdueConfig>"; final InputStream is = new ByteArrayInputStream(xml.getBytes()); final OverdueConfig c = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); Assert.assertEquals(c.getStateSet().size(), 2);
@Test(groups = "slow") public void testApplicator() throws Exception { final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); overdueWrapperFactory.setOverdueConfig(config); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); final OverdueStateSet overdueStateSet = config.getStateSet(); final OverdueState clearState = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME); OverdueState state; state = config.getStateSet().findState("OD1"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD1"); state = config.getStateSet().findState("OD2"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD2"); state = config.getStateSet().findState("OD3"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD3"); }
@Test(groups = "slow") public void testWrapperBasic() throws Exception { final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); overdueWrapperFactory.setOverdueConfig(config); Account account; OverdueWrapper wrapper; OverdueState state; state = config.getStateSet().findState("OD1"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); state = config.getStateSet().findState("OD2"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(41)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); state = config.getStateSet().findState("OD3"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(51)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); }