Search in sources :

Example 1 with CommandRouter

use of io.spine.server.procman.CommandRouter in project core-java by SpineEventEngine.

the class CommandRouterOnErrorShould method createRouter.

/**
     * Creates a router with mocked {@code CommandBus} which always calls
     * {@link StreamObserver#onError(Throwable) StreamObserver.onError()} when
     * {@link CommandBus#post(Command, StreamObserver) CommandBus.post()} is invoked.
     */
@Override
CommandRouter createRouter(CommandBus ignored, Message sourceMessage, CommandContext commandContext) {
    final CommandBus mockBus = mock(CommandBus.class);
    doAnswer(new Answer() {

        // is OK for Answer
        @SuppressWarnings("ReturnOfNull")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final StreamObserver<Response> observer = invocation.getArgument(1);
            observer.onError(new RuntimeException("simulate error"));
            return null;
        }
    }).when(mockBus).post(any(Command.class), ArgumentMatchers.<StreamObserver<Response>>any());
    return new CommandRouter(mockBus, sourceMessage, commandContext);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Response(io.spine.base.Response) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CommandRouter(io.spine.server.procman.CommandRouter) Command(io.spine.base.Command) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CommandBus(io.spine.server.commandbus.CommandBus)

Aggregations

StreamObserver (io.grpc.stub.StreamObserver)1 Command (io.spine.base.Command)1 Response (io.spine.base.Response)1 CommandBus (io.spine.server.commandbus.CommandBus)1 CommandRouter (io.spine.server.procman.CommandRouter)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1