|
31 | 31 |
|
32 | 32 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
33 | 33 | import com.google.android.gms.tasks.Task;
|
| 34 | +import com.google.common.collect.Lists; |
| 35 | +import com.google.common.collect.Maps; |
34 | 36 | import com.google.firebase.firestore.Query.Direction;
|
35 | 37 | import com.google.firebase.firestore.testutil.EventAccumulator;
|
36 | 38 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
|
39 | 41 | import java.util.Map;
|
40 | 42 | import java.util.concurrent.Semaphore;
|
41 | 43 | import org.junit.After;
|
| 44 | +import org.junit.Ignore; |
42 | 45 | import org.junit.Test;
|
43 | 46 | import org.junit.runner.RunWith;
|
44 | 47 |
|
@@ -483,6 +486,79 @@ public void testQueriesFireFromCacheWhenOffline() {
|
483 | 486 | listener.remove();
|
484 | 487 | }
|
485 | 488 |
|
| 489 | + // TODO(ne-queries): Re-enable once emulator support is added to CI. |
| 490 | + @Ignore |
| 491 | + @Test |
| 492 | + public void testQueriesCanUseNotEqualFilters() { |
| 493 | + Map<String, Object> docA = map("zip", 98101L); |
| 494 | + Map<String, Object> docB = map("zip", 91102L); |
| 495 | + Map<String, Object> docC = map("zip", "98101"); |
| 496 | + Map<String, Object> docD = map("zip", asList(98101L)); |
| 497 | + Map<String, Object> docE = map("zip", asList("98101", map("zip", 98101L))); |
| 498 | + Map<String, Object> docF = map("zip", map("code", 500L)); |
| 499 | + Map<String, Object> docG = map("zip", asList(98101L, 98102L)); |
| 500 | + Map<String, Object> docH = map("code", 500L); |
| 501 | + Map<String, Object> docI = map("zip", null); |
| 502 | + Map<String, Object> docJ = map("zip", Double.NaN); |
| 503 | + |
| 504 | + Map<String, Map<String, Object>> allDocs = |
| 505 | + map( |
| 506 | + "a", docA, "b", docB, "c", docC, "d", docD, "e", docE, "f", docF, "g", docG, "h", docH, |
| 507 | + "i", docI, "j", docJ); |
| 508 | + CollectionReference collection = testCollectionWithDocs(allDocs); |
| 509 | + |
| 510 | + // Search for zips not matching 98101. |
| 511 | + Map<String, Map<String, Object>> expectedDocsMap = Maps.newHashMap(allDocs); |
| 512 | + expectedDocsMap.remove("a"); |
| 513 | + expectedDocsMap.remove("h"); |
| 514 | + expectedDocsMap.remove("i"); |
| 515 | + |
| 516 | + QuerySnapshot snapshot = waitFor(collection.whereNotEqualTo("zip", 98101L).get()); |
| 517 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 518 | + |
| 519 | + // With objects. |
| 520 | + expectedDocsMap = Maps.newHashMap(allDocs); |
| 521 | + expectedDocsMap.remove("f"); |
| 522 | + expectedDocsMap.remove("h"); |
| 523 | + expectedDocsMap.remove("i"); |
| 524 | + snapshot = waitFor(collection.whereNotEqualTo("zip", map("code", 500)).get()); |
| 525 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 526 | + |
| 527 | + // With Null. |
| 528 | + expectedDocsMap = Maps.newHashMap(allDocs); |
| 529 | + expectedDocsMap.remove("h"); |
| 530 | + expectedDocsMap.remove("i"); |
| 531 | + snapshot = waitFor(collection.whereNotEqualTo("zip", null).get()); |
| 532 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 533 | + |
| 534 | + // With NaN. |
| 535 | + expectedDocsMap = Maps.newHashMap(allDocs); |
| 536 | + expectedDocsMap.remove("h"); |
| 537 | + expectedDocsMap.remove("i"); |
| 538 | + expectedDocsMap.remove("j"); |
| 539 | + snapshot = waitFor(collection.whereNotEqualTo("zip", Double.NaN).get()); |
| 540 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 541 | + } |
| 542 | + |
| 543 | + // TODO(ne-queries): Re-enable once emulator support is added to CI. |
| 544 | + @Ignore |
| 545 | + @Test |
| 546 | + public void testQueriesCanUseNotEqualFiltersWithDocIds() { |
| 547 | + Map<String, String> docA = map("key", "aa"); |
| 548 | + Map<String, String> docB = map("key", "ab"); |
| 549 | + Map<String, String> docC = map("key", "ba"); |
| 550 | + Map<String, String> docD = map("key", "bb"); |
| 551 | + Map<String, Map<String, Object>> testDocs = |
| 552 | + map( |
| 553 | + "aa", docA, |
| 554 | + "ab", docB, |
| 555 | + "ba", docC, |
| 556 | + "bb", docD); |
| 557 | + CollectionReference collection = testCollectionWithDocs(testDocs); |
| 558 | + QuerySnapshot docs = waitFor(collection.whereNotEqualTo(FieldPath.documentId(), "aa").get()); |
| 559 | + assertEquals(asList(docB, docC, docD), querySnapshotToValues(docs)); |
| 560 | + } |
| 561 | + |
486 | 562 | @Test
|
487 | 563 | public void testQueriesCanUseArrayContainsFilters() {
|
488 | 564 | Map<String, Object> docA = map("array", asList(42L));
|
@@ -541,6 +617,87 @@ public void testQueriesCanUseInFiltersWithDocIds() {
|
541 | 617 | assertEquals(asList(docA, docB), querySnapshotToValues(docs));
|
542 | 618 | }
|
543 | 619 |
|
| 620 | + // TODO(ne-queries): Re-enable once emulator support is added to CI. |
| 621 | + @Ignore |
| 622 | + @Test |
| 623 | + public void testQueriesCanUseNotInFilters() { |
| 624 | + Map<String, Object> docA = map("zip", 98101L); |
| 625 | + Map<String, Object> docB = map("zip", 91102L); |
| 626 | + Map<String, Object> docC = map("zip", 98103L); |
| 627 | + Map<String, Object> docD = map("zip", asList(98101L)); |
| 628 | + Map<String, Object> docE = map("zip", asList("98101", map("zip", 98101L))); |
| 629 | + Map<String, Object> docF = map("zip", map("code", 500L)); |
| 630 | + Map<String, Object> docG = map("zip", asList(98101L, 98102L)); |
| 631 | + Map<String, Object> docH = map("code", 500L); |
| 632 | + Map<String, Object> docI = map("zip", null); |
| 633 | + Map<String, Object> docJ = map("zip", Double.NaN); |
| 634 | + |
| 635 | + Map<String, Map<String, Object>> allDocs = |
| 636 | + map( |
| 637 | + "a", docA, "b", docB, "c", docC, "d", docD, "e", docE, "f", docF, "g", docG, "h", docH, |
| 638 | + "i", docI, "j", docJ); |
| 639 | + CollectionReference collection = testCollectionWithDocs(allDocs); |
| 640 | + |
| 641 | + // Search for zips not matching 98101, 98103, or [98101, 98102]. |
| 642 | + Map<String, Map<String, Object>> expectedDocsMap = Maps.newHashMap(allDocs); |
| 643 | + expectedDocsMap.remove("a"); |
| 644 | + expectedDocsMap.remove("c"); |
| 645 | + expectedDocsMap.remove("g"); |
| 646 | + expectedDocsMap.remove("h"); |
| 647 | + |
| 648 | + QuerySnapshot snapshot = |
| 649 | + waitFor(collection.whereNotIn("zip", asList(98101L, 98103L, asList(98101L, 98102L))).get()); |
| 650 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 651 | + |
| 652 | + // With objects. |
| 653 | + expectedDocsMap = Maps.newHashMap(allDocs); |
| 654 | + expectedDocsMap.remove("f"); |
| 655 | + expectedDocsMap.remove("h"); |
| 656 | + snapshot = waitFor(collection.whereNotIn("zip", asList(map("code", 500L))).get()); |
| 657 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 658 | + |
| 659 | + // With Null. |
| 660 | + List<Object> nullArray = new ArrayList<>(); |
| 661 | + nullArray.add(null); |
| 662 | + snapshot = waitFor(collection.whereNotIn("key", nullArray).get()); |
| 663 | + assertEquals(new ArrayList<>(), querySnapshotToValues(snapshot)); |
| 664 | + |
| 665 | + // With NaN. |
| 666 | + expectedDocsMap = Maps.newHashMap(allDocs); |
| 667 | + expectedDocsMap.remove("h"); |
| 668 | + expectedDocsMap.remove("j"); |
| 669 | + snapshot = waitFor(collection.whereNotIn("zip", asList(Double.NaN)).get()); |
| 670 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 671 | + |
| 672 | + // With NaN and a number. |
| 673 | + expectedDocsMap = Maps.newHashMap(allDocs); |
| 674 | + expectedDocsMap.remove("a"); |
| 675 | + expectedDocsMap.remove("h"); |
| 676 | + expectedDocsMap.remove("j"); |
| 677 | + snapshot = waitFor(collection.whereNotIn("zip", asList(Float.NaN, 98101L)).get()); |
| 678 | + assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); |
| 679 | + } |
| 680 | + |
| 681 | + // TODO(ne-queries): Re-enable once emulator support is added to CI. |
| 682 | + @Ignore |
| 683 | + @Test |
| 684 | + public void testQueriesCanUseNotInFiltersWithDocIds() { |
| 685 | + Map<String, String> docA = map("key", "aa"); |
| 686 | + Map<String, String> docB = map("key", "ab"); |
| 687 | + Map<String, String> docC = map("key", "ba"); |
| 688 | + Map<String, String> docD = map("key", "bb"); |
| 689 | + Map<String, Map<String, Object>> testDocs = |
| 690 | + map( |
| 691 | + "aa", docA, |
| 692 | + "ab", docB, |
| 693 | + "ba", docC, |
| 694 | + "bb", docD); |
| 695 | + CollectionReference collection = testCollectionWithDocs(testDocs); |
| 696 | + QuerySnapshot docs = |
| 697 | + waitFor(collection.whereNotIn(FieldPath.documentId(), asList("aa", "ab")).get()); |
| 698 | + assertEquals(asList(docC, docD), querySnapshotToValues(docs)); |
| 699 | + } |
| 700 | + |
544 | 701 | @Test
|
545 | 702 | public void testQueriesCanUseArrayContainsAnyFilters() {
|
546 | 703 | Map<String, Object> docA = map("array", asList(42L));
|
|
0 commit comments