Search in sources :

Example 26 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_a_rejection_react.

/**
 * Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
 * value returned from a reaction on a rejection stores a single event.
 *
 * <p>The rejection is fired by the {@link TaskAggregate#handle(AggReassignTask)
 * TaskAggregate.handle(AggReassignTask)}
 * and handled by the {@link TaskAggregate#on(Rejections.AggCannotReassignUnassignedTask)
 * TaskAggregate.on(AggCannotReassignUnassignedTask)}.
 */
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_rejection_react() {
    final BoundedContext boundedContext = newTaskBoundedContext();
    final TenantId tenantId = newTenantId();
    final Command command = command(reassignTask(), 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(1, events);
    final Event reactionEvent = events.get(0);
    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)

Example 27 with Error

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

the class IntegrationBusShould method emit_unsupported_external_message_exception_if_message_type_is_unknown.

@Test
public void emit_unsupported_external_message_exception_if_message_type_is_unknown() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext boundedContext = contextWithTransport(transportFactory);
    final Event event = projectCreated();
    final BoundedContextName boundedContextName = BoundedContext.newName("External context ID");
    final ExternalMessage externalMessage = ExternalMessages.of(event, boundedContextName);
    final MemoizingObserver<Ack> observer = StreamObservers.memoizingObserver();
    boundedContext.getIntegrationBus().post(externalMessage, observer);
    final Error error = observer.firstResponse().getStatus().getError();
    assertFalse(Validate.isDefault(error));
    assertEquals(ExternalMessageValidationError.getDescriptor().getFullName(), error.getType());
    assertTrue(UNSUPPORTED_EXTERNAL_MESSAGE.getNumber() == error.getCode());
}
Also used : Ack(io.spine.core.Ack) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) Error(io.spine.base.Error) BoundedContext(io.spine.server.BoundedContext) BoundedContextName(io.spine.core.BoundedContextName) Test(org.junit.Test)

Example 28 with Error

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

the class UnsupportedExternalMessageException method asError.

@Override
public Error asError() {
    final String msgType = externalMessage.getDescriptorForType().getFullName();
    final String errMsg = format("External messages of the type `%s` are not supported.", msgType);
    final int errorCode = UNSUPPORTED_EXTERNAL_MESSAGE.getNumber();
    final String errorType = ExternalMessageValidationError.getDescriptor().getFullName();
    final Error error = Error.newBuilder().setType(errorType).setCode(errorCode).setMessage(errMsg).build();
    return error;
}
Also used : Error(io.spine.base.Error)

Example 29 with Error

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

the class DuplicateCommandShould method be_acknowledged_on_client_when_posted_to_an_aggregate.

@Test
public void be_acknowledged_on_client_when_posted_to_an_aggregate() {
    final TenantId tenantId = newTenantId();
    final Command command = command(createProject(), tenantId);
    client.post(command);
    final Ack ack = client.post(command);
    final Status status = ack.getStatus();
    final Error error = status.getError();
    final String errorType = error.getType();
    final String expectedErrorType = DuplicateCommandException.class.getCanonicalName();
    assertEquals(expectedErrorType, errorType);
}
Also used : Status(io.spine.core.Status) TenantId(io.spine.core.TenantId) DuplicateCommandTestEnv.newTenantId(io.spine.server.command.given.DuplicateCommandTestEnv.newTenantId) Command(io.spine.core.Command) Ack(io.spine.core.Ack) Error(io.spine.base.Error) Test(org.junit.Test)

Example 30 with Error

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

the class AbstractCommandBusTestSuite method checkCommandError.

static void checkCommandError(Ack sendingResult, CommandValidationError validationError, String errorType, Command cmd) {
    final Status status = sendingResult.getStatus();
    assertEquals(status.getStatusCase(), Status.StatusCase.ERROR);
    final CommandId commandId = cmd.getId();
    assertEquals(commandId, unpack(sendingResult.getMessageId()));
    final Error error = status.getError();
    assertEquals(errorType, error.getType());
    assertEquals(validationError.getNumber(), error.getCode());
    assertFalse(error.getMessage().isEmpty());
    if (validationError == INVALID_COMMAND) {
        assertFalse(error.getValidationError().getConstraintViolationList().isEmpty());
    }
}
Also used : Status(io.spine.core.Status) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError) CommandId(io.spine.core.CommandId)

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