Skip to content

Test Utilities

bloge-test provides focused helpers for unit and integration testing of BLOGE graphs. The goal is to make orchestration behavior easy to assert without building a custom test harness around every graph.

What the module provides

UtilityPurpose
MockOperatorLightweight stand-in operator with return, throw, delay, and recording modes
GraphTestRunnerTest-oriented graph execution wrapper with execution assertions
DslTestHelperDSL compilation helper for parser and compiler tests

MockOperator

MockOperator<I, O> is useful when you want to control node behavior precisely.

Common creation patterns

java
MockOperator<String, Integer> returns42 = MockOperator.returning(42);
MockOperator<String, Integer> fails = MockOperator.throwing(new RuntimeException("fail"));
MockOperator<String, Integer> delayed = MockOperator.delaying(Duration.ofMillis(200), 42);
MockOperator<String, Integer> recorder = MockOperator.recording();
MockOperator<String, Integer> custom = MockOperator.of(String::length);

It also records call history, last input, and invocation context for assertions.

GraphTestRunner

GraphTestRunner wraps execution and adds graph-level assertions.

java
var runner = new GraphTestRunner(Map.of(
    "fetch", fetchUserOperator,
    "transform", transformOperator
));

GraphResult result = runner.execute(graph, new GraphContext(Map.of("name", "test")));

runner.assertNodeExecuted("fetch");
runner.assertExecutionOrder("fetch", "transform");

Typical assertions include:

  • node executed / skipped / failed
  • partial execution order
  • final node outputs
  • execution log inspection

DslTestHelper

DslTestHelper is useful when the graph itself is a test subject.

java
var registry = new DefaultOperatorRegistry();
registry.register("MyOperator", MockOperator.returning("ok"));

var helper = new DslTestHelper(registry);
Graph graph = helper.compile("""
    graph test {
      node a : MyOperator {
        input { key = ctx.value }
      }
    }
    """);

It can also assert parse or compile failures directly.

BLOGE workflows are easiest to maintain when tests are layered:

  1. Operator unit tests for pure business logic
  2. Graph tests for orchestration shape and branch behavior
  3. DSL compilation tests for externally authored graph assets
  4. Module integration tests for Spring, durable runtime, or observability wiring

Useful scenarios to test

  • branch selection and skipped nodes
  • fallback behavior
  • timeout and retry policies
  • transform outputs consumed downstream
  • schema-sensitive field references in DSL
  • long-running or resumable flows through dedicated durable tests

Repository-level commands

bash
mvn test
mvn test -pl bloge-core
cd bloge-studio && npm test

Next steps