Skip to content

Commit 085cec0

Browse files
author
elasticsearchmachine
committed
[CI] Auto commit changes from spotless
1 parent 5e1a815 commit 085cec0

File tree

3 files changed

+56
-69
lines changed

3 files changed

+56
-69
lines changed

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/rules/QueryRule.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,12 @@ private void validate() {
164164
Double.parseDouble(value.toString());
165165
} catch (NumberFormatException e) {
166166
throw new IllegalArgumentException(
167-
"Numeric comparison rule type " + criteriaType + " requires numeric values, but got " + value +
168-
" for criterion " + criterion
167+
"Numeric comparison rule type "
168+
+ criteriaType
169+
+ " requires numeric values, but got "
170+
+ value
171+
+ " for criterion "
172+
+ criterion
169173
);
170174
}
171175
}

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/EnterpriseSearchModuleTestUtils.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,23 @@
2121
import org.elasticsearch.xpack.core.action.util.PageParams;
2222

2323
import java.util.ArrayList;
24-
import java.util.Arrays;
2524
import java.util.Collections;
2625
import java.util.List;
2726
import java.util.Locale;
2827
import java.util.Map;
2928

3029
import static org.elasticsearch.test.ESTestCase.generateRandomStringArray;
30+
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength;
3131
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLengthBetween;
3232
import static org.elasticsearch.test.ESTestCase.randomBoolean;
33+
import static org.elasticsearch.test.ESTestCase.randomDoubleBetween;
3334
import static org.elasticsearch.test.ESTestCase.randomFrom;
3435
import static org.elasticsearch.test.ESTestCase.randomIdentifier;
3536
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
36-
import static org.elasticsearch.test.ESTestCase.randomList;
3737
import static org.elasticsearch.test.ESTestCase.randomLongBetween;
3838
import static org.elasticsearch.test.ESTestCase.randomMap;
3939
import static org.elasticsearch.xpack.application.rules.QueryRule.MAX_PRIORITY;
4040
import static org.elasticsearch.xpack.application.rules.QueryRule.MIN_PRIORITY;
41-
import static org.elasticsearch.xpack.application.rules.QueryRuleCriteriaType.ALWAYS;
42-
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength;
43-
import static org.elasticsearch.test.ESTestCase.randomDoubleBetween;
4441

4542
public final class EnterpriseSearchModuleTestUtils {
4643

@@ -154,9 +151,7 @@ private static QueryRule createNonNumericQueryRule() {
154151
);
155152

156153
String metadata = criteriaType == QueryRuleCriteriaType.ALWAYS ? null : randomAlphaOfLength(10);
157-
List<Object> values = criteriaType == QueryRuleCriteriaType.ALWAYS ?
158-
null :
159-
List.of(randomAlphaOfLength(5));
154+
List<Object> values = criteriaType == QueryRuleCriteriaType.ALWAYS ? null : List.of(randomAlphaOfLength(5));
160155

161156
criteria.add(new QueryRuleCriteria(criteriaType, metadata, values));
162157
}

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/rules/QueryRuleTests.java

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import org.elasticsearch.search.SearchModule;
1616
import org.elasticsearch.test.ESTestCase;
1717
import org.elasticsearch.xcontent.ToXContent;
18+
import org.elasticsearch.xcontent.XContentBuilder;
19+
import org.elasticsearch.xcontent.XContentFactory;
1820
import org.elasticsearch.xcontent.XContentParser;
1921
import org.elasticsearch.xcontent.XContentType;
2022
import org.elasticsearch.xpack.application.EnterpriseSearchModuleTestUtils;
2123
import org.elasticsearch.xpack.searchbusinessrules.SpecifiedDocument;
2224
import org.junit.Before;
23-
import org.elasticsearch.xcontent.XContentBuilder;
24-
import org.elasticsearch.xcontent.XContentFactory;
2525

2626
import java.io.IOException;
2727
import java.util.Collections;
@@ -32,9 +32,9 @@
3232
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
3333
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
3434
import static org.elasticsearch.xpack.application.rules.QueryRuleCriteriaType.EXACT;
35+
import static org.elasticsearch.xpack.application.rules.QueryRuleCriteriaType.LTE;
3536
import static org.elasticsearch.xpack.application.rules.QueryRuleCriteriaType.PREFIX;
3637
import static org.elasticsearch.xpack.application.rules.QueryRuleCriteriaType.SUFFIX;
37-
import static org.elasticsearch.xpack.application.rules.QueryRuleCriteriaType.LTE;
3838
import static org.hamcrest.CoreMatchers.equalTo;
3939

