Search in sources :

Example 66 with Command

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

the class DuplicateCommandShould method not_be_acknowledged_on_client_when_not_sent.

@Test
public void not_be_acknowledged_on_client_when_not_sent() {
    final TenantId tenantId = newTenantId();
    final Command command = command(createProject(), tenantId);
    final Ack ack = client.post(command);
    final Status status = ack.getStatus();
    assertTrue(status.hasOk());
}
Also used : Status(io.spine.core.Status) TenantId(io.spine.core.TenantId) DuplicateCommandTestEnv.newTenantId(io.spine.server.command.given.DuplicateCommandTestEnv.newTenantId) Command(io.spine.core.Command) Ack(io.spine.core.Ack) Test(org.junit.Test)

Example 67 with Command

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

the class AbstractCommandBusTestSuite method storeAsScheduled.

void storeAsScheduled(Iterable<Command> commands, Duration delay, Timestamp schedulingTime) {
    for (Command cmd : commands) {
        final Command cmdWithSchedule = setSchedule(cmd, delay, schedulingTime);
        commandStore.store(cmdWithSchedule, SCHEDULED);
    }
}
Also used : Command(io.spine.core.Command)

Example 68 with Command

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

the class AbstractCommandBusTestSuite method newCommandWithoutContext.

static Command newCommandWithoutContext() {
    final Command cmd = createProject();
    final Command invalidCmd = cmd.toBuilder().setContext(CommandContext.getDefaultInstance()).build();
    return invalidCmd;
}
Also used : Command(io.spine.core.Command)

Example 69 with Command

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

the class AbstractCommandBusTestSuite method clearTenantId.

protected static Command clearTenantId(Command cmd) {
    final ActorContext.Builder withNoTenant = ActorContext.newBuilder().setTenantId(TenantId.getDefaultInstance());
    final Command result = cmd.toBuilder().setContext(cmd.getContext().toBuilder().setActorContext(withNoTenant)).build();
    return result;
}
Also used : Command(io.spine.core.Command) ActorContext(io.spine.core.ActorContext)

Example 70 with Command

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

the class AbstractCommandBusTestSuite method post_commands_in_bulk.

@Test
public void post_commands_in_bulk() {
    final Command first = newCommand();
    final Command second = newCommand();
    final List<Command> commands = newArrayList(first, second);
    // Some derived test suite classes may register the handler in setUp().
    // This prevents the repeating registration (which is an illegal operation).
    commandBus.unregister(createProjectHandler);
    commandBus.register(createProjectHandler);
    final CommandBus spy = spy(commandBus);
    spy.post(commands, StreamObservers.<Ack>memoizingObserver());
    @SuppressWarnings("unchecked") final ArgumentCaptor<Iterable<Command>> storingCaptor = forClass(Iterable.class);
    verify(spy).store(storingCaptor.capture());
    final Iterable<Command> storingArgs = storingCaptor.getValue();
    assertSize(commands.size(), storingArgs);
    assertContainsAll(storingArgs, first, second);
    final ArgumentCaptor<CommandEnvelope> postingCaptor = forClass(CommandEnvelope.class);
    verify(spy, times(2)).doPost(postingCaptor.capture());
    final List<CommandEnvelope> postingArgs = postingCaptor.getAllValues();
    assertSize(commands.size(), postingArgs);
    assertEquals(commands.get(0), postingArgs.get(0).getCommand());
    assertEquals(commands.get(1), postingArgs.get(1).getCommand());
    commandBus.unregister(createProjectHandler);
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

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