Search in sources :

Example 1 with AggCreateProject

use of io.spine.test.aggregate.command.AggCreateProject 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 2 with AggCreateProject

use of io.spine.test.aggregate.command.AggCreateProject 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)2 AggCreateProject (io.spine.test.aggregate.command.AggCreateProject)2 Test (org.junit.Test)2 Command (io.spine.core.Command)1 ProjectAggregate (io.spine.server.aggregate.given.AggregateCommandEndpointTestEnv.ProjectAggregate)1 PostponingCommandDelivery (io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingCommandDelivery)1 ProjectId (io.spine.test.aggregate.ProjectId)1