Search in sources :

Example 1 with Failure

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

the class FailureBusShould method call_subscriber_when_failure_posted.

@Test
public void call_subscriber_when_failure_posted() {
    final InvalidProjectNameSubscriber subscriber = new InvalidProjectNameSubscriber();
    final Failure failure = invalidProjectNameFailure();
    failureBus.register(subscriber);
    failureBus.post(failure);
    final Failure handled = subscriber.getFailureHandled();
    // Compare the content without command ID, which is different in the remembered
    assertEquals(failure.getMessage(), handled.getMessage());
    assertEquals(failure.getContext().getCommand().getMessage(), handled.getContext().getCommand().getMessage());
    assertEquals(failure.getContext().getCommand().getContext(), handled.getContext().getCommand().getContext());
}
Also used : Failure(io.spine.base.Failure) Test(org.junit.Test)

Example 2 with Failure

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

the class FailureBusShould method deliver_postponed_failure_to_dispatcher_using_configured_executor.

@Test
public void deliver_postponed_failure_to_dispatcher_using_configured_executor() {
    final BareDispatcher dispatcher = new BareDispatcher();
    failureBusWithPostponedExecution.register(dispatcher);
    final Failure failure = invalidProjectNameFailure();
    failureBusWithPostponedExecution.post(failure);
    final Set<FailureEnvelope> postponedFailures = postponedDelivery.getPostponedFailures();
    final FailureEnvelope postponedFailure = postponedFailures.iterator().next();
    verify(delegateDispatcherExecutor, never()).execute(any(Runnable.class));
    postponedDelivery.deliverNow(postponedFailure, dispatcher.getClass());
    assertTrue(dispatcher.isDispatchCalled());
    verify(delegateDispatcherExecutor).execute(any(Runnable.class));
}
Also used : FailureEnvelope(io.spine.envelope.FailureEnvelope) Failure(io.spine.base.Failure) Test(org.junit.Test)

Example 3 with Failure

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

the class FailureBusShould method not_call_dispatchers_if_dispatcher_failure_execution_postponed.

@Test
public void not_call_dispatchers_if_dispatcher_failure_execution_postponed() {
    final BareDispatcher dispatcher = new BareDispatcher();
    failureBusWithPostponedExecution.register(dispatcher);
    final Failure failure = invalidProjectNameFailure();
    failureBusWithPostponedExecution.post(failure);
    assertFalse(dispatcher.isDispatchCalled());
    final boolean failurePostponed = postponedDelivery.isPostponed(failure, dispatcher);
    assertTrue(failurePostponed);
}
Also used : Failure(io.spine.base.Failure) Test(org.junit.Test)

Example 4 with Failure

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

the class FailureBusShould method not_enrich_failure_messages.

// as the FailureBus instances do not support enrichment yet.
@Test
public void not_enrich_failure_messages() {
    final Failure original = Failure.getDefaultInstance();
    final Failure enriched = failureBus.enrich(original);
    assertEquals(original, enriched);
}
Also used : Failure(io.spine.base.Failure) Test(org.junit.Test)

Example 5 with Failure

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

the class FailureEnvelopeShould method setUp.

@Before
public void setUp() {
    this.commandMessage = Int32Value.getDefaultInstance();
    this.command = requestFactory.command().create(commandMessage);
    this.failureMessage = CannotPerformBusinessOperation.newBuilder().setOperationId(Identifiers.newUuid()).build();
    final Failure failure = Failures.createFailure(failureMessage, command);
    this.envelope = FailureEnvelope.of(failure);
}
Also used : Failure(io.spine.base.Failure) Before(org.junit.Before)

Aggregations

Failure (io.spine.base.Failure)8 Test (org.junit.Test)6 Message (com.google.protobuf.Message)1 Command (io.spine.base.Command)1 Response (io.spine.base.Response)1 FailureEnvelope (io.spine.envelope.FailureEnvelope)1 CommandRecord (io.spine.server.commandbus.CommandRecord)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 InvalidProjectName (io.spine.test.failure.InvalidProjectName)1 Before (org.junit.Before)1