Map

Assertions API

The API map for the assertion layer. For deeper walkthroughs, see Record, Topic, and Extraction assertions.

For deeper walkthroughs and overload examples, see:

KafkaAssertions

Package: io.typecheck.wiretap.core.assertions

Entry point for AssertJ-style Kafka assertions.

PropertyDefaultDescription
assertThat(record)—Starts a record assertion chain.
assertThatRecord(topic)—Reads one String record from the shared broker and starts a record assertion chain.
assertThatRecord(topic, targetType)—Reads one typed record from the shared broker and starts a record assertion chain.
assertThatTopic(topic)—Starts a topic assertion chain using the shared broker.
assertThatTopic(topic, broker)—Starts a topic assertion chain.
assertThatTopic(topic, bootstrapServers)—Starts a topic assertion chain without a broker bean.
assertThatChoreography()—Starts a key-scoped multi-topic choreography assertion.
Java
KafkaAssertions.assertThatRecord("orders-topic", OrderEvent.class)
    .hasKeyMatching(startsWith("order-"))
    .hasJsonPath("$.product", equalTo("Widget"));

KafkaRecordAssert

Assertions for a single ConsumerRecord.

PropertyDefaultDescription
metadata—hasTopic, hasPartition, hasOffset
key and value—hasKey, hasKeyMatching, hasNoKey, hasValue, hasValueMatching, hasNoValue
headers—hasHeader, hasHeaderWithValue, doesNotHaveHeader, hasHeaders
payload structure—hasJsonPath, including Hamcrest nullValue(), doesNotHaveJsonPath
Java
KafkaAssertions.assertThat(record)
    .hasHeader("X-Correlation-Id")
    .hasHeaderWithValue("X-System-Origin", equalTo("checkout-service"))
    .hasJsonPath("$.status", "CREATED");

KafkaTopicAssert

Assertions for topic existence, topology, and record content.

PropertyDefaultDescription
existence—exists, doesNotExist
topology—hasPartitionCount
record counts—hasRecordCount, hasRecordCountAtLeast, isEmpty
listener readiness—hasReadyListeners, hasReadyListener, including multi-listener varargs overloads
content checks—containsRecordWithKey, containsRecordWithKeyMatching, containsRecordWithValue, containsRecordWithValueMatching, containsRecordSatisfying, allRecordsSatisfy, noRecordSatisfies, plus typed overloads
record sequences—records() and records(Class) for ordered and snapshot assertions
extraction—extractingKeys, extractingValues, extractingJsonPath with typed overloads
Java
KafkaAssertions.assertThatTopic("orders-topic")
    .exists()
    .hasPartitionCount(2)
    .hasRecordCountAtLeast(1);

Typed topic example

Java
KafkaAssertions.assertThatTopic("orders-topic")
    .containsRecordWithValue(OrderEvent.class, expectedOrder)
    .containsRecordWithValueMatching(OrderEvent.class, hasProperty("quantity", equalTo(2)))
    .containsRecordSatisfying(OrderEvent.class, record -> record.hasJsonPath("$.product", equalTo("Widget")));

Extraction example

Java
KafkaAssertions.assertThatTopic("orders-topic")
    .extractingJsonPath(OrderEvent.class, "$.status")
    .containsExactly("CREATED", "CREATED");

KafkaRecordsAssert

Assertions for exact record sequences and JSON snapshots read from a topic.

PropertyDefaultDescription
inOrder()—Requires expectations to match topic read order.
inAnyOrder()—Allows exact expectations to match in any order.
containingExactly(...)—Applies one record assertion lambda per observed record.
ignoringJsonPaths(...)—Deletes volatile JSON paths before snapshot comparison.
containsExactlyJson(...)—Compares normalized JSON snapshots.
Java
KafkaAssertions.assertThatTopic("orders-topic")
    .hasReadyListeners("orderListener", "auditListener")
    .records(OrderEvent.class)
    .inOrder()
    .containingExactly(
        record -> record.hasJsonPath("$.status", "CREATED"),
        record -> record.hasJsonPath("$.status", "PAID"));

KafkaChoreographyAssert

Assertions for proving one business key moved through every expected Kafka topic.

PropertyDefaultDescription
forKey(key)—Scopes the choreography to one record key.
input(topic)—Starts an input-topic step; supports listener readiness checks.
topic(topic).contains()—Requires the scoped key to appear on the topic.
verify()—Checks every step and reports a table with the first missing topic.
Java
KafkaAssertions.assertThatChoreography()
    .forKey("ord-7782")
    .topic("orders.in").contains()
    .topic("orders.routed").contains()
    .topic("audit.log").contains()
    .verify();

KafkaPayloadMatchers

Reusable Hamcrest matchers for common Kafka payload fields. Import them statically and pass them to existing matcher-based assertion overloads such as hasJsonPath, hasHeaderWithValue, hasKeyMatching, and topic scan assertions.

PropertyDefaultDescription
base64—validBase64(), base64DecodedAs(FileType), base64DecodedAsOneOf(...), base64DecodedSize(...), base64DecodedUtf8(...), base64DecodedBytes(...)
file types—PDF, PNG, JPEG, GIF, WEBP, ZIP, GZIP, JSON, XML, TEXT, UNKNOWN
identifiers—validUuid(), validUlid(), validUri()
time fields—validIsoInstant(), isoInstantWithin(...), isoInstantAfter(...)
JSON strings—validJson(), jsonEquivalentTo(...), jsonPath(...)
strings—nonBlankString(), matchesRegex(...)
Java
KafkaAssertions.assertThat(record)
    .hasHeaderWithValue("X-Correlation-Id", validUuid())
    .hasJsonPath("$.attachment.data", validBase64())
    .hasJsonPath("$.attachment.data", base64DecodedAs(PDF))
    .hasJsonPath("$.attachment.data", base64DecodedSize(greaterThan(512)));

KafkaAssertions.assertThat(record)
    .hasJsonPath("$.publishedAt", validIsoInstant())
    .hasJsonPath("$.metadata", jsonPath("$.source", equalTo("checkout")));