|
22 | 22 | import org.eclipse.ditto.base.model.entity.metadata.Metadata;
|
23 | 23 | import org.eclipse.ditto.base.model.exceptions.InvalidRqlExpressionException;
|
24 | 24 | import org.eclipse.ditto.base.model.headers.DittoHeaders;
|
| 25 | +import org.eclipse.ditto.json.JsonArray; |
| 26 | +import org.eclipse.ditto.json.JsonObject; |
25 | 27 | import org.eclipse.ditto.json.JsonPointer;
|
26 | 28 | import org.eclipse.ditto.json.JsonValue;
|
27 | 29 | import org.eclipse.ditto.placeholders.PlaceholderFactory;
|
@@ -70,6 +72,23 @@ public final class ThingPredicateVisitorTest {
|
70 | 72 | .setAttribute(JsonPointer.of("aDouble"), JsonValue.of(MATCHING_THING_DOUBLE))
|
71 | 73 | .setAttribute(JsonPointer.of("aBoolean"), JsonValue.of(MATCHING_THING_BOOLEAN))
|
72 | 74 | .setAttribute(JsonPointer.of("aString"), JsonValue.of(MATCHING_THING_STRING))
|
| 75 | + .setAttribute(JsonPointer.of("anArrayOfObjects"), JsonArray.newBuilder() |
| 76 | + .add(JsonObject.newBuilder() |
| 77 | + .set("anInteger", MATCHING_THING_INTEGER) |
| 78 | + .set("aBoolean", MATCHING_THING_BOOLEAN) |
| 79 | + .set("anArrayOfObjects", JsonArray.newBuilder() |
| 80 | + .add( |
| 81 | + JsonObject.newBuilder() |
| 82 | + .set("anInteger", MATCHING_THING_INTEGER) |
| 83 | + .set("aBoolean", MATCHING_THING_BOOLEAN) |
| 84 | + .build() |
| 85 | + ) |
| 86 | + .build() |
| 87 | + ) |
| 88 | + .build() |
| 89 | + ) |
| 90 | + .build() |
| 91 | + ) |
73 | 92 | .setFeature("foo", FeatureProperties.newBuilder()
|
74 | 93 | .set(JsonPointer.of("anInteger"), JsonValue.of(MATCHING_THING_INTEGER))
|
75 | 94 | .set(JsonPointer.of("aLong"), JsonValue.of(MATCHING_THING_LONG))
|
@@ -453,6 +472,67 @@ public void testFilterAttributeExists() {
|
453 | 472 | .isFalse();
|
454 | 473 | }
|
455 | 474 |
|
| 475 | + @Test |
| 476 | + public void testFilterAttributeNestedInArrayExists() { |
| 477 | + final Predicate<Thing> thingPredicate = createPredicate("exists(attributes/anArrayOfObjects/aBoolean)"); |
| 478 | + assertThat(thingPredicate.test(MATCHING_THING)) |
| 479 | + .as("Filtering 'exists(attributes/anArrayOfObjects/aBoolean)' should be true") |
| 480 | + .isTrue(); |
| 481 | + |
| 482 | + final Predicate<Thing> negativePredicate = createPredicate("exists(attributes/anArrayOfObjects/missing)"); |
| 483 | + assertThat(negativePredicate.test(MATCHING_THING)) |
| 484 | + .as("Filtering 'exists(attributes/anArrayOfObjects/missing)' should be false") |
| 485 | + .isFalse(); |
| 486 | + } |
| 487 | + |
| 488 | + @Test |
| 489 | + public void testFilterAttributeNestedInArrayNestedExists() { |
| 490 | + final Predicate<Thing> thingPredicate = createPredicate("exists(attributes/anArrayOfObjects/anArrayOfObjects/aBoolean)"); |
| 491 | + assertThat(thingPredicate.test(MATCHING_THING)) |
| 492 | + .as("Filtering 'exists(attributes/anArrayOfObjects/anArrayOfObjects/aBoolean)' should be true") |
| 493 | + .isTrue(); |
| 494 | + |
| 495 | + final Predicate<Thing> negativePredicate = createPredicate("exists(attributes/anArrayOfObjects/anArrayOfObjects/missing)"); |
| 496 | + assertThat(negativePredicate.test(MATCHING_THING)) |
| 497 | + .as("Filtering 'exists(attributes/anArrayOfObjects/anArrayOfObjects/missing)' should be false") |
| 498 | + .isFalse(); |
| 499 | + } |
| 500 | + |
| 501 | + @Test |
| 502 | + public void testFilterArrayAttributeWithNestedIntegerGe() { |
| 503 | + final String filter = "ge(attributes/anArrayOfObjects/anInteger," + (MATCHING_THING_INTEGER - 1) + ")"; |
| 504 | + final Predicate<Thing> thingPredicate = createPredicate(filter); |
| 505 | + assertThat(thingPredicate.test(MATCHING_THING)) |
| 506 | + .as("Filtering '" + filter + "' should be true") |
| 507 | + .isTrue(); |
| 508 | + } |
| 509 | + |
| 510 | + @Test |
| 511 | + public void testFilterArrayAttributeWithArrayNestedIntegerGe() { |
| 512 | + final String filter = |
| 513 | + "ge(attributes/anArrayOfObjects/anArrayOfObjects/anInteger," + (MATCHING_THING_INTEGER - 1) + ")"; |
| 514 | + final Predicate<Thing> thingPredicate = createPredicate(filter); |
| 515 | + assertThat(thingPredicate.test(MATCHING_THING)) |
| 516 | + .as("Filtering '" + filter + "' should be true") |
| 517 | + .isTrue(); |
| 518 | + } |
| 519 | + |
| 520 | + @Test |
| 521 | + public void testFilterArrayAttributeWithNestedBooleanEq() { |
| 522 | + final Predicate<Thing> thingPredicate = createPredicate("eq(attributes/anArrayOfObjects/aBoolean,true)"); |
| 523 | + assertThat(thingPredicate.test(MATCHING_THING)) |
| 524 | + .as("Filtering 'exists(attributes/anArrayOfObjects/aBoolean)' should be true") |
| 525 | + .isTrue(); |
| 526 | + } |
| 527 | + |
| 528 | + @Test |
| 529 | + public void testFilterArrayAttributeWithArrayNestedBooleanEq() { |
| 530 | + final Predicate<Thing> thingPredicate = createPredicate("eq(attributes/anArrayOfObjects/anArrayOfObjects/aBoolean,true)"); |
| 531 | + assertThat(thingPredicate.test(MATCHING_THING)) |
| 532 | + .as("Filtering 'exists(attributes/anArrayOfObjects/anArrayOfObjects/aBoolean)' should be true") |
| 533 | + .isTrue(); |
| 534 | + } |
| 535 | + |
456 | 536 | @Test
|
457 | 537 | public void testFilterFeatureExists() {
|
458 | 538 | final Predicate<Thing> thingPredicate = createPredicate("exists(features/foo)");
|
|
0 commit comments