use of io.spine.base.Error in project core-java by SpineEventEngine.
the class AbstractCommandBusTestSuite method checkCommandError.
static <E extends CommandException> void checkCommandError(Throwable throwable, CommandValidationError validationError, Class<E> exceptionClass, Command cmd) {
final Throwable cause = throwable.getCause();
assertEquals(exceptionClass, cause.getClass());
@SuppressWarnings("unchecked") final E exception = (E) cause;
assertEquals(cmd, exception.getCommand());
final Error error = exception.getError();
assertEquals(CommandValidationError.getDescriptor().getFullName(), error.getType());
assertEquals(validationError.getNumber(), error.getCode());
assertFalse(error.getMessage().isEmpty());
if (validationError == INVALID_COMMAND) {
assertFalse(error.getValidationError().getConstraintViolationList().isEmpty());
}
}
use of io.spine.base.Error 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());
}
}
use of io.spine.base.Error in project core-java by SpineEventEngine.
the class CommandServiceShould method return_error_status_if_command_is_unsupported.
@Test
public void return_error_status_if_command_is_unsupported() {
final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
final Command unsupportedCmd = factory.createCommand(StringValue.getDefaultInstance());
service.post(unsupportedCmd, responseObserver);
assertTrue(responseObserver.isCompleted());
final Ack result = responseObserver.firstResponse();
assertNotNull(result);
assertTrue(isNotDefault(result));
final Status status = result.getStatus();
assertEquals(ERROR, status.getStatusCase());
final Error error = status.getError();
assertEquals(CommandValidationError.getDescriptor().getFullName(), error.getType());
}
use of io.spine.base.Error in project core-java by SpineEventEngine.
the class StatusesShould method create_invalid_argument_status_exception.
@Test
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void create_invalid_argument_status_exception() {
final MessageRejection rejection = new UnsupportedEventException(Sample.messageOfType(ProjectCreated.class));
final StatusRuntimeException statusRuntimeEx = invalidArgumentWithCause(rejection);
final Error actualError = MetadataConverter.toError(statusRuntimeEx.getTrailers()).get();
assertEquals(Status.INVALID_ARGUMENT.getCode(), statusRuntimeEx.getStatus().getCode());
assertEquals(rejection, statusRuntimeEx.getCause());
assertEquals(rejection.asError(), actualError);
}
use of io.spine.base.Error in project core-java by SpineEventEngine.
the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_an_event_react.
/**
* Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
* value returned from a reaction on an event stores a single event.
*
* <p>The first event is produced while handling a command by the
* {@link TaskAggregate#handle(AggAssignTask) TaskAggregate#handle(AggAssignTask)}.
* Then as a reaction to this event a single event should be fired as part of the pair by
* {@link TaskAggregate#on(AggTaskAssigned) TaskAggregate#on(AggTaskAssigned)}.
*/
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_an_event_react() {
final BoundedContext boundedContext = newTaskBoundedContext();
final TenantId tenantId = newTenantId();
final Command command = command(assignTask(), tenantId);
final MemoizingObserver<Ack> observer = memoizingObserver();
boundedContext.getCommandBus().post(command, observer);
assertNull(observer.getError());
final List<Ack> responses = observer.responses();
assertSize(1, responses);
final Ack response = responses.get(0);
final io.spine.core.Status status = response.getStatus();
final Error emptyError = Error.getDefaultInstance();
assertEquals(emptyError, status.getError());
final Rejection emptyRejection = Rejection.getDefaultInstance();
assertEquals(emptyRejection, status.getRejection());
final List<Event> events = readAllEvents(boundedContext, tenantId);
assertSize(2, events);
final Event sourceEvent = events.get(0);
final TypeUrl taskAssignedType = TypeUrl.from(AggTaskAssigned.getDescriptor());
assertEquals(typeUrlOf(sourceEvent), taskAssignedType);
final Event reactionEvent = events.get(1);
final TypeUrl userNotifiedType = TypeUrl.from(AggUserNotified.getDescriptor());
assertEquals(typeUrlOf(reactionEvent), userNotifiedType);
}
Aggregations