use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class AbstractCommandRouterShould method setUp.
@Before
public void setUp() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final CommandBus commandBus = boundedContext.getCommandBus();
// Register dispatcher for `StringValue` message type.
// Otherwise we won't be able to post.
commandBus.register(new CommandDispatcher<String>() {
@Override
public Set<CommandClass> getMessageClasses() {
return CommandClass.setOf(StringValue.class);
}
@Override
public String dispatch(CommandEnvelope envelope) {
// Do nothing.
return "Anonymous";
}
@Override
public void onError(CommandEnvelope envelope, RuntimeException exception) {
// Do nothing.
}
});
sourceMessage = toMessage(getClass().getSimpleName());
sourceContext = requestFactory.createCommandContext();
router = createRouter(commandBus, sourceMessage, sourceContext);
router.addAll(messages);
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandRouterOnErrorShould method throw_IllegalStateException_when_caught_error_when_posting.
@Test(expected = IllegalStateException.class)
public void throw_IllegalStateException_when_caught_error_when_posting() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final CommandBus commandBus = boundedContext.getCommandBus();
// Register dispatcher for `StringValue` message type.
// Fails each time of dispatch().
commandBus.register(new CommandDispatcher<Message>() {
@Override
public Set<CommandClass> getMessageClasses() {
return CommandClass.setOf(StringValue.class);
}
@Override
public Message dispatch(CommandEnvelope envelope) {
throw new IllegalStateException("I am faulty!");
}
@Override
public void onError(CommandEnvelope envelope, RuntimeException exception) {
// Do nothing.
}
});
final StringValue sourceMessage = toMessage(getClass().getSimpleName());
final CommandContext sourceContext = getRequestFactory().createCommandContext();
final CommandRouter router = createRouter(commandBus, sourceMessage, sourceContext);
router.addAll(getMessages());
router.routeAll();
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class PmMessageDeliveryShould method postpone_commands_dispatched_to_command_subscriber_method.
@Test
public void postpone_commands_dispatched_to_command_subscriber_method() {
assertNull(ReactingProjectWizard.getCommandReceived());
final Command command = createProject();
boundedContext.getCommandBus().post(command, StreamObservers.<Ack>noOpObserver());
assertNull(ReactingProjectWizard.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 PmCreateProject deliveredCommandMsg = ReactingProjectWizard.getCommandReceived();
assertNotNull(deliveredCommandMsg);
assertEquals(Commands.getMessage(command), deliveredCommandMsg);
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class ProcessManagerRepositoryShould method dispatch_rejection.
@Test
public void dispatch_rejection() {
final CommandEnvelope ce = requestFactory.generateEnvelope();
final EntityAlreadyArchived rejectionMessage = EntityAlreadyArchived.newBuilder().setEntityId(Identifier.pack(newUuid())).build();
final Rejection rejection = createRejection(rejectionMessage, ce.getCommand());
final ProjectId id = ProcessManagerRepositoryTestEnv.GivenCommandMessage.ID;
final Rejection.Builder builder = rejection.toBuilder().setContext(rejection.getContext().toBuilder().setProducerId(Identifier.pack(id)));
final RejectionEnvelope re = RejectionEnvelope.of(builder.build());
final Set<?> delivered = repository().dispatchRejection(re);
assertTrue(delivered.contains(id));
assertTrue(TestProcessManager.processed(rejectionMessage));
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class ProcessManagerRepositoryShould method throw_exception_if_dispatch_unknown_command.
@Test(expected = IllegalArgumentException.class)
public void throw_exception_if_dispatch_unknown_command() {
final Command unknownCommand = requestFactory.createCommand(Int32Value.getDefaultInstance());
final CommandEnvelope request = CommandEnvelope.of(unknownCommand);
repository().dispatchCommand(request);
}
Aggregations