-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for assertion Key, Headers and Topic of a Kafka Message (#215)
* enrich assertion of kafka with metadata information such as; topic, key, and headers * modify test for metadataCondition * encapsulate the incoming message with ObservedMessage * add header test * test is fixed * rename example app classes
- Loading branch information
Showing
10 changed files
with
221 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import stove.spring.example.application.handlers.ProductCreatedEvent | |
import stove.spring.example.application.services.SupplierPermission | ||
import stove.spring.example.infrastructure.couchbase.CouchbaseProperties | ||
import stove.spring.example.infrastructure.messaging.kafka.consumers.BusinessException | ||
import stove.spring.example.infrastructure.messaging.kafka.consumers.ProductCreateEvent | ||
import stove.spring.example.infrastructure.messaging.kafka.consumers.CreateProductCommand | ||
|
||
class ExampleTest : FunSpec({ | ||
test("bridge should work") { | ||
|
@@ -55,13 +55,13 @@ class ExampleTest : FunSpec({ | |
} | ||
|
||
http { | ||
postAndExpectJson<String>(uri = "/api/product/create", body = productCreateRequest.some()) { actual -> | ||
actual shouldBe "OK" | ||
postAndExpectBodilessResponse(uri = "/api/product/create", body = productCreateRequest.some()) { actual -> | ||
actual.status shouldBe 200 | ||
} | ||
} | ||
|
||
kafka { | ||
shouldBePublished<ProductCreatedEvent> { actual -> | ||
shouldBePublished<ProductCreatedEvent> { | ||
actual.id == productCreateRequest.id && | ||
actual.name == productCreateRequest.name && | ||
actual.supplierId == productCreateRequest.supplierId | ||
|
@@ -99,7 +99,7 @@ class ExampleTest : FunSpec({ | |
|
||
test("should throw error when send product create event for the not allowed supplier") { | ||
TestSystem.validate { | ||
val productCreateEvent = ProductCreateEvent(3L, name = "product name", 97L) | ||
val productCreateEvent = CreateProductCommand(3L, name = "product name", 97L) | ||
val supplierPermission = SupplierPermission(productCreateEvent.supplierId, isAllowed = false) | ||
|
||
wiremock { | ||
|
@@ -112,7 +112,7 @@ class ExampleTest : FunSpec({ | |
|
||
kafka { | ||
publish("trendyol.stove.service.product.create.0", productCreateEvent) | ||
shouldBeConsumed<ProductCreateEvent> { actual -> | ||
shouldBeConsumed<CreateProductCommand> { | ||
actual.id == productCreateEvent.id | ||
} | ||
} | ||
|
@@ -121,34 +121,32 @@ class ExampleTest : FunSpec({ | |
|
||
test("should create new product when send product create event for the allowed supplier") { | ||
TestSystem.validate { | ||
val productCreateEvent = ProductCreateEvent(4L, name = "product name", 96L) | ||
val supplierPermission = SupplierPermission(productCreateEvent.supplierId, isAllowed = true) | ||
val createProductCommand = CreateProductCommand(4L, name = "product name", 96L) | ||
val supplierPermission = SupplierPermission(createProductCommand.supplierId, isAllowed = true) | ||
|
||
wiremock { | ||
mockGet( | ||
"/suppliers/${productCreateEvent.id}/allowed", | ||
"/suppliers/${createProductCommand.id}/allowed", | ||
statusCode = 200, | ||
responseBody = supplierPermission.some() | ||
) | ||
} | ||
|
||
kafka { | ||
publish("trendyol.stove.service.product.create.0", productCreateEvent) | ||
shouldBeConsumed<ProductCreateEvent> { actual -> | ||
actual.id == productCreateEvent.id | ||
} | ||
shouldBePublished<ProductCreatedEvent> { actual -> | ||
actual.id == productCreateEvent.id && | ||
actual.name == productCreateEvent.name && | ||
actual.supplierId == productCreateEvent.supplierId | ||
publish("trendyol.stove.service.product.create.0", createProductCommand) | ||
shouldBePublished<ProductCreatedEvent> { | ||
actual.id == createProductCommand.id && | ||
actual.name == createProductCommand.name && | ||
actual.supplierId == createProductCommand.supplierId && | ||
metadata.headers["X-UserEmail"] == "[email protected]" | ||
} | ||
} | ||
|
||
couchbase { | ||
shouldGet<ProductCreateRequest>("product:${productCreateEvent.id}") { actual -> | ||
actual.id shouldBe productCreateEvent.id | ||
actual.name shouldBe productCreateEvent.name | ||
actual.supplierId shouldBe productCreateEvent.supplierId | ||
shouldGet<ProductCreateRequest>("product:${createProductCommand.id}") { actual -> | ||
actual.id shouldBe createProductCommand.id | ||
actual.name shouldBe createProductCommand.name | ||
actual.supplierId shouldBe createProductCommand.supplierId | ||
} | ||
} | ||
} | ||
|
@@ -159,10 +157,13 @@ class ExampleTest : FunSpec({ | |
TestSystem.validate { | ||
kafka { | ||
publish("trendyol.stove.service.product.failing.0", FailingEvent(5L)) | ||
shouldBeFailed<FailingEvent> { actual, exception -> | ||
actual.id == 5L && exception is BusinessException | ||
shouldBeFailed<FailingEvent> { | ||
actual.id == 5L && reason is BusinessException | ||
} | ||
|
||
shouldBeFailed<FailingEvent> { | ||
actual == FailingEvent(5L) && reason is BusinessException | ||
} | ||
shouldBeFailed(message = FailingEvent(5L), exception = BusinessException("Failing product create event")) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
examples/spring-example/src/test/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<logger name="org.testcontainers" level="WARN"/> | ||
<logger name="com.couchbase" level="OFF"/>" | ||
<logger name="tc" level="OFF"/> | ||
<logger name="com.github.dockerjava" level="OFF"/> | ||
<logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="OFF"/> | ||
<logger name="org.apache" level="OFF"/> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.