Search in sources :

Example 16 with Rejection

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

the class RejectionEnvelopeShould method obtain_command_context.

@Test
public void obtain_command_context() {
    final Rejection rejection = outerObject();
    final Command command = rejection.getContext().getCommand();
    final RejectionEnvelope envelope = toEnvelope(rejection);
    assertEquals(command.getContext(), envelope.getCommandContext());
}
Also used : Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 17 with Rejection

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

the class AggregateMessageDeliveryShould method postpone_rejections_dispatched_to_reactor_method.

@Test
public void postpone_rejections_dispatched_to_reactor_method() {
    assertNull(ReactingProject.getEventReceived());
    final Rejection rejection = cannotStartProject();
    boundedContext.getRejectionBus().post(rejection);
    assertNull(ReactingProject.getRejectionReceived());
    final RejectionEnvelope expectedEnvelope = RejectionEnvelope.of(rejection);
    final PostponingRejectionDelivery delivery = repository.getRejectionEndpointDelivery();
    final Map<ProjectId, RejectionEnvelope> postponedRejections = delivery.getPostponedRejections();
    assertTrue(postponedRejections.size() == 1 && postponedRejections.containsValue(expectedEnvelope));
    final ProjectId projectId = postponedRejections.keySet().iterator().next();
    delivery.deliverNow(projectId, postponedRejections.get(projectId));
    final AggCannotStartArchivedProject deliveredRejectionMsg = ReactingProject.getRejectionReceived();
    assertNotNull(deliveredRejectionMsg);
    assertEquals(getMessage(rejection), deliveredRejectionMsg);
}
Also used : Rejection(io.spine.core.Rejection) AggCannotStartArchivedProject(io.spine.test.aggregate.rejection.Rejections.AggCannotStartArchivedProject) ProjectId(io.spine.test.aggregate.ProjectId) PostponingRejectionDelivery(io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingRejectionDelivery) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 18 with Rejection

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

the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_a_command_dispatch.

/**
 * Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second
 * optional value returned from a command handler stores a single event.
 *
 * <p>The command handler that should return a pair is
 * {@link TaskAggregate#handle(AggAssignTask)
 * TaskAggregate#handle(AggAssignTask)}.
 */
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_command_dispatch() {
    final BoundedContext boundedContext = newTaskBoundedContext();
    final TenantId tenantId = newTenantId();
    final Command command = command(createTask(), 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);
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) 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 19 with Rejection

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

the class DelegatingRejectionDispatcher method getExternalDispatcher.

/**
 * Wraps this dispatcher to an external rejection dispatcher.
 *
 * @return the external rejection dispatcher proxying calls to the underlying instance
 */
public ExternalMessageDispatcher<I> getExternalDispatcher() {
    return new ExternalMessageDispatcher<I>() {

        @Override
        public Set<ExternalMessageClass> getMessageClasses() {
            final Set<RejectionClass> rejectionClasses = delegate.getExternalRejectionClasses();
            return ExternalMessageClass.fromRejectionClasses(rejectionClasses);
        }

        @Override
        public Set<I> dispatch(ExternalMessageEnvelope envelope) {
            final ExternalMessage externalMessage = envelope.getOuterObject();
            final Rejection rejection = unpack(externalMessage.getOriginalMessage());
            final Set<I> ids = delegate.dispatchRejection(RejectionEnvelope.of(rejection));
            return ids;
        }

        @Override
        public void onError(ExternalMessageEnvelope envelope, RuntimeException exception) {
            final MessageClass messageClass = envelope.getMessageClass();
            final String messageId = Stringifiers.toString(envelope.getId());
            final String errorMessage = format("Error dispatching external rejection (class: %s, id: %s)", messageClass, messageId);
            log().error(errorMessage, exception);
        }
    };
}
Also used : Rejection(io.spine.core.Rejection) ExternalMessageClass(io.spine.server.integration.ExternalMessageClass) ExternalMessageClass(io.spine.server.integration.ExternalMessageClass) MessageClass(io.spine.type.MessageClass) ExternalMessageEnvelope(io.spine.server.integration.ExternalMessageEnvelope) ExternalMessageDispatcher(io.spine.server.integration.ExternalMessageDispatcher) RejectionClass(io.spine.core.RejectionClass) ExternalMessage(io.spine.server.integration.ExternalMessage)

Example 20 with Rejection

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

the class AggregateTestEnv method cannotModifyDeletedEntity.

public static RejectionEnvelope cannotModifyDeletedEntity(Class<? extends Message> commandMessageCls) {
    final CannotModifyDeletedEntity rejectionMsg = CannotModifyDeletedEntity.newBuilder().build();
    final Command command = io.spine.server.commandbus.Given.ACommand.withMessage(Sample.messageOfType(commandMessageCls));
    final Rejection rejection = Rejections.createRejection(rejectionMsg, command);
    return RejectionEnvelope.of(rejection);
}
Also used : Rejection(io.spine.core.Rejection) CannotModifyDeletedEntity(io.spine.server.entity.rejection.StandardRejections.CannotModifyDeletedEntity) Command(io.spine.core.Command)

Aggregations

Rejection (io.spine.core.Rejection)36 Test (org.junit.Test)21 Command (io.spine.core.Command)13 Given.invalidProjectNameRejection (io.spine.server.rejection.given.Given.invalidProjectNameRejection)9 RejectionEnvelope (io.spine.core.RejectionEnvelope)8 Given.missingOwnerRejection (io.spine.server.rejection.given.Given.missingOwnerRejection)8 BoundedContext (io.spine.server.BoundedContext)6 Message (com.google.protobuf.Message)5 Ack (io.spine.core.Ack)5 Error (io.spine.base.Error)4 Rejections.toRejection (io.spine.core.Rejections.toRejection)4 Any (com.google.protobuf.Any)3 Event (io.spine.core.Event)3 TenantId (io.spine.core.TenantId)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 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)3 ProjectId (io.spine.test.procman.ProjectId)3