4040
public class QueryRuleTests extends ESTestCase {
@@ -58,16 +58,16 @@ public final void testRandomSerialization() throws IOException {
5858

5959
public void testNumericValidationWithValidValues() throws IOException {
6060
String content = XContentHelper.stripWhitespace("""
61-
{
62-
"rule_id": "numeric_rule",
63-
"type": "pinned",
64-
"criteria": [
65-
{ "type": "lte", "metadata": "price", "values": ["100.50", "200"] }
66-
],
67-
"actions": {
68-
"ids": ["id1"]
69-
}
70-
}""");
61+
{
62+
"rule_id": "numeric_rule",
63+
"type": "pinned",
64+
"criteria": [
65+
{ "type": "lte", "metadata": "price", "values": ["100.50", "200"] }
66+
],
67+
"actions": {
68+
"ids": ["id1"]
69+
}
70+
}""");
7171
QueryRule queryRule = QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON);
7272
boolean humanReadable = true;
7373
BytesReference originalBytes = toShuffledXContent(queryRule, XContentType.JSON, ToXContent.EMPTY_PARAMS, humanReadable);
@@ -80,46 +80,46 @@ public void testNumericValidationWithValidValues() throws IOException {
8080

8181
public void testNumericValidationWithInvalidValues() throws IOException {
8282
String content = XContentHelper.stripWhitespace("""
83-
{
84-
"rule_id": "numeric_rule",
85-
"type": "pinned",
86-
"criteria": [
87-
{ "type": "lte", "metadata": "price", "values": ["abc"] }
88-
],
89-
"actions": {
90-
"ids": ["id1"]
91-
}
92-
}""");
83+
{
84+
"rule_id": "numeric_rule",
85+
"type": "pinned",
86+
"criteria": [
87+
{ "type": "lte", "metadata": "price", "values": ["abc"] }
88+
],
89+
"actions": {
90+
"ids": ["id1"]
91+
}
92+
}""");
9393
expectThrows(IllegalArgumentException.class, () -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON));
9494
}
9595

9696
public void testNumericValidationWithMixedValues() throws IOException {
9797
String content = XContentHelper.stripWhitespace("""
98-
{
99-
"rule_id": "numeric_rule",
100-
"type": "pinned",
101-
"criteria": [
102-
{ "type": "lte", "metadata": "price", "values": ["100", "abc", "200"] }
103-
],
104-
"actions": {
105-
"ids": ["id1"]
106-
}
107-
}""");
98+
{
99+
"rule_id": "numeric_rule",
100+
"type": "pinned",
101+
"criteria": [
102+
{ "type": "lte", "metadata": "price", "values": ["100", "abc", "200"] }
103+
],
104+
"actions": {
105+
"ids": ["id1"]
106+
}
107+
}""");
108108
expectThrows(IllegalArgumentException.class, () -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON));
109109
}
110110

111111
public void testNumericValidationWithEmptyValues() throws IOException {
112112
String content = XContentHelper.stripWhitespace("""
113-
{
114-
"rule_id": "numeric_rule",
115-
"type": "pinned",
116-
"criteria": [
117-
{ "type": "lte", "metadata": "price", "values": [] }
118-
],
119-
"actions": {
120-
"ids": ["id1"]
121-
}
122-
}""");
113+
{
114+
"rule_id": "numeric_rule",
115+
"type": "pinned",
116+
"criteria": [
117+
{ "type": "lte", "metadata": "price", "values": [] }
118+
],
119+
"actions": {
120+
"ids": ["id1"]
121+
}
122+
}""");
123123
expectThrows(IllegalArgumentException.class, () -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON));
124124
}
125125

@@ -420,13 +420,7 @@ public void testValidateNumericComparisonRule() {
420420
QueryRuleCriteria invalidCriteria = new QueryRuleCriteria(LTE, "price", List.of("not_a_number"));
421421
IllegalArgumentException e = expectThrows(
422422
IllegalArgumentException.class,
423-
() -> new QueryRule(
424-
"test_rule",
425-
QueryRule.QueryRuleType.PINNED,
426-
List.of(invalidCriteria),
427-
Map.of("ids", List.of("1")),
428-
null
429-
)
423+
() -> new QueryRule("test_rule", QueryRule.QueryRuleType.PINNED, List.of(invalidCriteria), Map.of("ids", List.of("1")), null)
430424
);
431425

432426
String expectedMessage = String.format(
@@ -475,20 +469,14 @@ public void testParseNumericComparisonRule() throws IOException {
475469

476470
public void testIsRuleMatchWithNumericComparison() {
477471
QueryRuleCriteria criteria = new QueryRuleCriteria(LTE, "price", List.of("100"));
478-
QueryRule rule = new QueryRule(
479-
"test_rule",
480-
QueryRule.QueryRuleType.PINNED,
481-
List.of(criteria),
482-
Map.of("ids", List.of("1")),
483-
null
484-
);
472+
QueryRule rule = new QueryRule("test_rule", QueryRule.QueryRuleType.PINNED, List.of(criteria), Map.of("ids", List.of("1")), null);
485473

486474
// Test matching value
487475
assertTrue(rule.isRuleMatch(Map.of("price", "50")));
488-
476+
489477
// Test non-matching value
490478
assertFalse(rule.isRuleMatch(Map.of("price", "150")));
491-
479+
492480
// Test with non-numeric value
493481
assertFalse(rule.isRuleMatch(Map.of("price", "not_a_number")));
494482
}

0 commit comments

Comments
 (0)