forked from kafbat/kafka-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BE: Closes kafbat#71 Messages: Show headers duplicates
- Loading branch information
Showing
9 changed files
with
140 additions
and
20 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
51 changes: 51 additions & 0 deletions
51
api/src/test/java/io/kafbat/ui/serdes/ProducerRecordCreatorTest.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.kafbat.ui.serdes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import io.kafbat.ui.exception.ValidationException; | ||
import io.kafbat.ui.serde.api.Serde; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.common.header.internals.RecordHeader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ProducerRecordCreatorTest { | ||
|
||
@Test | ||
void createWithHeaders() { | ||
Serde.Serializer keySerializer = mock(Serde.Serializer.class); | ||
Serde.Serializer valueSerializer = mock(Serde.Serializer.class); | ||
|
||
ProducerRecordCreator recordCreator = new ProducerRecordCreator(keySerializer, valueSerializer); | ||
Map<String, Object> headersMap = Map.of( | ||
"headerKey1", "headerValue1", | ||
"headerKey2", List.of("headerValue2", "headerValue3") | ||
); | ||
ProducerRecord<byte[], byte[]> record = recordCreator.create("topic", 1, "key", "value", headersMap); | ||
|
||
assertNotNull(record.headers()); | ||
assertEquals(3, record.headers().toArray().length); | ||
assertThat(record.headers()).containsExactlyInAnyOrder( | ||
new RecordHeader("headerKey1", "headerValue1".getBytes()), | ||
new RecordHeader("headerKey2", "headerValue2".getBytes()), | ||
new RecordHeader("headerKey2", "headerValue3".getBytes()) | ||
); | ||
} | ||
|
||
@Test | ||
void createWithInvalidHeaderValue() { | ||
Serde.Serializer keySerializer = mock(Serde.Serializer.class); | ||
Serde.Serializer valueSerializer = mock(Serde.Serializer.class); | ||
|
||
ProducerRecordCreator recordCreator = new ProducerRecordCreator(keySerializer, valueSerializer); | ||
Map<String, Object> invalidHeaders = Map.of("headerKey", Map.of("invalid", "value")); | ||
|
||
assertThrows(ValidationException.class, () -> | ||
recordCreator.create("topic", 1, "key", "value", invalidHeaders)); | ||
} | ||
} |
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