Search in sources :

Example 11 with Error

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

the class MetadataConverterShould method return_error_extracted_form_metadata.

@Test
public void return_error_extracted_form_metadata() {
    final Error expectedError = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(expectedError);
    assertEquals(expectedError, MetadataConverter.toError(metadata).get());
}
Also used : Metadata(io.grpc.Metadata) Error(io.spine.base.Error) Test(org.junit.Test)

Example 12 with Error

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

the class MetadataConverterShould method return_metadata_containing_error.

// A part of the test.
@SuppressWarnings("ConstantConditions")
@Test
public void return_metadata_containing_error() throws InvalidProtocolBufferException {
    final Error error = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(error);
    final byte[] bytes = metadata.get(MetadataConverter.KEY);
    assertEquals(error, Error.parseFrom(bytes));
}
Also used : Metadata(io.grpc.Metadata) Error(io.spine.base.Error) Test(org.junit.Test)

Example 13 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.getCommandId();
        // 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.commandExpiredError(msg);
        assertEquals(expected, status.getError());
    }
}
Also used : 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) CommandEnvelope(io.spine.envelope.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.base.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 14 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)

Aggregations

Error (io.spine.base.Error)14 Test (org.junit.Test)7 Message (com.google.protobuf.Message)4 CommandId (io.spine.base.CommandId)4 CommandEnvelope (io.spine.envelope.CommandEnvelope)4 Command (io.spine.base.Command)3 CommandValidationError (io.spine.base.CommandValidationError)3 Identifiers.idToString (io.spine.base.Identifiers.idToString)3 CommandRecord (io.spine.server.commandbus.CommandRecord)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 ProtocolMessageEnum (com.google.protobuf.ProtocolMessageEnum)2 Metadata (io.grpc.Metadata)2 ValidationError (io.spine.validate.ValidationError)2 Duration (com.google.protobuf.Duration)1 Timestamp (com.google.protobuf.Timestamp)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 FailureThrowable (io.spine.base.FailureThrowable)1 CommandException (io.spine.server.commandbus.CommandException)1 CommandMessage.createProjectMessage (io.spine.server.commandbus.Given.CommandMessage.createProjectMessage)1