Search in sources :

Example 1 with ProjectId

use of io.spine.test.event.ProjectId in project core-java by SpineEventEngine.

the class EventEnricherShould method enrich_event_with_several_fields_by_same_source_id.

@Test
public void enrich_event_with_several_fields_by_same_source_id() {
    final ProjectCreated msg = projectCreated();
    final ProjectId projectId = msg.getProjectId();
    eventBus.post(createEvent(msg));
    assertEquals(getProjectName.apply(projectId), subscriber.projectCreatedEnrichment.getProjectName());
    assertEquals(getProjectOwnerId.apply(projectId), subscriber.projectCreatedEnrichment.getOwnerId());
}
Also used : ProjectId(io.spine.test.event.ProjectId) ProjectCreated(io.spine.test.event.ProjectCreated) Test(org.junit.Test)

Example 2 with ProjectId

use of io.spine.test.event.ProjectId in project core-java by SpineEventEngine.

the class EventEnricherShould method enrich_event_if_function_added_at_runtime.

@Test
public void enrich_event_if_function_added_at_runtime() {
    final GetProjectMaxMemberCount function = new GetProjectMaxMemberCount();
    enricher.registerFieldEnrichment(ProjectId.class, Integer.class, function);
    final ProjectCreated msg = projectCreated();
    final ProjectId projectId = msg.getProjectId();
    eventBus.post(createEvent(msg));
    // the `function` was specially implemented to return non-null ints.
    @SuppressWarnings("ConstantConditions") final int expectedValue = function.apply(projectId);
    assertEquals(expectedValue, subscriber.projectCreatedDynamicEnrichment.getMaxMemberCount());
}
Also used : GetProjectMaxMemberCount(io.spine.server.event.Given.Enrichment.GetProjectMaxMemberCount) ProjectId(io.spine.test.event.ProjectId) ProjectCreated(io.spine.test.event.ProjectCreated) Test(org.junit.Test)

Example 3 with ProjectId

use of io.spine.test.event.ProjectId in project core-java by SpineEventEngine.

the class EventBusShould method allow_enrichment_configuration_at_runtime_if_enricher_not_set_previously.

@Test
public void allow_enrichment_configuration_at_runtime_if_enricher_not_set_previously() {
    setUp(null);
    assertNull(eventBus.getEnricher());
    final Class<ProjectId> eventFieldClass = ProjectId.class;
    final Class<String> enrichmentFieldClass = String.class;
    final Function<ProjectId, String> function = new Function<ProjectId, String>() {

        @Override
        public String apply(@Nullable ProjectId input) {
            checkNotNull(input);
            return input.toString();
        }
    };
    eventBus.addFieldEnrichment(eventFieldClass, enrichmentFieldClass, function);
    final EventEnricher enricher = eventBus.getEnricher();
    assertNotNull(enricher);
}
Also used : Function(com.google.common.base.Function) EventEnricher(io.spine.server.event.enrich.EventEnricher) ProjectId(io.spine.test.event.ProjectId) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 4 with ProjectId

use of io.spine.test.event.ProjectId in project core-java by SpineEventEngine.

the class EventEnricherShould method enrich_several_events_with_same_enrichment_message_with_wildcard_by.

@Test
public void enrich_several_events_with_same_enrichment_message_with_wildcard_by() {
    final ProjectCompleted completed = Given.EventMessage.projectCompleted();
    final ProjectStarred starred = Given.EventMessage.projectStarred();
    final ProjectId completedProjectId = completed.getProjectId();
    final ProjectId starredProjectId = starred.getProjectId();
    eventBus.post(createEvent(completed));
    eventBus.post(createEvent(starred));
    assertEquals(getProjectName.apply(completedProjectId), subscriber.projectCompletedEnrichment.getProjectName());
    assertEquals(getProjectName.apply(starredProjectId), subscriber.projectStarredEnrichment.getProjectName());
}
Also used : ProjectCompleted(io.spine.test.event.ProjectCompleted) ProjectId(io.spine.test.event.ProjectId) ProjectStarred(io.spine.test.event.ProjectStarred) Test(org.junit.Test)

Example 5 with ProjectId

use of io.spine.test.event.ProjectId in project core-java by SpineEventEngine.

the class EventBusShould method allow_enrichment_configuration_at_runtime_if_enricher_previously_set.

@Test
public void allow_enrichment_configuration_at_runtime_if_enricher_previously_set() {
    final EventEnricher enricher = mock(EventEnricher.class);
    setUp(enricher);
    final Class<ProjectId> eventFieldClass = ProjectId.class;
    final Class<String> enrichmentFieldClass = String.class;
    final Function<ProjectId, String> function = new Function<ProjectId, String>() {

        @Override
        public String apply(@Nullable ProjectId input) {
            checkNotNull(input);
            return input.toString();
        }
    };
    eventBus.addFieldEnrichment(eventFieldClass, enrichmentFieldClass, function);
    verify(enricher).registerFieldEnrichment(eq(eventFieldClass), eq(enrichmentFieldClass), eq(function));
}
Also used : Function(com.google.common.base.Function) EventEnricher(io.spine.server.event.enrich.EventEnricher) ProjectId(io.spine.test.event.ProjectId) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Aggregations

ProjectId (io.spine.test.event.ProjectId)5 Test (org.junit.Test)5 Function (com.google.common.base.Function)2 EventEnricher (io.spine.server.event.enrich.EventEnricher)2 ProjectCreated (io.spine.test.event.ProjectCreated)2 Nullable (javax.annotation.Nullable)2 GetProjectMaxMemberCount (io.spine.server.event.Given.Enrichment.GetProjectMaxMemberCount)1 ProjectCompleted (io.spine.test.event.ProjectCompleted)1 ProjectStarred (io.spine.test.event.ProjectStarred)1