Search in sources :

Example 1 with CommandEnvelope

use of io.spine.envelope.CommandEnvelope in project core-java by SpineEventEngine.

the class CommandStoreShould method set_command_status_to_error_when_handler_throws_exception.

@Test
public void set_command_status_to_error_when_handler_throws_exception() {
    final RuntimeException exception = new IllegalStateException("handler throws");
    final Command command = givenThrowingHandler(exception);
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    commandBus.post(command, responseObserver);
    // Check that the logging was called.
    verify(log).errorHandling(eq(exception), eq(envelope.getMessage()), eq(envelope.getCommandId()));
    final String errorMessage = exception.getMessage();
    assertHasErrorStatusWithMessage(envelope, errorMessage);
}
Also used : Command(io.spine.base.Command) CommandEnvelope(io.spine.envelope.CommandEnvelope) Test(org.junit.Test)

Example 2 with CommandEnvelope

use of io.spine.envelope.CommandEnvelope in project core-java by SpineEventEngine.

the class CommandStoreShould method set_command_status_to_error_when_dispatcher_throws.

@Test
public void set_command_status_to_error_when_dispatcher_throws() {
    final ThrowingDispatcher dispatcher = new ThrowingDispatcher();
    commandBus.register(dispatcher);
    final Command command = requestFactory.command().create(createProjectMessage());
    commandBus.post(command, responseObserver);
    // Check that the logging was called.
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    verify(log).errorHandling(dispatcher.exception, envelope.getMessage(), envelope.getCommandId());
    // Check that the command status has the correct code,
    // and the error matches the thrown exception.
    assertHasErrorStatusWithMessage(envelope, dispatcher.exception.getMessage());
}
Also used : Command(io.spine.base.Command) CommandEnvelope(io.spine.envelope.CommandEnvelope) Test(org.junit.Test)

Example 3 with CommandEnvelope

use of io.spine.envelope.CommandEnvelope in project core-java by SpineEventEngine.

the class ProcessManagerRepositoryShould method throw_exception_if_dispatch_unknown_command.

@Test(expected = IllegalArgumentException.class)
public void throw_exception_if_dispatch_unknown_command() throws InvocationTargetException {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final Command unknownCommand = factory.createCommand(Int32Value.getDefaultInstance());
    final CommandEnvelope request = CommandEnvelope.of(unknownCommand);
    repository.dispatchCommand(request);
}
Also used : TestActorRequestFactory(io.spine.test.TestActorRequestFactory) Command(io.spine.base.Command) CommandEnvelope(io.spine.envelope.CommandEnvelope) Test(org.junit.Test)

Example 4 with CommandEnvelope

use of io.spine.envelope.CommandEnvelope in project core-java by SpineEventEngine.

the class ProcessManagerShould method testDispatchCommand.

private List<Event> testDispatchCommand(Message commandMsg) {
    final CommandEnvelope envelope = CommandEnvelope.of(requestFactory.command().create(commandMsg));
    final ProcManTransaction<?, ?, ?> tx = start(processManager);
    final List<Event> events = processManager.dispatchCommand(envelope);
    tx.commit();
    assertEquals(AnyPacker.pack(commandMsg), processManager.getState());
    return events;
}
Also used : CommandEnvelope(io.spine.envelope.CommandEnvelope) Event(io.spine.base.Event)

Example 5 with CommandEnvelope

use of io.spine.envelope.CommandEnvelope in project core-java by SpineEventEngine.

the class AbstractCommandRouterShould method setUp.

@Before
public void setUp() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().build();
    final CommandBus commandBus = boundedContext.getCommandBus();
    // Register dispatcher for `StringValue` message type.
    // Otherwise we won't be able to post.
    commandBus.register(new CommandDispatcher() {

        @Override
        public Set<CommandClass> getMessageClasses() {
            return CommandClass.setOf(StringValue.class);
        }

        @Override
        public void dispatch(CommandEnvelope envelope) {
        // Do nothing.
        }
    });
    sourceMessage = Wrapper.forString(getClass().getSimpleName());
    sourceContext = requestFactory.createCommandContext();
    router = createRouter(commandBus, sourceMessage, sourceContext);
    router.addAll(messages);
}
Also used : Set(java.util.Set) CommandDispatcher(io.spine.server.commandbus.CommandDispatcher) CommandEnvelope(io.spine.envelope.CommandEnvelope) BoundedContext(io.spine.server.BoundedContext) CommandBus(io.spine.server.commandbus.CommandBus) StringValue(com.google.protobuf.StringValue) Before(org.junit.Before)

Aggregations

CommandEnvelope (io.spine.envelope.CommandEnvelope)19 Test (org.junit.Test)9 Command (io.spine.base.Command)5 Error (io.spine.base.Error)4 Message (com.google.protobuf.Message)3 CommandId (io.spine.base.CommandId)2 CommandValidationError (io.spine.base.CommandValidationError)2 Identifiers.idToString (io.spine.base.Identifiers.idToString)2 BoundedContext (io.spine.server.BoundedContext)2 CommandDispatcher (io.spine.server.commandbus.CommandDispatcher)2 Set (java.util.Set)2 Before (org.junit.Before)2 Duration (com.google.protobuf.Duration)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 Timestamp (com.google.protobuf.Timestamp)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 Event (io.spine.base.Event)1 FailureThrowable (io.spine.base.FailureThrowable)1 CommandBus (io.spine.server.commandbus.CommandBus)1