Search in sources :

Example 21 with Command

use of io.spine.core.Command 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);
}
Also used : Command(io.spine.core.Command) PmCreateProject(io.spine.test.procman.command.PmCreateProject) PostponingCommandDelivery(io.spine.server.procman.given.PmMessageDeliveryTestEnv.PostponingCommandDelivery) ProjectId(io.spine.test.procman.ProjectId) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 22 with Command

use of io.spine.core.Command 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);
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 23 with Command

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

the class ProcessManagerShould method entityAlreadyArchived.

private static RejectionEnvelope entityAlreadyArchived(Class<? extends Message> commandMessageCls) {
    final Any id = Identifier.pack(ProcessManagerShould.class.getName());
    final EntityAlreadyArchived rejectionMessage = EntityAlreadyArchived.newBuilder().setEntityId(id).build();
    final Command command = ACommand.withMessage(Sample.messageOfType(commandMessageCls));
    final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
    return RejectionEnvelope.of(rejection);
}
Also used : Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) ACommand(io.spine.server.commandbus.Given.ACommand) EntityAlreadyArchived(io.spine.server.entity.rejection.StandardRejections.EntityAlreadyArchived) Any(com.google.protobuf.Any)

Example 24 with Command

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

the class Given method missingOwnerRejection.

public static Rejection missingOwnerRejection() {
    final ProjectId projectId = newProjectId();
    final ProjectRejections.MissingOwner msg = ProjectRejections.MissingOwner.newBuilder().setProjectId(projectId).build();
    final Command command = io.spine.server.commandbus.Given.ACommand.withMessage(Sample.messageOfType(RjRemoveOwner.class));
    return Rejections.createRejection(msg, command);
}
Also used : Command(io.spine.core.Command) ProjectRejections(io.spine.test.rejection.ProjectRejections) RjRemoveOwner(io.spine.test.rejection.command.RjRemoveOwner) ProjectId(io.spine.test.rejection.ProjectId)

Example 25 with Command

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

the class InvalidProjectNameSubscriber method on.

@Subscribe
public void on(InvalidProjectName rejection, RjUpdateProjectName commandMessage, CommandContext context) {
    final CommandFactory commandFactory = TestActorRequestFactory.newInstance(InvalidProjectNameSubscriber.class).command();
    final Command command = commandFactory.createWithContext(commandMessage, context);
    this.rejectionHandled = Rejections.createRejection(rejection, command);
}
Also used : Command(io.spine.core.Command) CommandFactory(io.spine.client.CommandFactory) Subscribe(io.spine.core.Subscribe)

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