Search in sources :

Example 76 with Message

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));
}
Also used : Message(com.google.protobuf.Message) TestProcessManager(io.spine.server.procman.given.PmTransactionTestEnv.TestProcessManager)

Example 77 with Message

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());
}
Also used : AddTaskDispatcher(io.spine.server.procman.given.ProcessManagerTestEnv.AddTaskDispatcher) TypeConverter.toMessage(io.spine.protobuf.TypeConverter.toMessage) Commands.getMessage(io.spine.core.Commands.getMessage) Message(com.google.protobuf.Message) PmStartProject(io.spine.test.procman.command.PmStartProject) Event(io.spine.core.Event) CommandEnvelope(io.spine.core.CommandEnvelope) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 78 with Message

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;
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 79 with Message

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());
}
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 80 with Message

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);
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.aggregate.ProjectId) SubscriptionUpdate(io.spine.client.SubscriptionUpdate) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Aggregations

Message (com.google.protobuf.Message)185 Test (org.junit.Test)62 Any (com.google.protobuf.Any)30 Command (io.spine.core.Command)14 EntityRecord (io.spine.server.entity.EntityRecord)10 ByteString (com.google.protobuf.ByteString)9 Event (io.spine.core.Event)8 Event (io.spine.base.Event)7 CommandEnvelope (io.spine.core.CommandEnvelope)7 TypeUrl (io.spine.type.TypeUrl)7 IOException (java.io.IOException)7 Timestamp (com.google.protobuf.Timestamp)5 Error (io.spine.base.Error)5 Rejection (io.spine.core.Rejection)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Method (java.lang.reflect.Method)5 FieldMask (com.google.protobuf.FieldMask)4 GeneratedMessage (com.google.protobuf.GeneratedMessage)4 ThrowableMessage (io.spine.base.ThrowableMessage)4 EntityFilters (io.spine.client.EntityFilters)4