Search in sources :

Example 26 with Rejection

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

the class IntegrationBusShould method dispatch_rejections_from_one_BC_to_external_subscribers_of_another_BC.

@Test
public void dispatch_rejections_from_one_BC_to_external_subscribers_of_another_BC() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithTransport(transportFactory);
    contextWithExternalSubscribers(transportFactory);
    assertNull(ProjectRejectionsExtSubscriber.getExternalRejection());
    assertNull(ProjectCountAggregate.getExternalRejection());
    assertNull(ProjectWizard.getExternalRejection());
    final Rejection rejection = cannotStartArchivedProject();
    sourceContext.getRejectionBus().post(rejection);
    final Message rejectionMessage = AnyPacker.unpack(rejection.getMessage());
    assertEquals(rejectionMessage, ProjectRejectionsExtSubscriber.getExternalRejection());
    assertEquals(rejectionMessage, ProjectCountAggregate.getExternalRejection());
    assertEquals(rejectionMessage, ProjectWizard.getExternalRejection());
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 27 with Rejection

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

the class PmMessageDeliveryTestEnv method cannotStartProject.

public static Rejection cannotStartProject() {
    final ProjectId projectId = projectId();
    final PmStartProject cmdMessage = PmStartProject.newBuilder().setProjectId(projectId).build();
    final Command command = createCommand(cmdMessage);
    final Rejection result = toRejection(throwableWith(projectId), command);
    return result;
}
Also used : Rejections.toRejection(io.spine.core.Rejections.toRejection) Rejection(io.spine.core.Rejection) PmStartProject(io.spine.test.procman.command.PmStartProject) Command(io.spine.core.Command) ProjectId(io.spine.test.procman.ProjectId)

Example 28 with Rejection

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

the class DelegatingRejectionDispatcherShould method setUp.

@Before
public void setUp() {
    delegate = new EmptyRejectionDispatcherDelegate();
    delegatingDispatcher = DelegatingRejectionDispatcher.of(delegate);
    final Command command = requestFactory.generateCommand();
    final Message rejectionMessage = EntityAlreadyDeleted.newBuilder().setEntityId(Identifier.pack(getClass().getName())).build();
    final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
    rejectionEnvelope = RejectionEnvelope.of(rejection);
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) Command(io.spine.core.Command) Before(org.junit.Before)

Example 29 with Rejection

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

the class RejectionBusShould method call_subscriber_when_rejection_posted.

@Test
public void call_subscriber_when_rejection_posted() {
    final InvalidProjectNameSubscriber subscriber = new InvalidProjectNameSubscriber();
    final Rejection rejection = invalidProjectNameRejection();
    rejectionBus.register(subscriber);
    rejectionBus.post(rejection);
    final Rejection handled = subscriber.getRejectionHandled();
    // Compare the content without command ID, which is different in the remembered
    assertEquals(rejection.getMessage(), handled.getMessage());
    assertEquals(rejection.getContext().getCommand().getMessage(), handled.getContext().getCommand().getMessage());
    assertEquals(rejection.getContext().getCommand().getContext(), handled.getContext().getCommand().getContext());
}
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) InvalidProjectNameSubscriber(io.spine.server.rejection.given.InvalidProjectNameSubscriber) Test(org.junit.Test)

Example 30 with Rejection

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

the class RejectionBusShould method not_call_dispatchers_if_dispatcher_rejection_execution_postponed.

@Test
public void not_call_dispatchers_if_dispatcher_rejection_execution_postponed() {
    final BareDispatcher dispatcher = new BareDispatcher();
    rejectionBusWithPostponedExecution.register(dispatcher);
    final Rejection rejection = invalidProjectNameRejection();
    rejectionBusWithPostponedExecution.post(rejection);
    assertFalse(dispatcher.isDispatchCalled());
    final boolean rejectionPostponed = postponedDelivery.isPostponed(rejection, dispatcher);
    assertTrue(rejectionPostponed);
}
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) BareDispatcher(io.spine.server.rejection.given.BareDispatcher) Test(org.junit.Test)

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