2222import org .elasticsearch .xpack .application .EnterpriseSearchModuleTestUtils ;
2323import org .elasticsearch .xpack .searchbusinessrules .SpecifiedDocument ;
2424import org .junit .Before ;
25+ import org .slf4j .Logger ;
26+ import org .slf4j .LoggerFactory ;
2527
2628import java .io .IOException ;
2729import java .util .Collections ;
3941
4042public class QueryRuleTests extends ESTestCase {
4143 private NamedWriteableRegistry namedWriteableRegistry ;
44+ private static final Logger logger = LoggerFactory .getLogger (QueryRuleTests .class );
4245
4346 @ Before
4447 public void registerNamedObjects () {
@@ -83,7 +86,13 @@ public void testNumericValidationWithInvalidValues() throws IOException {
8386 "ids": ["id1"]
8487 }
8588 }""" );
86- expectThrows (IllegalArgumentException .class , () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON ));
89+ IllegalArgumentException e = expectThrows (
90+ IllegalArgumentException .class ,
91+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
92+ );
93+ logger .info ("Actual error message for invalid values: " + e .getMessage ());
94+ assertTrue ("Error message [" + e .getMessage () + "] should contain 'Failed to build [query_rule]'" ,
95+ e .getMessage ().contains ("Failed to build [query_rule]" ));
8796 }
8897
8998 public void testNumericValidationWithMixedValues () throws IOException {
@@ -98,7 +107,13 @@ public void testNumericValidationWithMixedValues() throws IOException {
98107 "ids": ["id1"]
99108 }
100109 }""" );
101- expectThrows (IllegalArgumentException .class , () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON ));
110+ IllegalArgumentException e = expectThrows (
111+ IllegalArgumentException .class ,
112+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
113+ );
114+ logger .info ("Actual error message for mixed values: " + e .getMessage ());
115+ assertTrue ("Error message [" + e .getMessage () + "] should contain 'Failed to build [query_rule]'" ,
116+ e .getMessage ().contains ("Failed to build [query_rule]" ));
102117 }
103118
104119 public void testNumericValidationWithEmptyValues () throws IOException {
@@ -113,7 +128,12 @@ public void testNumericValidationWithEmptyValues() throws IOException {
113128 "ids": ["id1"]
114129 }
115130 }""" );
116- expectThrows (IllegalArgumentException .class , () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON ));
131+ IllegalArgumentException e = expectThrows (
132+ IllegalArgumentException .class ,
133+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
134+ );
135+ logger .info ("Actual error message: " + e .getMessage ());
136+ assertTrue (e .getMessage ().contains ("failed to parse field [criteria]" ));
117137 }
118138
119139 public void testToXContent () throws IOException {
@@ -140,7 +160,13 @@ public void testToXContentEmptyCriteria() throws IOException {
140160 "criteria": [],
141161 "actions": {}
142162 }""" );
143- expectThrows (IllegalArgumentException .class , () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON ));
163+ IllegalArgumentException e = expectThrows (
164+ IllegalArgumentException .class ,
165+ () -> QueryRule .fromXContentBytes (new BytesArray (content ), XContentType .JSON )
166+ );
167+ logger .info ("Actual error message for empty criteria: " + e .getMessage ());
168+ assertTrue ("Error message [" + e .getMessage () + "] should contain 'Failed to build [query_rule]'" ,
169+ e .getMessage ().contains ("Failed to build [query_rule]" ));
144170 }
145171
146172 public void testToXContentValidPinnedRulesWithIds () throws IOException {
0 commit comments