Good evening,
I was wondering if someone could help me. I would like to test the dispatch in a command bus. For example:
CommandBus commandBus = config.getBean(CommandBus.class); //config is the application context
commandBus.dispatch(new GenericCommandMessage<>(new CreateAccountCommand(1, “john”, “doe”)));
The above code was from an example that I retype and it was located in the application main, and for that reason it is getting the bean. Now, I am trying to do something similar in my own class, but of I do not have the context. I can get the context again, but it feels like complicated. There is a CommandGateway class, but it seems like is for sagas. Is there something similar to dispatch a command?
For the testing I am using mockito and I have something similar to this:
@Mock
private GenericMessage mockMessage;
@Mock
private CommandGateway gateway; // this is because it seems easy with this, but I am not using sagas
@Test
public void testOnMessage() throws Exception {
Account account = new Account();
account.setFirstName(“john”);
account.setLastName(“doe”);
doReturn(account).when(mockMessage).getPayload();
//here I am missing the mock dispatch
accountProcessor.onMessage(mockMessage);
}
Thanks in advance