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() {
52
52
53
53
public static Predicate <TopicMessageDTO > containsStringFilter (String string ) {
54
54
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 ;
56
72
}
57
73
58
74
public static Predicate <TopicMessageDTO > celScriptFilter (String script ) {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class StringContainsFilter {
28
28
Predicate <TopicMessageDTO > filter = containsStringFilter ("abC" );
29
29
30
30
@ Test
31
- void returnsTrueWhenStringContainedInKeyOrContentOrInBoth () {
31
+ void returnsTrueWhenStringContainedInKeyOrContentOrHeadersOrInAllThree () {
32
32
assertTrue (
33
33
filter .test (msg ().key ("contains abCd" ).content ("some str" ))
34
34
);
@@ -40,6 +40,14 @@ void returnsTrueWhenStringContainedInKeyOrContentOrInBoth() {
40
40
assertTrue (
41
41
filter .test (msg ().key ("contains abCd" ).content ("contains abCd" ))
42
42
);
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
+ );
43
51
}
44
52
45
53
@ Test
@@ -55,6 +63,11 @@ void returnsFalseOtherwise() {
55
63
assertFalse (
56
64
filter .test (msg ().key ("aBc" ).content ("AbC" ))
57
65
);
66
+
67
+ assertFalse (
68
+ filter .test (msg ().key ("aBc" ).content ("AbC" ).headers (Map .of ("abc" , "value" )))
69
+ );
70
+
58
71
}
59
72
60
73
}
You can’t perform that action at this time.
0 commit comments