Search in sources :

Example 21 with CommandEnvelope

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

the class StandPostShould method aggregateRepositoryDispatch.

private static BoundedContextAction aggregateRepositoryDispatch() {
    return new BoundedContextAction() {

        @Override
        public void perform(BoundedContext context) {
            // Init repository
            final AggregateRepository<?, ?> repository = Given.aggregateRepo();
            repository.initStorage(storageFactory(context.isMultitenant()));
            try {
                // Mock aggregate and mock stand are not able to handle events
                // returned after command handling.
                // This causes IllegalStateException to be thrown.
                // Note that this is not the end of a test case,
                // so we can't just "expect=IllegalStateException".
                final CommandEnvelope cmd = CommandEnvelope.of(Given.validCommand());
                repository.dispatch(cmd);
            } catch (IllegalStateException e) {
                // Proceed crash if it's not.
                if (!e.getMessage().contains("No record found for command ID: EMPTY")) {
                    throw e;
                }
            }
        }
    };
}
Also used : CommandEnvelope(io.spine.core.CommandEnvelope) BoundedContext(io.spine.server.BoundedContext)

Example 22 with CommandEnvelope

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

the class AggregateMessageDispatcherShould method dispatch_command.

@Test
public void dispatch_command() {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final int messageValue = 2017_07_28;
    final UInt32Value message = UInt32Value.newBuilder().setValue(messageValue).build();
    final CommandEnvelope commandEnvelope = CommandEnvelope.of(factory.createCommand(message));
    final List<? extends Message> eventMessages = dispatchCommand(aggregate, commandEnvelope);
    assertTrue(aggregate.getState().getValue().contains(String.valueOf(messageValue)));
    assertEquals(1, eventMessages.size());
    assertTrue(eventMessages.get(0) instanceof StringValue);
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) UInt32Value(com.google.protobuf.UInt32Value) CommandEnvelope(io.spine.core.CommandEnvelope) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 23 with CommandEnvelope

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

the class CommandStoreShould method set_command_status_to_error_when_handler_throws_unknown_Throwable.

@Test
public void set_command_status_to_error_when_handler_throws_unknown_Throwable() throws TestRejection, TestThrowable {
    ModelTests.clearModel();
    final Throwable throwable = new TestThrowable("Unexpected Throwable");
    final Command command = givenThrowingHandler(throwable);
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    commandBus.post(command, observer);
    // Check that the logging was called.
    verify(log).errorHandlingUnknown(eq(throwable), eq(envelope.getMessage()), eq(envelope.getId()));
    // Check that the status and message.
    assertHasErrorStatusWithMessage(envelope, throwable.getMessage());
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 24 with CommandEnvelope

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

the class CommandStoreShould method set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed.

@Test
public void set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed() {
    final List<Command> commands = newArrayList(createProject(), addTask(), startProject());
    final Duration delay = fromMinutes(5);
    // time to post passed
    final Timestamp schedulingTime = TimeTests.Past.minutesAgo(10);
    storeAsScheduled(commands, delay, schedulingTime);
    commandBus.rescheduleCommands();
    for (Command cmd : commands) {
        final CommandEnvelope envelope = CommandEnvelope.of(cmd);
        final Message msg = envelope.getMessage();
        final CommandId id = envelope.getId();
        // Check the expired status error was set.
        final ProcessingStatus status = getProcessingStatus(envelope);
        // Check that the logging was called.
        verify(log).errorExpiredCommand(msg, id);
        final Error expected = CommandExpiredException.commandExpired(cmd);
        assertEquals(expected, status.getError());
    }
}
Also used : Commands.getMessage(io.spine.core.Commands.getMessage) ThrowableMessage(io.spine.base.ThrowableMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.core.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 25 with CommandEnvelope

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

the class CommandEnvelopeShould method obtain_actor_context.

@Test
public void obtain_actor_context() {
    final Command command = outerObject();
    final CommandEnvelope envelope = toEnvelope(command);
    assertEquals(command.getContext().getActorContext(), envelope.getActorContext());
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Aggregations

CommandEnvelope (io.spine.core.CommandEnvelope)40 Test (org.junit.Test)25 Command (io.spine.core.Command)11 Message (com.google.protobuf.Message)7 Error (io.spine.base.Error)5 TestActorRequestFactory (io.spine.client.TestActorRequestFactory)4 StringValue (com.google.protobuf.StringValue)3 CommandValidationError (io.spine.core.CommandValidationError)3 Event (io.spine.core.Event)3 BoundedContext (io.spine.server.BoundedContext)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 CommandId (io.spine.core.CommandId)2 Commands.getMessage (io.spine.core.Commands.getMessage)2 TypeConverter.toMessage (io.spine.protobuf.TypeConverter.toMessage)2 CommandBus (io.spine.server.commandbus.CommandBus)2 HandlerMethodFailedException (io.spine.server.model.HandlerMethodFailedException)2 AggCreateProject (io.spine.test.aggregate.command.AggCreateProject)2 ProjectId (io.spine.test.procman.ProjectId)2 TypeName (io.spine.type.TypeName)2 Set (java.util.Set)2