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());
}
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());
}
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);
}
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());
}
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));
}
Aggregations