Search in sources :

Example 11 with Rejection

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

the class RejectionBusShould method call_subscriber_by_rejection_and_command_message_when_rejection_posted.

@Test
public void call_subscriber_by_rejection_and_command_message_when_rejection_posted() {
    final MultipleRejectionSubscriber subscriber = new MultipleRejectionSubscriber();
    rejectionBus.register(subscriber);
    final Class<RjStartProject> commandMessageCls = RjStartProject.class;
    final Rejection rejection = cannotModifyDeletedEntity(commandMessageCls);
    rejectionBus.post(rejection);
    assertEquals(1, subscriber.numberOfSubscriberCalls());
    assertEquals(commandMessageCls, subscriber.commandMessageClass());
}
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) MultipleRejectionSubscriber(io.spine.server.rejection.given.MultipleRejectionSubscriber) RjStartProject(io.spine.test.rejection.command.RjStartProject) Test(org.junit.Test)

Example 12 with Rejection

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

the class RejectionBusShould method checkRejection.

private void checkRejection(VerifiableSubscriber subscriber) {
    final Rejection rejection = missingOwnerRejection();
    rejectionBus.register(subscriber);
    rejectionBus.post(rejection);
    assertTrue(subscriber.isMethodCalled());
    subscriber.verifyGot(rejection);
}
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)

Example 13 with Rejection

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

the class SingleTenantCommandBusShould method propagate_rejections_to_rejection_bus.

@Test
public void propagate_rejections_to_rejection_bus() {
    final FaultyHandler faultyHandler = new FaultyHandler(eventBus);
    commandBus.register(faultyHandler);
    final Command addTaskCommand = clearTenantId(addTask());
    final MemoizingObserver<Ack> observer = memoizingObserver();
    commandBus.post(addTaskCommand, observer);
    final InvalidProjectName throwable = faultyHandler.getThrowable();
    final Rejection expectedRejection = toRejection(throwable, addTaskCommand);
    final Ack ack = observer.firstResponse();
    final Rejection actualRejection = ack.getStatus().getRejection();
    assertTrue(isNotDefault(actualRejection));
    assertEquals(unpack(expectedRejection.getMessage()), unpack(actualRejection.getMessage()));
}
Also used : Rejections.toRejection(io.spine.core.Rejections.toRejection) Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) InvalidProjectName(io.spine.test.reflect.InvalidProjectName) Ack(io.spine.core.Ack) Test(org.junit.Test)

Example 14 with Rejection

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

the class RejectionEnvelopeShould method outerObject.

@Override
protected Rejection outerObject() {
    final Message commandMessage = Int32Value.getDefaultInstance();
    final Command command = requestFactory.command().create(commandMessage);
    final Message rejectionMessage = CannotPerformBusinessOperation.newBuilder().setOperationId(newUuid()).build();
    final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
    return rejection;
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 15 with Rejection

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

the class RejectionEnvelopeShould method obtain_command_message.

@Test
public void obtain_command_message() {
    final Rejection rejection = outerObject();
    final Command command = rejection.getContext().getCommand();
    final Message commandMessage = AnyPacker.unpack(command.getMessage());
    final RejectionEnvelope envelope = toEnvelope(rejection);
    assertEquals(commandMessage, envelope.getCommandMessage());
}
Also used : Rejection(io.spine.core.Rejection) Message(com.google.protobuf.Message) Command(io.spine.core.Command) 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