Search in sources :

Example 11 with CommandEnvelope

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

the class DelegatingCommandDispatcherShould method delegate_onError.

@Test
public void delegate_onError() throws Exception {
    final EmptyCommandDispatcherDelegate delegate = new EmptyCommandDispatcherDelegate();
    final DelegatingCommandDispatcher<String> delegatingDispatcher = DelegatingCommandDispatcher.of(delegate);
    final CommandEnvelope commandEnvelope = TestActorRequestFactory.newInstance(getClass()).generateEnvelope();
    delegatingDispatcher.onError(commandEnvelope, new RuntimeException(getClass().getName()));
    assertTrue(delegate.onErrorCalled());
}
Also used : CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 12 with CommandEnvelope

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

the class CommandEnvelopeShould method obtain_command_context.

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

Example 13 with CommandEnvelope

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

the class AggregateCommandEndpointShould method store_aggregate_on_command_dispatching.

@Test
public void store_aggregate_on_command_dispatching() {
    final CommandEnvelope cmd = CommandEnvelope.of(createProject(projectId));
    final AggCreateProject msg = (AggCreateProject) cmd.getMessage();
    repository.dispatch(cmd);
    final Optional<ProjectAggregate> optional = repository.find(projectId);
    assertTrue(optional.isPresent());
    final ProjectAggregate aggregate = optional.get();
    assertEquals(projectId, aggregate.getId());
    assertEquals(msg.getName(), aggregate.getState().getName());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateCommandEndpointTestEnv.ProjectAggregate) CommandEnvelope(io.spine.core.CommandEnvelope) AggCreateProject(io.spine.test.aggregate.command.AggCreateProject) Test(org.junit.Test)

Example 14 with CommandEnvelope

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

the class AggregateCommandEndpointShould method post_events_on_command_dispatching.

@Test
public void post_events_on_command_dispatching() {
    final CommandEnvelope cmd = CommandEnvelope.of(createProject(projectId));
    repository.dispatch(cmd);
    final AggProjectCreated msg = subscriber.remembered;
    assertEquals(projectId, msg.getProjectId());
}
Also used : CommandEnvelope(io.spine.core.CommandEnvelope) AggProjectCreated(io.spine.test.aggregate.event.AggProjectCreated) Test(org.junit.Test)

Example 15 with CommandEnvelope

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

the class AggregateMessageDeliveryShould method postpone_commands_dispatched_to_command_handler_method.

@Test
public void postpone_commands_dispatched_to_command_handler_method() {
    assertNull(ReactingProject.getCommandReceived());
    final Command command = createProject();
    boundedContext.getCommandBus().post(command, StreamObservers.<Ack>noOpObserver());
    assertNull(ReactingProject.getCommandReceived());
    final CommandEnvelope expectedEnvelope = CommandEnvelope.of(command);
    final PostponingCommandDelivery delivery = repository.getCommandEndpointDelivery();
    final Map<ProjectId, CommandEnvelope> postponedCommands = delivery.getPostponedCommands();
    assertTrue(postponedCommands.size() == 1 && postponedCommands.containsValue(expectedEnvelope));
    final ProjectId projectId = postponedCommands.keySet().iterator().next();
    delivery.deliverNow(projectId, postponedCommands.get(projectId));
    final AggCreateProject deliveredCommandMsg = ReactingProject.getCommandReceived();
    assertNotNull(deliveredCommandMsg);
    assertEquals(Commands.getMessage(command), deliveredCommandMsg);
}
Also used : Command(io.spine.core.Command) PostponingCommandDelivery(io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingCommandDelivery) ProjectId(io.spine.test.aggregate.ProjectId) CommandEnvelope(io.spine.core.CommandEnvelope) AggCreateProject(io.spine.test.aggregate.command.AggCreateProject) 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