-
-
Save kasramp/f1bd75425e19612a3f100f7ec3ae51dd to your computer and use it in GitHub Desktop.
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
class UserKafkaProducerTest { | |
@Test | |
void testWriteToKafka() throws InterruptedException, JsonProcessingException { | |
// Create a user and write to Kafka | |
User user = new User("11111", "John", "Wick"); | |
producer.writeToKafka(user); | |
// Read the message (John Wick user) with a test consumer from Kafka and assert its properties | |
ConsumerRecord<String, String> message = records.poll(500, TimeUnit.MILLISECONDS); | |
assertNotNull(message); | |
assertEquals("11111", message.key()); | |
User result = objectMapper.readValue(message.value(), User.class); | |
assertNotNull(result); | |
assertEquals("John", result.getFirstName()); | |
assertEquals("Wick", result.getLastName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment