Search in sources :

Example 31 with Rejection

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

the class RejectionBusShould method call_subscriber_by_rejection_message_only.

@Test
public void call_subscriber_by_rejection_message_only() {
    final MultipleRejectionSubscriber subscriber = new MultipleRejectionSubscriber();
    rejectionBus.register(subscriber);
    final Rejection rejection = cannotModifyDeletedEntity(StringValue.class);
    rejectionBus.post(rejection);
    assertEquals(1, subscriber.numberOfSubscriberCalls());
    assertNull(subscriber.commandMessageClass());
}
Also used : Given.missingOwnerRejection(io.spine.server.rejection.given.Given.missingOwnerRejection) Rejection(io.spine.core.Rejection) Given.invalidProjectNameRejection(io.spine.server.rejection.given.Given.invalidProjectNameRejection) MultipleRejectionSubscriber(io.spine.server.rejection.given.MultipleRejectionSubscriber) Test(org.junit.Test)

Example 32 with Rejection

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

the class RejectionBusShould method pick_proper_consumer_by_consumer_id_when_delivering_to_delegates_of_same_rejection.

@Test
public void pick_proper_consumer_by_consumer_id_when_delivering_to_delegates_of_same_rejection() {
    final InvalidProjectNameDelegate first = new InvalidProjectNameDelegate();
    final AnotherInvalidProjectNameDelegate second = new AnotherInvalidProjectNameDelegate();
    final DelegatingRejectionDispatcher<String> firstDispatcher = DelegatingRejectionDispatcher.of(first);
    final DelegatingRejectionDispatcher<String> secondDispatcher = DelegatingRejectionDispatcher.of(second);
    rejectionBusWithPostponedExecution.register(firstDispatcher);
    rejectionBusWithPostponedExecution.register(secondDispatcher);
    final Rejection rejection = invalidProjectNameRejection();
    rejectionBusWithPostponedExecution.post(rejection);
    final Set<RejectionEnvelope> postponedRejections = postponedDelivery.getPostponedRejections();
    final RejectionEnvelope postponedRejection = postponedRejections.iterator().next();
    verify(delegateDispatcherExecutor, never()).execute(any(Runnable.class));
    postponedDelivery.deliverNow(postponedRejection, Consumers.idOf(firstDispatcher));
    assertTrue(first.isDispatchCalled());
    verify(delegateDispatcherExecutor).execute(any(Runnable.class));
    assertFalse(second.isDispatchCalled());
}
Also used : AnotherInvalidProjectNameDelegate(io.spine.server.rejection.given.AnotherInvalidProjectNameDelegate) Given.missingOwnerRejection(io.spine.server.rejection.given.Given.missingOwnerRejection) Rejection(io.spine.core.Rejection) Given.invalidProjectNameRejection(io.spine.server.rejection.given.Given.invalidProjectNameRejection) InvalidProjectNameDelegate(io.spine.server.rejection.given.InvalidProjectNameDelegate) AnotherInvalidProjectNameDelegate(io.spine.server.rejection.given.AnotherInvalidProjectNameDelegate) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 33 with Rejection

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

the class RejectionEnricherShould method boolean_enrich_rejection.

@Test
public void boolean_enrich_rejection() {
    final RejectionEnrichmentConsumer consumer = new RejectionEnrichmentConsumer();
    rejectionBus.register(consumer);
    final Rejection rejection = invalidProjectNameRejection();
    rejectionBus.post(rejection);
    final RejectionContext context = consumer.getContext();
    final Enrichment enrichment = context.getEnrichment();
    assertNotEquals(Enrichment.getDefaultInstance(), enrichment);
    final Optional<ProjectRejections.ProjectInfo> optional = Enrichments.getEnrichment(ProjectRejections.ProjectInfo.class, context);
    assertTrue(optional.isPresent());
    assertTrue(optional.get().getProjectName().startsWith(PROJECT_NAME_PREFIX));
}
Also used : Given.invalidProjectNameRejection(io.spine.server.rejection.given.Given.invalidProjectNameRejection) Rejection(io.spine.core.Rejection) Enrichment(io.spine.core.Enrichment) RejectionContext(io.spine.core.RejectionContext) ProjectRejections(io.spine.test.rejection.ProjectRejections) RejectionEnrichmentConsumer(io.spine.server.rejection.given.RejectionEnrichmentConsumer) Test(org.junit.Test)

Example 34 with Rejection

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

the class ExternalRejectionSubscriber method dispatch.

@Override
public Set<String> dispatch(ExternalMessageEnvelope envelope) {
    final ExternalMessage externalMessage = envelope.getOuterObject();
    final Message unpacked = AnyPacker.unpack(externalMessage.getOriginalMessage());
    if (!(unpacked instanceof Rejection)) {
        throw newIllegalStateException("Unexpected object %s while dispatching the external " + "rejection to the rejection subscriber.", Stringifiers.toString(unpacked));
    }
    final Rejection rejection = (Rejection) unpacked;
    checkArgument(isExternal(rejection.getContext()), "External rejection expected, but got %s", Stringifiers.toString(rejection));
    return delegate.dispatch(RejectionEnvelope.of(rejection));
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message)

Example 35 with Rejection

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

the class RejectionBusAdapter method markExternal.

@Override
ExternalMessageEnvelope markExternal(ExternalMessage externalMsg) {
    final Any packedEvent = externalMsg.getOriginalMessage();
    final Rejection rejection = AnyPacker.unpack(packedEvent);
    final Rejection.Builder rejectionBuilder = rejection.toBuilder();
    final RejectionContext modifiedContext = rejectionBuilder.getContext().toBuilder().setExternal(true).build();
    final Rejection marked = rejectionBuilder.setContext(modifiedContext).build();
    final ExternalMessage result = ExternalMessages.of(marked, externalMsg.getBoundedContextName());
    return ExternalMessageEnvelope.of(result, Rejections.getMessage(rejection));
}
Also used : Rejection(io.spine.core.Rejection) RejectionContext(io.spine.core.RejectionContext) Any(com.google.protobuf.Any)

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