Search in sources :

Example 81 with Command

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

the class CommandStoreShould method set_command_status_to_OK_when_handler_returns.

@Test
public void set_command_status_to_OK_when_handler_returns() {
    commandBus.register(createProjectHandler);
    final Command command = requestFactory.command().create(createProjectMessage());
    commandBus.post(command, observer);
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final CommandId commandId = command.getId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.OK, status.getCode());
}
Also used : TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) CommandId(io.spine.core.CommandId) Test(org.junit.Test)

Example 82 with Command

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

the class CommandStoreShould method set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed.

@Test
public void set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed() {
    final List<Command> commands = newArrayList(createProject(), addTask(), startProject());
    final Duration delay = fromMinutes(5);
    // time to post passed
    final Timestamp schedulingTime = TimeTests.Past.minutesAgo(10);
    storeAsScheduled(commands, delay, schedulingTime);
    commandBus.rescheduleCommands();
    for (Command cmd : commands) {
        final CommandEnvelope envelope = CommandEnvelope.of(cmd);
        final Message msg = envelope.getMessage();
        final CommandId id = envelope.getId();
        // Check the expired status error was set.
        final ProcessingStatus status = getProcessingStatus(envelope);
        // Check that the logging was called.
        verify(log).errorExpiredCommand(msg, id);
        final Error expected = CommandExpiredException.commandExpired(cmd);
        assertEquals(expected, status.getError());
    }
}
Also used : Commands.getMessage(io.spine.core.Commands.getMessage) ThrowableMessage(io.spine.base.ThrowableMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.core.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 83 with Command

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

the class CommandValidatorViolationCheckShould method validate_command_and_return_violations_if_message_is_NOT_valid.

@Test
public void validate_command_and_return_violations_if_message_is_NOT_valid() {
    final Any invalidMessagePacked = AnyPacker.pack(CmdCreateProject.getDefaultInstance());
    final Command commandWithEmptyMessage = Command.newBuilder().setId(generateId()).setMessage(invalidMessagePacked).setContext(withRandomActor()).build();
    final List<ConstraintViolation> violations = inspect(CommandEnvelope.of(commandWithEmptyMessage));
    assertEquals(3, violations.size());
}
Also used : Command(io.spine.core.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 84 with Command

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

the class ExecutorCommandSchedulerShould method schedule_command_if_delay_is_set.

@Test
public void schedule_command_if_delay_is_set() {
    final Command cmdPrimary = commandFactory.createBasedOnContext(createProjectMessage(), context);
    final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    scheduler.schedule(cmdPrimary);
    verify(scheduler, never()).post(any(Command.class));
    verify(scheduler, timeout(DELAY_MS + WAIT_FOR_PROPAGATION_MS)).post(commandCaptor.capture());
    final Command actualCmd = commandCaptor.getValue();
    final Command expectedCmd = CommandScheduler.setSchedulingTime(cmdPrimary, getSchedulingTime(actualCmd));
    assertEquals(expectedCmd, actualCmd);
}
Also used : Command(io.spine.core.Command) Test(org.junit.Test)

Example 85 with Command

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

the class MultiTenantCommandBusShould method verify_tenant_id_attribute_if_multitenant.

/*
     * Command validation tests.
     ***************************/
@Test
public void verify_tenant_id_attribute_if_multitenant() {
    commandBus.register(createProjectHandler);
    final Command cmd = newCommandWithoutTenantId();
    commandBus.post(cmd, observer);
    checkCommandError(observer.firstResponse(), TENANT_UNKNOWN, InvalidCommandException.class, cmd);
}
Also used : Command(io.spine.core.Command) 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