use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class PmTransactionShould method checkEventReceived.
@Override
protected void checkEventReceived(ProcessManager<ProjectId, Project, PatchedProjectBuilder> entity, Event event) {
final TestProcessManager aggregate = (TestProcessManager) entity;
final Message actualMessage = unpack(event.getMessage());
assertTrue(aggregate.getReceivedEvents().contains(actualMessage));
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class ProcessManagerShould method route_commands.
/**
* Tests command routing.
*
* @see TestProcessManager#handle(PmStartProject, CommandContext)
*/
@Test
public void route_commands() {
// Add dispatcher for the routed command. Otherwise the command would reject the command.
final AddTaskDispatcher dispatcher = new AddTaskDispatcher();
commandBus.register(dispatcher);
processManager.injectCommandBus(commandBus);
final List<Event> events = testDispatchCommand(startProject());
// There's only one event generated.
assertEquals(1, events.size());
final Event event = events.get(0);
// The producer of the event is our Process Manager.
assertEquals(processManager.getId(), Events.getProducer(event.getContext()));
final Message message = AnyPacker.unpack(event.getMessage());
// The event type is CommandRouted.
assertThat(message, instanceOf(CommandRouted.class));
final CommandRouted commandRouted = (CommandRouted) message;
// The source of the command is StartProject.
assertThat(getMessage(commandRouted.getSource()), instanceOf(PmStartProject.class));
final List<CommandEnvelope> dispatchedCommands = dispatcher.getCommands();
assertSize(1, dispatchedCommands);
final CommandEnvelope dispatchedCommand = dispatcher.getCommands().get(0);
assertEquals(commandRouted.getProduced(0), dispatchedCommand.getCommand());
}
use of com.google.protobuf.Message 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 com.google.protobuf.Message 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 com.google.protobuf.Message in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method activate_subscription.
@Test
public void activate_subscription() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
// Subscribe to the topic
final MemoizeStreamObserver<Subscription> subscriptionObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscriptionObserver);
subscriptionObserver.verifyState();
// Activate subscription
final MemoizeStreamObserver<SubscriptionUpdate> activationObserver = new MemoizeStreamObserver<>();
subscriptionService.activate(subscriptionObserver.streamFlowValue, activationObserver);
// Post update to Stand directly
final ProjectId projectId = ProjectId.newBuilder().setId("some-id").build();
final Message projectState = Project.newBuilder().setId(projectId).build();
final int version = 1;
final VersionableEntity entity = mockEntity(projectId, projectState, version);
boundedContext.getStand().post(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
// isCompleted set to false since we don't expect activationObserver::onCompleted to be called.
activationObserver.verifyState(false);
}
Aggregations