Search in sources :

Example 51 with Command

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

the class RejectionEnvelopeShould method outerObject.

@Override
protected Rejection outerObject() {
    final Message commandMessage = Int32Value.getDefaultInstance();
    final Command command = requestFactory.command().create(commandMessage);
    final Message rejectionMessage = CannotPerformBusinessOperation.newBuilder().setOperationId(newUuid()).build();
    final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
    return rejection;
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 52 with Command

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

the class RejectionEnvelopeShould method obtain_command_message.

@Test
public void obtain_command_message() {
    final Rejection rejection = outerObject();
    final Command command = rejection.getContext().getCommand();
    final Message commandMessage = AnyPacker.unpack(command.getMessage());
    final RejectionEnvelope envelope = toEnvelope(rejection);
    assertEquals(commandMessage, envelope.getCommandMessage());
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) Command(io.spine.core.Command) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 53 with Command

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

the class RejectionEnvelopeShould method obtain_command_context.

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

Example 54 with Command

use of io.spine.core.Command 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)

Example 55 with Command

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

the class AggregateRepositoryShould method allow_aggregates_react_on_rejections.

@Test
public void allow_aggregates_react_on_rejections() {
    boundedContext.register(new RejectingRepository());
    final RejectionReactingRepository repository = new RejectionReactingRepository();
    boundedContext.register(repository);
    final ProjectId parentId = givenAggregateId("rejectingParent");
    final ProjectId childId1 = givenAggregateId("acceptingChild-1");
    final ProjectId childId2 = givenAggregateId("acceptingChild-2");
    final ProjectId childId3 = givenAggregateId("acceptingChild-3");
    final StreamObserver<Ack> observer = StreamObservers.noOpObserver();
    final CommandBus commandBus = boundedContext.getCommandBus();
    // Create the parent project.
    final ImmutableSet<ProjectId> childProjects = ImmutableSet.of(childId1, childId2, childId3);
    final Command createParent = requestFactory.createCommand(AggCreateProjectWithChildren.newBuilder().setProjectId(parentId).addAllChildProjectId(childProjects).build());
    commandBus.post(createParent, observer);
    // Fire a command which would cause rejection.
    final Command startProject = requestFactory.createCommand(AggStartProjectWithChildren.newBuilder().setProjectId(parentId).build());
    commandBus.post(startProject, observer);
    for (ProjectId childProject : childProjects) {
        final Optional<RejectionReactingAggregate> optional = repository.find(childProject);
        assertTrue(optional.isPresent());
        // Check that all the aggregates:
        // 1. got Rejections.AggCannotStartArchivedProject;
        // 2. produced the state the event;
        // 3. applied the event.
        final String value = optional.get().getState().getValue();
        assertEquals(RejectionReactingAggregate.PARENT_ARCHIVED, value);
    }
}
Also used : RejectingRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectingRepository) RejectionReactingRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingRepository) Command(io.spine.core.Command) RejectionReactingAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingAggregate) ProjectId(io.spine.test.aggregate.ProjectId) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Aggregations

Command (io.spine.core.Command)137 Test (org.junit.Test)87 Event (io.spine.core.Event)19 TenantId (io.spine.core.TenantId)17 Ack (io.spine.core.Ack)15 Message (com.google.protobuf.Message)14 Rejection (io.spine.core.Rejection)13 CommandEnvelope (io.spine.core.CommandEnvelope)11 Timestamp (com.google.protobuf.Timestamp)9 Error (io.spine.base.Error)9 CommandContext (io.spine.core.CommandContext)9 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)8 CommandRecord (io.spine.server.commandbus.CommandRecord)8 ProjectId (io.spine.test.aggregate.ProjectId)8 CommandBus (io.spine.server.commandbus.CommandBus)7 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)7 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Any (com.google.protobuf.Any)6 CommandId (io.spine.core.CommandId)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6