Search in sources :

Example 11 with Command

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

the class ValidationFilter method isTenantIdValid.

private boolean isTenantIdValid(CommandEnvelope envelope, StreamObserver<Response> responseObserver) {
    final TenantId tenantId = envelope.getTenantId();
    final boolean tenantSpecified = !isDefault(tenantId);
    final Command command = envelope.getCommand();
    if (commandBus.isMultitenant()) {
        if (!tenantSpecified) {
            reportMissingTenantId(command, responseObserver);
            return false;
        }
    } else {
        if (tenantSpecified) {
            reportTenantIdInapplicable(command, responseObserver);
            return false;
        }
    }
    return true;
}
Also used : TenantId(io.spine.users.TenantId) Command(io.spine.base.Command)

Example 12 with Command

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

the class TypeNameShould method obtain_type_of_command.

@Test
public void obtain_type_of_command() {
    final Command command = requestFactory.command().create(newUuidValue());
    final TypeName typeName = TypeName.ofCommand(command);
    assertNotNull(typeName);
    assertEquals(StringValue.class.getSimpleName(), typeName.getSimpleName());
}
Also used : Command(io.spine.base.Command) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 13 with Command

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

the class TypeNameShould method obtain_type_name_of_event.

@Test
public void obtain_type_name_of_event() {
    final Command command = requestFactory.command().create(newUuidValue());
    final StringValue producerId = Wrapper.forString(getClass().getSimpleName());
    final EventFactory ef = EventFactory.newBuilder().setCommandId(Commands.generateId()).setProducerId(producerId).setCommandContext(command.getContext()).build();
    final Event event = ef.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
    final TypeName typeName = TypeName.ofEvent(event);
    assertNotNull(typeName);
    assertEquals(Timestamp.class.getSimpleName(), typeName.getSimpleName());
}
Also used : Command(io.spine.base.Command) EventFactory(io.spine.server.command.EventFactory) Event(io.spine.base.Event) StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 14 with Command

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

the class CommandStoreShould method set_command_status_to_failure_when_handler_throws_failure.

@Test
public void set_command_status_to_failure_when_handler_throws_failure() {
    final TestFailure failure = new TestFailure();
    final Command command = givenThrowingHandler(failure);
    final CommandId commandId = command.getId();
    final Message commandMessage = getMessage(command);
    commandBus.post(command, responseObserver);
    // Check that the logging was called.
    verify(log).failureHandling(eq(failure), eq(commandMessage), eq(commandId));
    // Check that the status has the correct code,
    // and the failure matches the thrown failure.
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.FAILURE, status.getCode());
    assertEquals(failure.toFailure(command).getMessage(), status.getFailure().getMessage());
}
Also used : TenantId(io.spine.users.TenantId) Commands.getMessage(io.spine.base.Commands.getMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.base.Command) CommandId(io.spine.base.CommandId) Test(org.junit.Test)

Example 15 with Command

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

the class FailureBusShould method invalidProjectNameFailure.

private static Failure invalidProjectNameFailure() {
    final ProjectId projectId = ProjectId.newBuilder().setId(newUuid()).build();
    final ProjectFailures.InvalidProjectName invalidProjectName = ProjectFailures.InvalidProjectName.newBuilder().setProjectId(projectId).build();
    final StringChange nameChange = StringChange.newBuilder().setNewValue("Too short").build();
    final UpdateProjectName updateProjectName = UpdateProjectName.newBuilder().setId(projectId).setNameUpdate(nameChange).build();
    final TenantId generatedTenantId = TenantId.newBuilder().setValue(newUuid()).build();
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(FailureBusShould.class, generatedTenantId);
    final Command command = factory.createCommand(updateProjectName);
    return Failures.createFailure(invalidProjectName, command);
}
Also used : TestActorRequestFactory(io.spine.test.TestActorRequestFactory) TenantId(io.spine.users.TenantId) Command(io.spine.base.Command) UpdateProjectName(io.spine.test.failure.command.UpdateProjectName) ProjectId(io.spine.test.failure.ProjectId) ProjectFailures(io.spine.test.failure.ProjectFailures) StringChange(io.spine.change.StringChange)

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