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