-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore : add tests * polish * implement code review comments
- Loading branch information
1 parent
4c8f499
commit 836420e
Showing
7 changed files
with
139 additions
and
18 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
73 changes: 71 additions & 2 deletions
73
...-integration/src/test/java/com/example/integration/kafkadsl/KafkaDslApplicationTests.java
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 |
---|---|---|
@@ -1,11 +1,80 @@ | ||
package com.example.integration.kafkadsl; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.example.integration.kafkadsl.config.KafkaAppProperties; | ||
import com.example.integration.kafkadsl.config.KafkaGateway; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.messaging.Message; | ||
|
||
@SpringBootTest(classes = ContainerConfiguration.class) | ||
@SpringBootTest(classes = {ContainerConfiguration.class}) | ||
class KafkaDslApplicationTests { | ||
|
||
@Autowired | ||
KafkaGateway kafkaGateway; | ||
|
||
@Autowired | ||
KafkaAppProperties kafkaAppProperties; | ||
|
||
@Autowired | ||
KafkaTemplate<String, String> kafkaTemplate; | ||
|
||
@Test | ||
void sendMessageToKafka() { | ||
String message = "test-message"; | ||
kafkaGateway.sendToKafka(message, kafkaAppProperties.topic()); | ||
Message<?> received = kafkaGateway.receiveFromKafka(); | ||
assertThat(received.getPayload()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
void receiveMessageFromKafka() { | ||
String message = "test-message"; | ||
kafkaTemplate.send(kafkaAppProperties.topic(), message); | ||
Message<?> received = kafkaGateway.receiveFromKafka(); | ||
assertThat(received.getPayload()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
void sendAndReceiveMultipleMessages() { | ||
for (int i = 0; i < 10; i++) { | ||
String message = "message" + i; | ||
kafkaGateway.sendToKafka(message, kafkaAppProperties.topic()); | ||
} | ||
for (int i = 0; i < 10; i++) { | ||
Message<?> received = kafkaGateway.receiveFromKafka(); | ||
assertThat(received.getPayload()).isEqualTo("message" + i); | ||
} | ||
} | ||
|
||
@Test | ||
void sendMessageToNewTopic() { | ||
String message = "new-topic-message"; | ||
kafkaGateway.sendToKafka(message, kafkaAppProperties.newTopic()); | ||
Message<?> received = kafkaGateway.receiveFromKafka(); | ||
assertThat(received.getPayload()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
void receiveMessageFromNewTopic() { | ||
String message = "new-topic-message"; | ||
kafkaTemplate.send(kafkaAppProperties.newTopic(), message); | ||
Message<?> received = kafkaGateway.receiveFromKafka(); | ||
assertThat(received.getPayload()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
void contextLoads() {} | ||
void sendAndReceiveMultipleMessagesFromNewTopic() { | ||
for (int i = 0; i < 10; i++) { | ||
String message = "new-topic-message" + i; | ||
kafkaGateway.sendToKafka(message, kafkaAppProperties.newTopic()); | ||
} | ||
for (int i = 0; i < 10; i++) { | ||
Message<?> received = kafkaGateway.receiveFromKafka(); | ||
assertThat(received.getPayload()).isEqualTo("new-topic-message" + i); | ||
} | ||
} | ||
} |
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