File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
main/java/io/kafbat/ui/emitter
test/java/io/kafbat/ui/emitter Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,23 @@ public static Predicate<TopicMessageDTO> noop() {
5252
5353 public static Predicate <TopicMessageDTO > containsStringFilter (String string ) {
5454 return msg -> StringUtils .contains (msg .getKey (), string )
55- || StringUtils .contains (msg .getContent (), string );
55+ || StringUtils .contains (msg .getContent (), string ) || headersContains (msg , string );
56+ }
57+
58+ private static boolean headersContains (TopicMessageDTO msg , String searchString ) {
59+ final var headers = msg .getHeaders ();
60+
61+ if (headers == null ) {
62+ return false ;
63+ }
64+
65+ for (final var entry : headers .entrySet ()) {
66+ if (StringUtils .contains (entry .getKey (), searchString ) || StringUtils .contains (entry .getValue (), searchString )) {
67+ return true ;
68+ }
69+ }
70+
71+ return false ;
5672 }
5773
5874 public static Predicate <TopicMessageDTO > celScriptFilter (String script ) {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class StringContainsFilter {
2828 Predicate <TopicMessageDTO > filter = containsStringFilter ("abC" );
2929
3030 @ Test
31- void returnsTrueWhenStringContainedInKeyOrContentOrInBoth () {
31+ void returnsTrueWhenStringContainedInKeyOrContentOrHeadersOrInAllThree () {
3232 assertTrue (
3333 filter .test (msg ().key ("contains abCd" ).content ("some str" ))
3434 );
@@ -40,6 +40,14 @@ void returnsTrueWhenStringContainedInKeyOrContentOrInBoth() {
4040 assertTrue (
4141 filter .test (msg ().key ("contains abCd" ).content ("contains abCd" ))
4242 );
43+
44+ assertTrue (
45+ filter .test (msg ().key ("dfg" ).content ("does-not-contain" ).headers (Map .of ("abC" , "value" )))
46+ );
47+
48+ assertTrue (
49+ filter .test (msg ().key ("dfg" ).content ("does-not-contain" ).headers (Map .of ("x1" , "some abC" )))
50+ );
4351 }
4452
4553 @ Test
@@ -55,6 +63,11 @@ void returnsFalseOtherwise() {
5563 assertFalse (
5664 filter .test (msg ().key ("aBc" ).content ("AbC" ))
5765 );
66+
67+ assertFalse (
68+ filter .test (msg ().key ("aBc" ).content ("AbC" ).headers (Map .of ("abc" , "value" )))
69+ );
70+
5871 }
5972
6073 }
You can’t perform that action at this time.
0 commit comments