Search in sources :

Example 1 with Rejection

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

the class IntegrationBusShould method not_dispatch_rejections_to_domestic_subscribers_if_they_requested_external.

@Test
public void not_dispatch_rejections_to_domestic_subscribers_if_they_requested_external() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithExtEntitySubscribers(transportFactory);
    final ProjectRejectionsExtSubscriber standaloneSubscriber = new ProjectRejectionsExtSubscriber();
    final RejectionBus rejectionBus = sourceContext.getRejectionBus();
    rejectionBus.register(standaloneSubscriber);
    assertNull(ProjectRejectionsExtSubscriber.getExternalRejection());
    assertNull(ProjectWizard.getExternalRejection());
    assertNull(ProjectCountAggregate.getExternalRejection());
    final Rejection rejection = cannotStartArchivedProject();
    rejectionBus.post(rejection);
    assertNull(ProjectRejectionsExtSubscriber.getExternalRejection());
    assertNull(ProjectWizard.getExternalRejection());
    assertNull(ProjectCountAggregate.getExternalRejection());
}
Also used : Rejection(io.spine.core.Rejection) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) BoundedContext(io.spine.server.BoundedContext) RejectionBus(io.spine.server.rejection.RejectionBus) ProjectRejectionsExtSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectRejectionsExtSubscriber) Test(org.junit.Test)

Example 2 with Rejection

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

the class IntegrationBusTestEnv method cannotStartArchivedProject.

// used to create a rejection
@SuppressWarnings("ThrowableNotThrown")
public static Rejection cannotStartArchivedProject() {
    final ProjectId projectId = projectId();
    final ItgStartProject cmdMessage = ItgStartProject.newBuilder().setProjectId(projectId).build();
    final Command startProjectCmd = toCommand(cmdMessage);
    final io.spine.test.integration.rejection.ItgCannotStartArchivedProject throwable = new io.spine.test.integration.rejection.ItgCannotStartArchivedProject(projectId);
    throwable.initProducer(AnyPacker.pack(projectId));
    final Rejection rejection = toRejection(throwable, startProjectCmd);
    return rejection;
}
Also used : Rejections.toRejection(io.spine.core.Rejections.toRejection) Rejection(io.spine.core.Rejection) ItgStartProject(io.spine.test.integration.command.ItgStartProject) Command(io.spine.core.Command) ProjectId(io.spine.test.integration.ProjectId) ItgCannotStartArchivedProject(io.spine.test.integration.rejection.IntegrationRejections.ItgCannotStartArchivedProject)

Example 3 with Rejection

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

the class PmMessageDeliveryShould method postpone_rejections_dispatched_to_reactor_method.

@Test
public void postpone_rejections_dispatched_to_reactor_method() {
    assertNull(ReactingProjectWizard.getEventReceived());
    final Rejection rejection = cannotStartProject();
    boundedContext.getRejectionBus().post(rejection);
    assertNull(ReactingProjectWizard.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 PmCannotStartArchivedProject deliveredRejectionMsg = ReactingProjectWizard.getRejectionReceived();
    assertNotNull(deliveredRejectionMsg);
    assertEquals(getMessage(rejection), deliveredRejectionMsg);
}
Also used : Rejection(io.spine.core.Rejection) PmCannotStartArchivedProject(io.spine.test.procman.rejection.Rejections.PmCannotStartArchivedProject) ProjectId(io.spine.test.procman.ProjectId) PostponingRejectionDelivery(io.spine.server.procman.given.PmMessageDeliveryTestEnv.PostponingRejectionDelivery) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 4 with Rejection

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

the class ProcessManagerRepositoryShould method dispatch_rejection.

@Test
public void dispatch_rejection() {
    final CommandEnvelope ce = requestFactory.generateEnvelope();
    final EntityAlreadyArchived rejectionMessage = EntityAlreadyArchived.newBuilder().setEntityId(Identifier.pack(newUuid())).build();
    final Rejection rejection = createRejection(rejectionMessage, ce.getCommand());
    final ProjectId id = ProcessManagerRepositoryTestEnv.GivenCommandMessage.ID;
    final Rejection.Builder builder = rejection.toBuilder().setContext(rejection.getContext().toBuilder().setProducerId(Identifier.pack(id)));
    final RejectionEnvelope re = RejectionEnvelope.of(builder.build());
    final Set<?> delivered = repository().dispatchRejection(re);
    assertTrue(delivered.contains(id));
    assertTrue(TestProcessManager.processed(rejectionMessage));
}
Also used : Rejections.createRejection(io.spine.core.Rejections.createRejection) Rejection(io.spine.core.Rejection) ProjectId(io.spine.test.procman.ProjectId) CommandEnvelope(io.spine.core.CommandEnvelope) PmThrowEntityAlreadyArchived(io.spine.test.procman.command.PmThrowEntityAlreadyArchived) EntityAlreadyArchived(io.spine.server.entity.rejection.StandardRejections.EntityAlreadyArchived) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 5 with Rejection

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

the class ProcessManagerShould method entityAlreadyArchived.

private static RejectionEnvelope entityAlreadyArchived(Class<? extends Message> commandMessageCls) {
    final Any id = Identifier.pack(ProcessManagerShould.class.getName());
    final EntityAlreadyArchived rejectionMessage = EntityAlreadyArchived.newBuilder().setEntityId(id).build();
    final Command command = ACommand.withMessage(Sample.messageOfType(commandMessageCls));
    final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
    return RejectionEnvelope.of(rejection);
}
Also used : Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) ACommand(io.spine.server.commandbus.Given.ACommand) EntityAlreadyArchived(io.spine.server.entity.rejection.StandardRejections.EntityAlreadyArchived) 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