Search in sources :

Example 46 with Command

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

the class StorageShould method newStorageRecord.

private static CommandRecord newStorageRecord() {
    final Command command = Given.ACommand.createProject();
    final String commandType = CommandEnvelope.of(command).getTypeName().value();
    final CommandRecord.Builder builder = CommandRecord.newBuilder().setCommandType(commandType).setCommandId(command.getId()).setCommand(command).setTimestamp(getCurrentTime()).setStatus(ProcessingStatus.newBuilder().setCode(RECEIVED));
    return builder.build();
}
Also used : Command(io.spine.core.Command) CommandRecord(io.spine.server.commandbus.CommandRecord)

Example 47 with Command

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

the class StorageShould method store_command_with_error_and_generate_ID_if_needed.

@Test
public void store_command_with_error_and_generate_ID_if_needed() {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final Command command = factory.createCommand(createProjectMessage());
    final Error error = newError();
    repository.store(command, error);
    final List<CommandRecord> records = Lists.newArrayList(repository.iterator(ERROR));
    assertEquals(1, records.size());
    final String commandIdStr = Identifier.toString(records.get(0).getCommandId());
    assertFalse(commandIdStr.isEmpty());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) Command(io.spine.core.Command) Error(io.spine.base.Error) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 48 with Command

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

the class StorageShould method load_commands_by_status.

@Test
public void load_commands_by_status() {
    final List<Command> commands = ImmutableList.of(Given.ACommand.createProject(), Given.ACommand.addTask(), Given.ACommand.startProject());
    final CommandStatus status = SCHEDULED;
    store(commands, status);
    // store an extra command with another status
    repository.store(Given.ACommand.createProject(), ERROR);
    final Iterator<CommandRecord> iterator = repository.iterator(status);
    final List<Command> actualCommands = newArrayList(toCommandIterator(iterator));
    assertEquals(commands.size(), actualCommands.size());
    for (Command cmd : actualCommands) {
        assertTrue(commands.contains(cmd));
    }
}
Also used : Command(io.spine.core.Command) CommandStatus(io.spine.core.CommandStatus) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 49 with Command

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

the class StorageShould method store_command_with_error.

// We get right after we store.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void store_command_with_error() {
    final Command command = Given.ACommand.createProject();
    final CommandId commandId = command.getId();
    final Error error = newError();
    repository.store(command, error);
    final CommandRecord record = read(commandId).get();
    checkRecord(record, command, ERROR);
    assertEquals(error, record.getStatus().getError());
}
Also used : Command(io.spine.core.Command) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 50 with Command

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

the class CommandEnvelopeShould method obtain_command_context.

@Test
public void obtain_command_context() {
    final Command command = outerObject();
    final CommandEnvelope envelope = toEnvelope(command);
    assertEquals(command.getContext(), envelope.getCommandContext());
    assertSame(envelope.getCommandContext(), envelope.getMessageContext());
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) 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