visit
Hence, if we want to test SUT(system under test ) in isolation, then we need the following stubs:
Knowing all this, let's start preparing a test environment in a test project. I will be using Citrus 3.2.1 version settings. I talked about how to generate a template Citrus project in one of the previous articles, now let's immediately start configuring the pom.xml and citrus-context.xml files:
<dependency>
<groupId>com.consol.citrus</groupId>
<artifactId>citrus-kafka</artifactId>
<version>${citrus.version}</version>
</dependency>
xmlns:citrus-kafka="//www.citrusframework.org/schema/kafka/config"
xsi:schemaLocation=
//www.citrusframework.org/schema/kafka/config
//www.citrusframework.org/schema/kafka/config/citrus-kafka-config.xsd
<citrus-kafka:embedded-server id="embeddedKafka"
kafka-server-port="9590"
topics="QUEUE_IN_NAME, QUEUE_OUT_NAME"
partitions="10"/>
<citrus-kafka:endpoint id="mqProducer"
server="localhost:9590"
topic="QUEUE_IN_NAME"/>
<citrus-kafka:endpoint id="mqConsumer"
server="localhost:9590"
topic="QUEUE_OUT_NAME"/>
package tests;
import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.testng.TestNGCitrusSupport;
import org.testng.annotations.Test;
import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;
import static com.consol.citrus.actions.SendMessageAction.Builder.send;
public class TestKafka extends TestNGCitrusSupport {
public TestContext context;
@Test(description = "Kafka test")
@CitrusTest
public void getTestActions() {
this.context = citrus.getCitrusContext().createTestContext();
run(send("mqProducer")
.message()
.body("Message content to send")
);
run(receive("mqConsumer")
.message()
.body("Expected message content"));
}
}