Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,78 @@ public final void testRandomSerialization() throws IOException {
}
}

public void testNumericValidationWithValidValues() throws IOException {
String content = XContentHelper.stripWhitespace("""
{
"rule_id": "numeric_rule",
"type": "pinned",
"criteria": [
{ "type": "lte", "metadata": "price", "values": ["100.50", "200"] }
],
"actions": {
"ids": ["id1"]
}
}""");
testToXContentRules(content);
}

public void testNumericValidationWithInvalidValues() throws IOException {
String content = XContentHelper.stripWhitespace("""
{
"rule_id": "numeric_rule",
"type": "pinned",
"criteria": [
{ "type": "lte", "metadata": "price", "values": ["abc"] }
],
"actions": {
"ids": ["id1"]
}
}""");
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON)
);
assertThat(e.getMessage(), containsString("Failed to build [query_rule]"));
}

public void testNumericValidationWithMixedValues() throws IOException {
String content = XContentHelper.stripWhitespace("""
{
"rule_id": "numeric_rule",
"type": "pinned",
"criteria": [
{ "type": "lte", "metadata": "price", "values": ["100", "abc", "200"] }
],
"actions": {
"ids": ["id1"]
}
}""");
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON)
);
assertThat(e.getMessage(), containsString("Failed to build [query_rule]"));
}

public void testNumericValidationWithEmptyValues() throws IOException {
String content = XContentHelper.stripWhitespace("""
{
"rule_id": "numeric_rule",
"type": "pinned",
"criteria": [
{ "type": "lte", "metadata": "price", "values": [] }
],
"actions": {
"ids": ["id1"]
}
}""");
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON)
);
assertThat(e.getMessage(), containsString("failed to parse field [criteria]"));
}

public void testToXContent() throws IOException {
String content = XContentHelper.stripWhitespace("""
{
Expand Down Expand Up @@ -85,7 +157,11 @@ public void testToXContentEmptyCriteria() throws IOException {
"criteria": [],
"actions": {}
}""");
expectThrows(IllegalArgumentException.class, () -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON));
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> QueryRule.fromXContentBytes(new BytesArray(content), XContentType.JSON)
);
assertThat(e.getMessage(), containsString("Failed to build [query_rule]"));
}

public void testToXContentValidPinnedRulesWithIds() throws IOException {
Expand Down