Search in sources :

Example 21 with Command

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

the class SingleTenantCommandBusShould method propagate_failures_to_failure_bus.

@Test
public void propagate_failures_to_failure_bus() {
    final FaultyHandler faultyHandler = new FaultyHandler(eventBus);
    commandBus.register(faultyHandler);
    final Command addTaskCommand = clearTenantId(addTask());
    commandBus.post(addTaskCommand, StreamObservers.<Response>noOpObserver());
    final InvalidProjectName failureThrowable = faultyHandler.getThrowable();
    final Failure expectedFailure = failureThrowable.toFailure(addTaskCommand);
    verify(failureBus).post(eq(expectedFailure), ArgumentMatchers.<StreamObserver<Response>>any());
}
Also used : Response(io.spine.base.Response) Command(io.spine.base.Command) InvalidProjectName(io.spine.test.failure.InvalidProjectName) Failure(io.spine.base.Failure) Test(org.junit.Test)

Example 22 with Command

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

the class ValidatorShould 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(CreateProject.getDefaultInstance());
    final Command commandWithEmptyMessage = Command.newBuilder().setId(generateId()).setMessage(invalidMessagePacked).setContext(createCommandContext()).build();
    final List<ConstraintViolation> violations = validator.validate(CommandEnvelope.of(commandWithEmptyMessage));
    assertEquals(3, violations.size());
}
Also used : Command(io.spine.base.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 23 with Command

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

the class CommandTestShould method stores_command_after_creation.

// This test verifies that Optionals
@SuppressWarnings("OptionalGetWithoutIsPresent")
// are initialized.
@Test
public void stores_command_after_creation() {
    final StringValue commandMessage = newUuidValue();
    final Command command = commandTest.createCommand(commandMessage);
    assertEquals(commandMessage, commandTest.commandMessage().get());
    assertEquals(command.getContext(), commandTest.commandContext().get());
    assertEquals(command, commandTest.command().get());
}
Also used : Command(io.spine.base.Command) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 24 with Command

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

the class CommandTestShould method create_command_with_custom_Timestamp.

@Test
public void create_command_with_custom_Timestamp() {
    final StringValue commandMessage = newUuidValue();
    final Timestamp timestamp = TimeTests.Past.minutesAgo(5);
    final Command command = commandTest.createCommand(commandMessage, timestamp);
    assertEquals(timestamp, command.getContext().getActorContext().getTimestamp());
}
Also used : Command(io.spine.base.Command) StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Command (io.spine.base.Command)24 Test (org.junit.Test)14 StringValue (com.google.protobuf.StringValue)6 Message (com.google.protobuf.Message)4 ConstraintViolation (io.spine.validate.ConstraintViolation)4 Timestamp (com.google.protobuf.Timestamp)3 TestActorRequestFactory (io.spine.test.TestActorRequestFactory)3 TenantId (io.spine.users.TenantId)3 Event (io.spine.base.Event)2 Response (io.spine.base.Response)2 CommandOperation (io.spine.server.tenant.CommandOperation)2 EqualsTester (com.google.common.testing.EqualsTester)1 Any (com.google.protobuf.Any)1 StreamObserver (io.grpc.stub.StreamObserver)1 ActorContext (io.spine.base.ActorContext)1 CommandContext (io.spine.base.CommandContext)1 CommandId (io.spine.base.CommandId)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 Failure (io.spine.base.Failure)1 StringChange (io.spine.change.StringChange)1