Search in sources :

Example 76 with Command

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

the class CommandSchedulingShould method update_scheduling_time.

@Test
public void update_scheduling_time() {
    final Command cmd = requestFactory.command().create(toMessage(newUuid()));
    final Timestamp schedulingTime = getCurrentTime();
    final Command cmdUpdated = CommandScheduler.setSchedulingTime(cmd, schedulingTime);
    assertEquals(schedulingTime, cmdUpdated.getSystemProperties().getSchedulingTime());
}
Also used : Command(io.spine.core.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 77 with Command

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

the class CommandSchedulingShould method not_schedule_command_if_no_scheduling_options_are_set.

@Test
public void not_schedule_command_if_no_scheduling_options_are_set() {
    commandBus.register(new CreateProjectHandler());
    final Command command = createProject();
    commandBus.post(command, observer);
    verify(scheduler, never()).schedule(createProject());
    checkResult(command);
}
Also used : Command(io.spine.core.Command) Test(org.junit.Test)

Example 78 with Command

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

the class CommandStoreShould method set_command_status_to_error_when_handler_throws_unknown_Throwable.

@Test
public void set_command_status_to_error_when_handler_throws_unknown_Throwable() throws TestRejection, TestThrowable {
    ModelTests.clearModel();
    final Throwable throwable = new TestThrowable("Unexpected Throwable");
    final Command command = givenThrowingHandler(throwable);
    final CommandEnvelope envelope = CommandEnvelope.of(command);
    commandBus.post(command, observer);
    // Check that the logging was called.
    verify(log).errorHandlingUnknown(eq(throwable), eq(envelope.getMessage()), eq(envelope.getId()));
    // Check that the status and message.
    assertHasErrorStatusWithMessage(envelope, throwable.getMessage());
}
Also used : Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 79 with Command

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

the class CommandStoreShould method set_command_status_to_rejection_when_handler_throws_rejection.

@Test
public void set_command_status_to_rejection_when_handler_throws_rejection() {
    ModelTests.clearModel();
    final TestRejection rejection = new TestRejection();
    final Command command = givenThrowingHandler(rejection);
    final CommandId commandId = command.getId();
    final Message commandMessage = getMessage(command);
    commandBus.post(command, observer);
    // Check that the logging was called.
    verify(log).rejectedWith(eq(rejection), eq(commandMessage), eq(commandId));
    // Check that the status has the correct code,
    // and the rejection matches the thrown rejection.
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.REJECTED, status.getCode());
    assertEquals(toRejection(rejection, command).getMessage(), status.getRejection().getMessage());
}
Also used : TenantId(io.spine.core.TenantId) 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) CommandId(io.spine.core.CommandId) Test(org.junit.Test)

Example 80 with Command

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

the class CommandStoreShould method givenThrowingHandler.

private <E extends Throwable> Command givenThrowingHandler(E throwable) {
    final CommandHandler handler = new ThrowingCreateProjectHandler(throwable);
    commandBus.register(handler);
    final CmdCreateProject msg = createProjectMessage();
    final Command command = requestFactory.command().create(msg);
    return command;
}
Also used : CmdCreateProject(io.spine.test.command.CmdCreateProject) Command(io.spine.core.Command) CommandHandler(io.spine.server.command.CommandHandler)

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