Search in sources :

Example 21 with Error

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());
    }
}
Also used : Error(io.spine.base.Error) CommandValidationError(io.spine.base.CommandValidationError)

Example 22 with Error

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());
    }
}
Also used : 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) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.core.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 23 with Error

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());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) Status(io.spine.core.Status) Command(io.spine.core.Command) Ack(io.spine.core.Ack) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError) Test(org.junit.Test)

Example 24 with Error

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);
}
Also used : MessageRejection(io.spine.core.MessageRejection) StatusRuntimeException(io.grpc.StatusRuntimeException) Error(io.spine.base.Error) UnsupportedEventException(io.spine.server.event.UnsupportedEventException) ProjectCreated(io.spine.test.event.ProjectCreated) Test(org.junit.Test)

Example 25 with Error

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);
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) TypeUrl(io.spine.type.TypeUrl) AggregateMessageDispatcher.dispatchRejection(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection) Rejection(io.spine.core.Rejection) AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) AggregateTestEnv.newTaskBoundedContext(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext) Test(org.junit.Test)

Aggregations

Error (io.spine.base.Error)35 Test (org.junit.Test)19 Ack (io.spine.core.Ack)11 Command (io.spine.core.Command)8 Message (com.google.protobuf.Message)6 Metadata (io.grpc.Metadata)6 CommandValidationError (io.spine.core.CommandValidationError)6 CommandEnvelope (io.spine.core.CommandEnvelope)5 CommandId (io.spine.core.CommandId)5 Event (io.spine.core.Event)5 Rejection (io.spine.core.Rejection)4 TenantId (io.spine.core.TenantId)4 BoundedContext (io.spine.server.BoundedContext)4 ThrowableMessage (io.spine.base.ThrowableMessage)3 Status (io.spine.core.Status)3 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)3 CommandRecord (io.spine.server.commandbus.CommandRecord)3