Search in sources :

Example 1 with Error

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

the class EventValidatorShould method validate_event_messages.

@Test
public void validate_event_messages() {
    final MessageValidator messageValidator = mock(MessageValidator.class);
    when(messageValidator.validate(any(Message.class))).thenReturn(newArrayList(ConstraintViolation.getDefaultInstance(), ConstraintViolation.getDefaultInstance()));
    final Event event = eventFactory.createEvent(Sample.messageOfType(ProjectCreated.class));
    final EventValidator eventValidator = new EventValidator(messageValidator);
    final Optional<MessageInvalid> error = eventValidator.validate(EventEnvelope.of(event));
    assertTrue(error.isPresent());
    final Error actualError = error.get().asError();
    assertEquals(EventValidationError.getDescriptor().getFullName(), actualError.getType());
}
Also used : Message(com.google.protobuf.Message) Event(io.spine.core.Event) Error(io.spine.base.Error) EventValidationError(io.spine.core.EventValidationError) MessageValidator(io.spine.validate.MessageValidator) MessageInvalid(io.spine.core.MessageInvalid) ProjectCreated(io.spine.test.event.ProjectCreated) Test(org.junit.Test)

Example 2 with Error

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

the class RejectionBusShould method report_dead_messages.

@Test
public void report_dead_messages() {
    final MemoizingObserver<Ack> observer = memoizingObserver();
    rejectionBus.post(missingOwnerRejection(), observer);
    assertTrue(observer.isCompleted());
    final Ack result = observer.firstResponse();
    assertNotNull(result);
    assertEquals(ERROR, result.getStatus().getStatusCase());
    final Error error = result.getStatus().getError();
    assertEquals(UnhandledRejectionException.class.getCanonicalName(), error.getType());
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) Test(org.junit.Test)

Example 3 with Error

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

the class StorageShould method set_error_command_status.

// We get right after we update status.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void set_error_command_status() {
    givenNewRecord();
    final Error error = newError();
    repository.updateStatus(id, error);
    final CommandRecord actual = read(id).get();
    assertEquals(ERROR, actual.getStatus().getCode());
    assertEquals(error, actual.getStatus().getError());
}
Also used : Error(io.spine.base.Error) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 4 with Error

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

the class StorageShould method store_command_with_error_and_generate_ID_if_needed.

@Test
public void store_command_with_error_and_generate_ID_if_needed() {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final Command command = factory.createCommand(createProjectMessage());
    final Error error = newError();
    repository.store(command, error);
    final List<CommandRecord> records = Lists.newArrayList(repository.iterator(ERROR));
    assertEquals(1, records.size());
    final String commandIdStr = Identifier.toString(records.get(0).getCommandId());
    assertFalse(commandIdStr.isEmpty());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) Command(io.spine.core.Command) Error(io.spine.base.Error) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 5 with Error

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

the class StorageShould method store_command_with_error.

// We get right after we store.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void store_command_with_error() {
    final Command command = Given.ACommand.createProject();
    final CommandId commandId = command.getId();
    final Error error = newError();
    repository.store(command, error);
    final CommandRecord record = read(commandId).get();
    checkRecord(record, command, ERROR);
    assertEquals(error, record.getStatus().getError());
}
Also used : Command(io.spine.core.Command) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) 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