use of io.spine.base.Command 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);
}
use of io.spine.base.Command in project core-java by SpineEventEngine.
the class TypeUrlShould method obtain_type_of_command.
@Test
public void obtain_type_of_command() {
final ActorRequestFactory factory = TestActorRequestFactory.newInstance(TypeUrlShould.class);
final StringValue message = Wrapper.forString(newUuid());
final Command command = factory.command().create(message);
final TypeUrl typeUrl = TypeUrl.ofCommand(command);
assertIsStringValueUrl(typeUrl);
}
use of io.spine.base.Command in project core-java by SpineEventEngine.
the class CommandEnvelopeShould method have_equals.
@Test
public void have_equals() {
final Command anotherCommand = requestFactory.command().create(Time.getCurrentTime());
new EqualsTester().addEqualityGroup(envelope).addEqualityGroup(CommandEnvelope.of(anotherCommand)).testEquals();
}
use of io.spine.base.Command in project core-java by SpineEventEngine.
the class CommandClass method of.
/**
* Creates a new instance for the class of the passed command.
*
* <p>If an instance of {@link Command} (which implements {@code Message}) is
* passed to this method, enclosing command message will be un-wrapped to
* determine the class of the command.
*
* @param command a command for which to get the class
* @return new instance
*/
public static CommandClass of(Message command) {
checkNotNull(command);
if (command instanceof Command) {
final Command commandRequest = (Command) command;
final Message enclosed = Commands.getMessage(commandRequest);
return of(enclosed.getClass());
}
final CommandClass result = of(command.getClass());
return result;
}
use of io.spine.base.Command in project core-java by SpineEventEngine.
the class DeadCommandFilter method accept.
@Override
public boolean accept(CommandEnvelope envelope, StreamObserver<Response> responseObserver) {
if (!hasDispatcher(envelope.getMessageClass())) {
final Command command = envelope.getCommand();
final CommandException unsupported = new UnsupportedCommandException(command);
commandBus.commandStore().storeWithError(command, unsupported);
responseObserver.onError(invalidArgumentWithCause(unsupported, unsupported.getError()));
return false;
}
return true;
}
Aggregations