Skip to main content

Testing and local development

This page covers the test-support module and the local infrastructure packaged with this repository.

Shared test-support module​

jeap-reaction-observer-service-test is a reusable JAR, not just an internal test folder. Its POM publishes:

  • ReactionIdentifiedV2EventBuilder for building reaction-identified-event v2 messages, optionally with a reaction model version
  • ReactionsObservedEventBuilder for building reactions-observed-event messages, optionally with a reaction model version and unidentified actions per reaction (TestUnidentifiedActions)
  • TestReaction and TestObservation model helpers. TestObservation.ofEvent and ofCommand create message observations, ofHttpRequest(provider, method, pattern) an http_request observation with the FQN provider METHOD pattern, and ofType(type, fqn) an observation of any type, e.g. one the service does not know. Their ids are built as the library builds them: type: followed by the FQN with %, :, # and & percent-encoded
  • jEAP Kafka test dependencies used by consumer-side tests

The module is consumed by the in-repo Kafka and web tests and can also be used by downstream services that test their integration with the Reaction Observer Service contracts.

In-repo test coverage verified​

The source tree contains and the Maven reactor successfully executed tests for:

  • domain graph extraction/building
  • Kafka listeners for both event types
  • persistence repositories and Flyway migrations
  • web controllers, graph fingerprinting, and integration flows across Kafka + persistence + API

Notable verified behaviours from tests include:

  • ReactionIdentifiedEventListener accepts full, trigger-only, and action-only payloads
  • ReactionsObservedEventListener maps timeframe/count data into persisted ObservedReaction batches
  • aggregated statistics can be queried after persisting identified and observed reactions
  • graph endpoints return 404 for empty system/component subgraphs and variant-specific graphs for message types
  • reactions with HTTP requests, unknown observation types and FQNs of 1000 characters are stored, the graph is built, and the API v1 shows their message part only (ReactionGraphExtensionsIT)
  • a reaction triggered by an HTTP request with an FQN of 512 characters, whose reaction id is longer than 1024 characters, is stored, counted and in the graph (ReactionGraphExtensionsIT); the longest reaction id of 1582 characters is stored, also if it does not compress and the name of the component has 1000 characters, so that it fits the unique index on component and reaction id (ReactionRepositoryImplTest)
  • the API v2 shows the same reactions with every kind of interface, an operation the caller named (//<host>[/<context>] <METHOD> /{*}) is an HTTP operation with where the call went as provider, the graph of an HTTP operation is fetched with the path from the index of interfaces, and the OpenAPI document of the v2 describes the kinds of node and what a node of an unknown kind is read as (ReactionGraphV2IT)
  • an event with a reaction model version below 1 is rejected as a permanent error and not stored (ReactionIdentifiedEventListenerTest, ReactionsObservedEventListenerTest)
  • the reaction model version and the unidentified actions of the events are stored, and an event built without them is stored with reaction model version 1 and without unidentified actions (ReactionModelVersionIT). These are the defaults of the event schemas, which give an event that predates the fields the same values; no test sends such an event
  • a further identification of a known reaction only replaces its reaction model version, and concurrent first identifications create exactly one reaction
  • counts of unknown reaction ids are skipped and counted, and the other counts of the event are saved

Downstream tests that replace GraphHolder​

As of 11.0.0 the graph resources answer from GraphHolder.getSnapshot() - one immutable snapshot holding the graph, the fingerprint of every subgraph and the index payloads - instead of reading getGraph() per request. A downstream test that replaces the GraphHolder bean with a mock and stubs getGraph() only therefore finds no snapshot; the resource says so rather than failing with a NullPointerException.

Two ways out, the second one preferable because it exercises what production does:

// stub the snapshot
when(graphHolder.getSnapshot()).thenReturn(graphSnapshotFactory.of(graph));

// or use the real bean and hand it a graph
@Autowired GraphHolder graphHolder;
graphHolder.setGraph(graph);

Local runtime environment​

docker/docker-compose.yml provides:

  • PostgreSQL 18.6 on port 5432
  • Kafka broker on port 9092
  • Schema Registry on port 7781

The matching Spring profile is application-localtest.yml in the web module. It also configures the authorization server the service requires - a local jEAP OAuth mock server on port 8180. The mock is needed when making requests with bearer tokens.

Useful commands​

./mvnw -pl jeap-reaction-observer-web -am install
./mvnw -pl jeap-reaction-observer-web test
./mvnw -pl jeap-reaction-observer-kafka test
./mvnw -pl jeap-reaction-observer-micrometer test
./mvnw -pl jeap-reaction-observer-persistence test

A successful reactor test run used:

./mvnw -q -am -pl jeap-reaction-observer-domain,jeap-reaction-observer-kafka,jeap-reaction-observer-micrometer,jeap-reaction-observer-persistence,jeap-reaction-observer-web test