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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations