in component-test/src/main/java/org/apache/fineract/cn/accounting/TestAccount.java [577:622]
public void shouldReturnOnlyAvailableCommands() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> openAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(2, openAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.LOCK.name(), openAccountCommands.get(0).getAction());
Assert.assertEquals(AccountCommand.Action.CLOSE.name(), openAccountCommands.get(1).getAction());
final AccountCommand lockAccountCommand = new AccountCommand();
lockAccountCommand.setAction(AccountCommand.Action.LOCK.name());
lockAccountCommand.setComment("lock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), lockAccountCommand);
this.eventRecorder.wait(EventConstants.LOCK_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> lockedAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(2, lockedAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.UNLOCK.name(), lockedAccountCommands.get(0).getAction());
Assert.assertEquals(AccountCommand.Action.CLOSE.name(), lockedAccountCommands.get(1).getAction());
final AccountCommand unlockAccountCommand = new AccountCommand();
unlockAccountCommand.setAction(AccountCommand.Action.UNLOCK.name());
unlockAccountCommand.setComment("unlock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), unlockAccountCommand);
this.eventRecorder.wait(EventConstants.UNLOCK_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> unlockedAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(2, unlockedAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.LOCK.name(), unlockedAccountCommands.get(0).getAction());
Assert.assertEquals(AccountCommand.Action.CLOSE.name(), unlockedAccountCommands.get(1).getAction());
final AccountCommand closeAccountCommand = new AccountCommand();
closeAccountCommand.setAction(AccountCommand.Action.CLOSE.name());
closeAccountCommand.setComment("unlock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), closeAccountCommand);
this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> closedAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(1, closedAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.REOPEN.name(), closedAccountCommands.get(0).getAction());
}