use of io.spine.core.Rejection in project core-java by SpineEventEngine.
the class StorageShould method set_rejected_command_status.
// We get right after we update status.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void set_rejected_command_status() {
givenNewRecord();
final Rejection rejection = newRejection();
repository.updateStatus(id, rejection);
final CommandRecord actual = read(id).get();
assertEquals(REJECTED, actual.getStatus().getCode());
assertEquals(rejection, actual.getStatus().getRejection());
}
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_an_event_react.
/**
* Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
* value returned from a reaction on an event stores a single event.
*
* <p>The first event is produced while handling a command by the
* {@link TaskAggregate#handle(AggAssignTask) TaskAggregate#handle(AggAssignTask)}.
* Then as a reaction to this event a single event should be fired as part of the pair by
* {@link TaskAggregate#on(AggTaskAssigned) TaskAggregate#on(AggTaskAssigned)}.
*/
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_an_event_react() {
final BoundedContext boundedContext = newTaskBoundedContext();
final TenantId tenantId = newTenantId();
final Command command = command(assignTask(), 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(2, events);
final Event sourceEvent = events.get(0);
final TypeUrl taskAssignedType = TypeUrl.from(AggTaskAssigned.getDescriptor());
assertEquals(typeUrlOf(sourceEvent), taskAssignedType);
final Event reactionEvent = events.get(1);
final TypeUrl userNotifiedType = TypeUrl.from(AggUserNotified.getDescriptor());
assertEquals(typeUrlOf(reactionEvent), userNotifiedType);
}
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_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);
}
use of io.spine.core.Rejection in project core-java by SpineEventEngine.
the class AggregateMessageDeliveryTestEnv method cannotStartProject.
public static Rejection cannotStartProject() {
final ProjectId projectId = projectId();
final AggStartProject cmdMessage = AggStartProject.newBuilder().setProjectId(projectId).build();
final Command command = createCommand(cmdMessage);
final Rejection result = Rejections.toRejection(new io.spine.test.aggregate.rejection.AggCannotStartArchivedProject(projectId, Lists.<ProjectId>newArrayList()), command);
return result;
}
use of io.spine.core.Rejection in project core-java by SpineEventEngine.
the class IntegrationBusShould method throw_on_mismatch_of_external_attribute_during_dispatching.
@Test
public void throw_on_mismatch_of_external_attribute_during_dispatching() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext sourceContext = contextWithTransport(transportFactory);
final RejectionSubscriber rejectionSubscriber = new ExternalMismatchSubscriber();
sourceContext.getRejectionBus().register(rejectionSubscriber);
sourceContext.getIntegrationBus().register(rejectionSubscriber);
final Rejection rejection = cannotStartArchivedProject();
try {
sourceContext.getRejectionBus().post(rejection);
fail("An exception is expected.");
} catch (Exception e) {
final String exceptionMsg = e.getMessage();
assertContains("external", exceptionMsg);
}
}
Aggregations