Search in sources :

Example 6 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 7 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 8 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)

Example 9 with Rejection

use of io.spine.core.Rejection 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 10 with Rejection

use of io.spine.core.Rejection 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)

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