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;
}
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());
}
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());
}
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);
}
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);
}
}
Aggregations