@@ -53,6 +53,78 @@ public final void testRandomSerialization() throws IOException {
5353 }
5454 }
5555
56+ public void testNumericValidationWithValidValues () throws IOException {
57+ String content = XContentHelper .stripWhitespace ("""
58+ {
59+ "rule_id": "numeric_rule",
60+ "type": "pinned",
61+ "criteria": [
62+ { "type": "lte", "metadata": "price", "values": ["100.50", "200"] }
63+ ],
64+ "actions": {
65+ "ids": ["id1"]
66+ }
67+ }""" );
68+ testToXContentRules (content );
69+ }
70+
71+ public void testNumericValidationWithInvalidValues () throws IOException {
72+ String content = XContentHelper .stripWhitespace ("""
73+ {
74+ "rule_id": "numeric_rule",
75+ "type": "pinned",
76+ "criteria": [
77+ { "type": "lte", "metadata": "price", "values": ["abc"] }
78+ ],
79+ "actions": {
80+ "ids": ["id1"]
81+ }
82+ }""" );
83+ IllegalArgumentException e = expectThrows (
84+ IllegalArgumentException .class ,
85+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
86+ );
87+ assertThat (e .getMessage (), containsString ("Failed to build [query_rule]" ));
88+ }
89+
90+ public void testNumericValidationWithMixedValues () throws IOException {
91+ String content = XContentHelper .stripWhitespace ("""
92+ {
93+ "rule_id": "numeric_rule",
94+ "type": "pinned",
95+ "criteria": [
96+ { "type": "lte", "metadata": "price", "values": ["100", "abc", "200"] }
97+ ],
98+ "actions": {
99+ "ids": ["id1"]
100+ }
101+ }""" );
102+ IllegalArgumentException e = expectThrows (
103+ IllegalArgumentException .class ,
104+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
105+ );
106+ assertThat (e .getMessage (), containsString ("Failed to build [query_rule]" ));
107+ }
108+
109+ public void testNumericValidationWithEmptyValues () throws IOException {
110+ String content = XContentHelper .stripWhitespace ("""
111+ {
112+ "rule_id": "numeric_rule",
113+ "type": "pinned",
114+ "criteria": [
115+ { "type": "lte", "metadata": "price", "values": [] }
116+ ],
117+ "actions": {
118+ "ids": ["id1"]
119+ }
120+ }""" );
121+ IllegalArgumentException e = expectThrows (
122+ IllegalArgumentException .class ,
123+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
124+ );
125+ assertThat (e .getMessage (), containsString ("failed to parse field [criteria]" ));
126+ }
127+
56128 public void testToXContent () throws IOException {
57129 String content = XContentHelper .stripWhitespace ("""
58130 {
@@ -85,7 +157,11 @@ public void testToXContentEmptyCriteria() throws IOException {
85157 "criteria": [],
86158 "actions": {}
87159 }""" );
88- expectThrows (IllegalArgumentException .class , () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON ));
160+ IllegalArgumentException e = expectThrows (
161+ IllegalArgumentException .class ,
162+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
163+ );
164+ assertThat (e .getMessage (), containsString ("Failed to build [query_rule]" ));
89165 }
90166
91167 public void testToXContentValidPinnedRulesWithIds () throws IOException {
0 commit comments