Search in sources :

Example 1 with RejectionEnvelope

use of io.spine.core.RejectionEnvelope 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 2 with RejectionEnvelope

use of io.spine.core.RejectionEnvelope 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 3 with RejectionEnvelope

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

the class RejectionBusShould method not_enrich_rejection_messages.

// as the RejectionBus instances do not support enrichment yet.
@Test
public void not_enrich_rejection_messages() {
    final Rejection original = invalidProjectNameRejection();
    final RejectionEnvelope enriched = rejectionBus.enrich(RejectionEnvelope.of(original));
    assertEquals(original, enriched.getOuterObject());
}
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) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 4 with RejectionEnvelope

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

the class RejectionBusShould method deliver_postponed_rejection_to_dispatcher_using_configured_executor.

@Test
public void deliver_postponed_rejection_to_dispatcher_using_configured_executor() {
    final BareDispatcher dispatcher = new BareDispatcher();
    rejectionBusWithPostponedExecution.register(dispatcher);
    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(dispatcher));
    assertTrue(dispatcher.isDispatchCalled());
    verify(delegateDispatcherExecutor).execute(any(Runnable.class));
}
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) RejectionEnvelope(io.spine.core.RejectionEnvelope) Test(org.junit.Test)

Example 5 with RejectionEnvelope

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

the class RejectionEnvelopeShould method obtain_actor_context.

@Test
public void obtain_actor_context() {
    final RejectionEnvelope rejection = toEnvelope(outerObject());
    final ActorContext actorContext = rejection.getActorContext();
    /* Since we're using `TestActorRequestFactory` initialized with the class of this test suite
           the actor ID should be the suite class name.
         */
    assertEquals(getClass().getName(), actorContext.getActor().getValue());
}
Also used : RejectionEnvelope(io.spine.core.RejectionEnvelope) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Aggregations

RejectionEnvelope (io.spine.core.RejectionEnvelope)14 Test (org.junit.Test)11 Rejection (io.spine.core.Rejection)8 Given.invalidProjectNameRejection (io.spine.server.rejection.given.Given.invalidProjectNameRejection)3 Given.missingOwnerRejection (io.spine.server.rejection.given.Given.missingOwnerRejection)3 Command (io.spine.core.Command)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 ProjectId (io.spine.test.procman.ProjectId)2 Message (com.google.protobuf.Message)1 ActorContext (io.spine.core.ActorContext)1 CommandEnvelope (io.spine.core.CommandEnvelope)1 Rejections.createRejection (io.spine.core.Rejections.createRejection)1 PostponingRejectionDelivery (io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingRejectionDelivery)1 EntityAlreadyArchived (io.spine.server.entity.rejection.StandardRejections.EntityAlreadyArchived)1 PostponingRejectionDelivery (io.spine.server.procman.given.PmMessageDeliveryTestEnv.PostponingRejectionDelivery)1 AnotherInvalidProjectNameDelegate (io.spine.server.rejection.given.AnotherInvalidProjectNameDelegate)1 BareDispatcher (io.spine.server.rejection.given.BareDispatcher)1 InvalidProjectNameDelegate (io.spine.server.rejection.given.InvalidProjectNameDelegate)1 ProjectId (io.spine.test.aggregate.ProjectId)1 AggCannotStartArchivedProject (io.spine.test.aggregate.rejection.Rejections.AggCannotStartArchivedProject)1