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());
}
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());
}
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));
}
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));
}
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));
}
Aggregations