Testing

We provide a helper class to aid users of the Java DSL mock a Surge Engine.

Java
sourcevoid testSendCommand() throws Exception {

    MockedSurgeEngine<UUID, BankAccount, BankAccountCommand, BankAccountCommand> mockedSurgeEngine;
    mockedSurgeEngine = new MockedSurgeEngine<>();

    UUID accountNumber = UUID.randomUUID();
    UUID otherAccountNumber = UUID.randomUUID();

    CreateAccount createAccount = new CreateAccount(accountNumber, "Jane", "Doe", 1000);
    DebitAccount debitAccount = new DebitAccount(otherAccountNumber, 50);
    BankAccount expectedBankAccount = new BankAccount(accountNumber, "Jane", "Doe", 1000);

    mockedSurgeEngine.whenSendCommand(accountNumber, createAccount).returnAggregate(expectedBankAccount);
    mockedSurgeEngine.whenSendCommand(otherAccountNumber, debitAccount).noSuchAggregate();

    CompletionStage<CommandResult<BankAccount>> actualResult;
    actualResult = mockedSurgeEngine.get()
            .aggregateFor(accountNumber).sendCommand(createAccount);

    // compare actual result to expected result
    // NOTE: must resolve/block the CompletionStage/CompletableFuture
}
Java
sourcevoid testGetAggregate() throws Exception {

    MockedSurgeEngine<UUID, BankAccount, BankAccountCommand, BankAccountCommand> mockedSurgeEngine;
    mockedSurgeEngine = new MockedSurgeEngine<>();

    UUID accountNumber = UUID.randomUUID();

    BankAccount fakeBankAccount = new BankAccount(accountNumber, "Jane", "Doe", 1000);

    mockedSurgeEngine.whenGetAggregate(accountNumber).returnAggregate(fakeBankAccount);

    CompletionStage<Optional<BankAccount>> result;
    result = mockedSurgeEngine.get()
            .aggregateFor(accountNumber).getState();

    // compare result to expected result
    // NOTE: must resolve/block the CompletionStage/CompletableFuture

}
The source code for this page can be found here.