@Test(groups = "slow")
public void testApiHistory() throws Exception {
final String overdueStateName = "WayPassedItMan";
final String service = "TEST";
final boolean blockChange = true;
final boolean blockEntitlement = false;
final boolean blockBilling = false;
final Account account = createAccount(getAccountData(7));
testListener.pushExpectedEvent(NextEvent.BLOCK);
final BlockingState state1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, overdueStateName, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
blockingInternalApi.setBlockingState(state1, internalCallContext);
assertListenerStatus();
clock.setDeltaFromReality(1000 * 3600 * 24);
testListener.pushExpectedEvent(NextEvent.BLOCK);
final String overdueStateName2 = "NoReallyThisCantGoOn";
final BlockingState state2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, overdueStateName2, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
blockingInternalApi.setBlockingState(state2, internalCallContext);
assertListenerStatus();
final List<BlockingState> blockingAll = blockingInternalApi.getBlockingAllForAccount(catalog, internalCallContext);
final List<BlockingState> history = ImmutableList.<BlockingState>copyOf(Collections2.<BlockingState>filter(blockingAll,
new Predicate<BlockingState>() {
@Override
public boolean apply(final BlockingState input) {
return input.getService().equals(service);
}
}));
Assert.assertEquals(history.size(), 2);
Assert.assertEquals(history.get(0).getStateName(), overdueStateName);
Assert.assertEquals(history.get(1).getStateName(), overdueStateName2);
}