File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
main/java/io/kafbat/ui/emitter
test/java/io/kafbat/ui/emitter Expand file tree Collapse file tree 2 files changed +32
-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 1717import java .util .UUID ;
1818import java .util .function .Predicate ;
1919import org .apache .commons .lang3 .RandomStringUtils ;
20+ import org .junit .jupiter .api .DisplayName ;
2021import org .junit .jupiter .api .Nested ;
2122import org .junit .jupiter .api .Test ;
2223
@@ -28,7 +29,7 @@ class StringContainsFilter {
2829 Predicate <TopicMessageDTO > filter = containsStringFilter ("abC" );
2930
3031 @ Test
31- void returnsTrueWhenStringContainedInKeyOrContentOrInBoth () {
32+ void returnsTrueWhenStringContainedInKeyOrContentOrHeadersOrInAllThree () {
3233 assertTrue (
3334 filter .test (msg ().key ("contains abCd" ).content ("some str" ))
3435 );
@@ -40,6 +41,14 @@ void returnsTrueWhenStringContainedInKeyOrContentOrInBoth() {
4041 assertTrue (
4142 filter .test (msg ().key ("contains abCd" ).content ("contains abCd" ))
4243 );
44+
45+ assertTrue (
46+ filter .test (msg ().key ("dfg" ).content ("does-not-contain" ).headers (Map .of ("abC" , "value" )))
47+ );
48+
49+ assertTrue (
50+ filter .test (msg ().key ("dfg" ).content ("does-not-contain" ).headers (Map .of ("x1" , "some abC" )))
51+ );
4352 }
4453
4554 @ Test
@@ -55,6 +64,11 @@ void returnsFalseOtherwise() {
5564 assertFalse (
5665 filter .test (msg ().key ("aBc" ).content ("AbC" ))
5766 );
67+
68+ assertFalse (
69+ filter .test (msg ().key ("aBc" ).content ("AbC" ).headers (Map .of ("abc" , "value" )))
70+ );
71+
5872 }
5973
6074 }
You can’t perform that action at this time.
0 commit comments