Search in sources :

Example 1 with RejectionContext

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

the class EventStoreShould method not_store_enrichment_for_origin_of_RejectionContext_type.

@Test
public void not_store_enrichment_for_origin_of_RejectionContext_type() {
    final RejectionContext originContext = RejectionContext.newBuilder().setEnrichment(withOneAttribute()).build();
    final Event event = projectCreated(Time.getCurrentTime());
    final Event enriched = event.toBuilder().setContext(event.getContext().toBuilder().setRejectionContext(originContext)).build();
    eventStore.append(enriched);
    final MemoizingObserver<Event> observer = memoizingObserver();
    eventStore.read(EventStreamQuery.getDefaultInstance(), observer);
    final RejectionContext loadedOriginContext = observer.responses().get(0).getContext().getRejectionContext();
    assertTrue(isDefault(loadedOriginContext.getEnrichment()));
}
Also used : RejectionContext(io.spine.core.RejectionContext) Event(io.spine.core.Event) Test(org.junit.Test)

Example 2 with RejectionContext

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

the class AggregateStorageShould method not_store_enrichment_for_origin_of_RejectionContext_type.

@Test
public void not_store_enrichment_for_origin_of_RejectionContext_type() {
    final RejectionContext origin = RejectionContext.newBuilder().setEnrichment(withOneAttribute()).build();
    final EventContext context = EventContext.newBuilder().setRejectionContext(origin).build();
    final Event event = Event.newBuilder().setId(newEventId()).setContext(context).setMessage(Any.getDefaultInstance()).build();
    storage.writeEvent(id, event);
    final RejectionContext loadedOrigin = storage.read(newReadRequest(id)).get().getEvent(0).getContext().getRejectionContext();
    assertTrue(isDefault(loadedOrigin.getEnrichment()));
}
Also used : EventContext(io.spine.core.EventContext) RejectionContext(io.spine.core.RejectionContext) Event(io.spine.core.Event) Test(org.junit.Test)

Example 3 with RejectionContext

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

the class RejectionEnricherShould method boolean_enrich_rejection.

@Test
public void boolean_enrich_rejection() {
    final RejectionEnrichmentConsumer consumer = new RejectionEnrichmentConsumer();
    rejectionBus.register(consumer);
    final Rejection rejection = invalidProjectNameRejection();
    rejectionBus.post(rejection);
    final RejectionContext context = consumer.getContext();
    final Enrichment enrichment = context.getEnrichment();
    assertNotEquals(Enrichment.getDefaultInstance(), enrichment);
    final Optional<ProjectRejections.ProjectInfo> optional = Enrichments.getEnrichment(ProjectRejections.ProjectInfo.class, context);
    assertTrue(optional.isPresent());
    assertTrue(optional.get().getProjectName().startsWith(PROJECT_NAME_PREFIX));
}
Also used : Given.invalidProjectNameRejection(io.spine.server.rejection.given.Given.invalidProjectNameRejection) Rejection(io.spine.core.Rejection) Enrichment(io.spine.core.Enrichment) RejectionContext(io.spine.core.RejectionContext) ProjectRejections(io.spine.test.rejection.ProjectRejections) RejectionEnrichmentConsumer(io.spine.server.rejection.given.RejectionEnrichmentConsumer) Test(org.junit.Test)

Example 4 with RejectionContext

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

the class RejectionReactorMethodShould method invoke_reactor_method.

@Test
public void invoke_reactor_method() throws InvocationTargetException {
    final RValidThreeParams reactorObject = new RValidThreeParams();
    final RejectionReactorMethod reactor = new RejectionReactorMethod(reactorObject.getMethod());
    final InvalidProjectName rejectionMessage = Given.RejectionMessage.invalidProjectName();
    final RejectionContext.Builder builder = RejectionContext.newBuilder();
    final CommandContext commandContext = CommandContext.newBuilder().setTargetVersion(3040).build();
    final RjUpdateProjectName commandMessage = RjUpdateProjectName.getDefaultInstance();
    builder.setCommand(Command.newBuilder().setMessage(pack(commandMessage)).setContext(commandContext));
    final RejectionContext rejectionContext = builder.build();
    reactor.invoke(reactorObject, rejectionMessage, rejectionContext);
    assertEquals(rejectionMessage, reactorObject.getLastRejectionMessage());
    assertEquals(commandMessage, reactorObject.getLastCommandMessage());
    assertEquals(commandContext, reactorObject.getLastCommandContext());
}
Also used : CommandContext(io.spine.core.CommandContext) InvalidProjectName(io.spine.test.reflect.ReflectRejections.InvalidProjectName) RejectionContext(io.spine.core.RejectionContext) RjUpdateProjectName(io.spine.test.rejection.command.RjUpdateProjectName) RValidThreeParams(io.spine.server.rejection.given.RejectionReactorMethodTestEnv.RValidThreeParams) Test(org.junit.Test)

Example 5 with RejectionContext

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

the class RejectionSubscriberMethodShould method invoke_subscriber_method.

@Test
public void invoke_subscriber_method() throws InvocationTargetException {
    final ValidThreeParams subscriberObject = new ValidThreeParams();
    final RejectionSubscriberMethod method = new RejectionSubscriberMethod(subscriberObject.getMethod());
    final InvalidProjectName rejectionMessage = Given.RejectionMessage.invalidProjectName();
    final RejectionContext.Builder builder = RejectionContext.newBuilder();
    final CommandContext commandContext = CommandContext.newBuilder().setTargetVersion(1020).build();
    final RjUpdateProjectName commandMessage = RjUpdateProjectName.getDefaultInstance();
    builder.setCommand(Command.newBuilder().setMessage(pack(commandMessage)).setContext(commandContext));
    final RejectionContext rejectionContext = builder.build();
    method.invoke(subscriberObject, rejectionMessage, rejectionContext);
    assertEquals(rejectionMessage, subscriberObject.getLastRejectionMessage());
    assertEquals(commandMessage, subscriberObject.getLastCommandMessage());
    assertEquals(commandContext, subscriberObject.getLastCommandContext());
}
Also used : CommandContext(io.spine.core.CommandContext) ValidThreeParams(io.spine.server.rejection.given.RejectionSubscriberMethodTestEnv.ValidThreeParams) InvalidProjectName(io.spine.test.reflect.ReflectRejections.InvalidProjectName) RejectionContext(io.spine.core.RejectionContext) RjUpdateProjectName(io.spine.test.rejection.command.RjUpdateProjectName) Test(org.junit.Test)

Aggregations

RejectionContext (io.spine.core.RejectionContext)7 Test (org.junit.Test)5 CommandContext (io.spine.core.CommandContext)2 Event (io.spine.core.Event)2 Rejection (io.spine.core.Rejection)2 InvalidProjectName (io.spine.test.reflect.ReflectRejections.InvalidProjectName)2 RjUpdateProjectName (io.spine.test.rejection.command.RjUpdateProjectName)2 Any (com.google.protobuf.Any)1 Command (io.spine.core.Command)1 Enrichment (io.spine.core.Enrichment)1 EventContext (io.spine.core.EventContext)1 Given.invalidProjectNameRejection (io.spine.server.rejection.given.Given.invalidProjectNameRejection)1 RejectionEnrichmentConsumer (io.spine.server.rejection.given.RejectionEnrichmentConsumer)1 RValidThreeParams (io.spine.server.rejection.given.RejectionReactorMethodTestEnv.RValidThreeParams)1 ValidThreeParams (io.spine.server.rejection.given.RejectionSubscriberMethodTestEnv.ValidThreeParams)1 ProjectRejections (io.spine.test.rejection.ProjectRejections)1