|
1 | 1 | package com.redis.om.spring.annotations.document;
|
2 | 2 |
|
| 3 | +import com.github.f4b6a3.ulid.Ulid; |
3 | 4 | import com.google.common.collect.Lists;
|
4 | 5 | import com.redis.om.spring.AbstractBaseDocumentTest;
|
5 | 6 | import com.redis.om.spring.annotations.document.fixtures.*;
|
6 | 7 | import com.redis.om.spring.repository.query.Sort;
|
7 | 8 | import com.redis.om.spring.search.stream.EntityStream;
|
| 9 | +import com.redis.om.spring.search.stream.SearchStream; |
8 | 10 | import org.junit.jupiter.api.BeforeEach;
|
9 | 11 | import org.junit.jupiter.api.Test;
|
10 | 12 | import org.springframework.beans.factory.annotation.Autowired;
|
|
17 | 19 | import java.time.LocalDateTime;
|
18 | 20 | import java.util.List;
|
19 | 21 | import java.util.Set;
|
| 22 | +import java.util.UUID; |
20 | 23 | import java.util.stream.Collectors;
|
21 | 24 |
|
22 | 25 | import static org.assertj.core.api.Assertions.assertThat;
|
|
33 | 36 | @Autowired
|
34 | 37 | ComplexRepository complexRepository;
|
35 | 38 |
|
| 39 | + @Autowired |
| 40 | + WithNestedListOfUUIDsRepository withNestedListOfUUIDsRepository; |
| 41 | + |
| 42 | + @Autowired |
| 43 | + WithNestedListOfUlidsRepository withNestedListOfUlidsRepository; |
| 44 | + |
36 | 45 | @Autowired
|
37 | 46 | EntityStream es;
|
38 | 47 |
|
| 48 | + UUID uuid1 = UUID.fromString("297c358e-08df-4e9e-8e0e-c5fd6e2b5b2d"); |
| 49 | + UUID uuid2 = UUID.fromString("72a93375-30ae-4075-86cf-b07c62800713"); |
| 50 | + UUID uuid3 = UUID.fromString("d6b65b6c-3b93-44b7-8f30-8695028ba36f"); |
| 51 | + UUID uuid4 = UUID.fromString("2b3b6517-5a4c-48da-a2a7-7a9ef2162c6d"); |
| 52 | + UUID uuid5 = UUID.fromString("3b4c23cc-f9b6-4df1-b368-5ec82e32b8f9"); |
| 53 | + UUID uuid6 = UUID.fromString("01be53c2-29e6-468f-9fe8-ad082d738c65"); |
| 54 | + |
| 55 | + Ulid ulid1 = Ulid.from(uuid1); |
| 56 | + Ulid ulid2 = Ulid.from(uuid2); |
| 57 | + Ulid ulid3 = Ulid.from(uuid3); |
| 58 | + Ulid ulid4 = Ulid.from(uuid4); |
| 59 | + Ulid ulid5 = Ulid.from(uuid5); |
| 60 | + Ulid ulid6 = Ulid.from(uuid6); |
| 61 | + |
39 | 62 | @BeforeEach
|
40 | 63 | void setup() {
|
41 | 64 | repository.deleteAll();
|
@@ -108,6 +131,19 @@ void setup() {
|
108 | 131 | Complex complex3 = Complex.of("complex3", List.of(HasAList.of(List.of("Pandiculation", "Taradiddle", "Ratoon")), HasAList.of(List.of("Yarborough", "Wabbit", "Erinaceous"))));
|
109 | 132 |
|
110 | 133 | complexRepository.saveAll(List.of(complex1, complex2, complex3));
|
| 134 | + |
| 135 | + // complex deep nested with uuids |
| 136 | + WithNestedListOfUUIDs withNestedListOfUUIDs1 = WithNestedListOfUUIDs.of("withNestedListOfUUIDs1", List.of(uuid1, uuid2, uuid3)); |
| 137 | + WithNestedListOfUUIDs withNestedListOfUUIDs2 = WithNestedListOfUUIDs.of("withNestedListOfUUIDs2", List.of(uuid4, uuid5, uuid6)); |
| 138 | + |
| 139 | + withNestedListOfUUIDsRepository.saveAll(List.of(withNestedListOfUUIDs1, withNestedListOfUUIDs2)); |
| 140 | + |
| 141 | + // complex deep nested with ulids |
| 142 | + WithNestedListOfUlids withNestedListOfUlids1 = WithNestedListOfUlids.of("withNestedListOfUlids1", List.of(ulid1, ulid2, ulid3)); |
| 143 | + WithNestedListOfUlids withNestedListOfUlids2 = WithNestedListOfUlids.of("withNestedListOfUlids2", List.of(ulid4, ulid5, ulid6)); |
| 144 | + |
| 145 | + withNestedListOfUlidsRepository.saveAll(List.of(withNestedListOfUlids1, withNestedListOfUlids2)); |
| 146 | + |
111 | 147 | }
|
112 | 148 |
|
113 | 149 | @Test
|
@@ -362,4 +398,111 @@ void testListInsideAListTagSearch() {
|
362 | 398 | () -> assertThat(withTaradiddle).extracting("id").containsExactlyInAnyOrder("complex2", "complex3") //
|
363 | 399 | );
|
364 | 400 | }
|
| 401 | + |
| 402 | + // UUID Tests |
| 403 | + @Test void testFindByNestedListOfUUIDsValuesIn() { |
| 404 | + SearchStream<WithNestedListOfUUIDs> stream1 = es.of(WithNestedListOfUUIDs.class); |
| 405 | + |
| 406 | + List<WithNestedListOfUUIDs> results1 = stream1 // |
| 407 | + .filter(WithNestedListOfUUIDs$.UUIDS.in(uuid1)).collect(Collectors.toList()); |
| 408 | + |
| 409 | + List<String> ids1 = results1.stream().map(WithNestedListOfUUIDs::getId).collect(Collectors.toList()); |
| 410 | + assertThat(ids1).contains("withNestedListOfUUIDs1"); |
| 411 | + |
| 412 | + SearchStream<WithNestedListOfUUIDs> stream2 = es.of(WithNestedListOfUUIDs.class); |
| 413 | + |
| 414 | + List<WithNestedListOfUUIDs> results2 = stream2 // |
| 415 | + .filter(WithNestedListOfUUIDs$.UUIDS.in(uuid1, uuid4)).collect(Collectors.toList()); |
| 416 | + |
| 417 | + List<String> ids2 = results2.stream().map(WithNestedListOfUUIDs::getId).collect(Collectors.toList()); |
| 418 | + assertThat(ids2).contains("withNestedListOfUUIDs1", "withNestedListOfUUIDs2"); |
| 419 | + |
| 420 | + SearchStream<WithNestedListOfUUIDs> stream3 = es.of(WithNestedListOfUUIDs.class); |
| 421 | + |
| 422 | + List<WithNestedListOfUUIDs> results3 = stream3 // |
| 423 | + .filter(WithNestedListOfUUIDs$.UUIDS.in(uuid1, uuid4)).collect(Collectors.toList()); |
| 424 | + |
| 425 | + List<String> ids3 = results3.stream().map(WithNestedListOfUUIDs::getId).collect(Collectors.toList()); |
| 426 | + assertThat(ids3).contains("withNestedListOfUUIDs1", "withNestedListOfUUIDs2"); |
| 427 | + } |
| 428 | + |
| 429 | + @Test void testFindByNestedListOfUUIDsValuesNotEq() { |
| 430 | + SearchStream<WithNestedListOfUUIDs> stream1 = es.of(WithNestedListOfUUIDs.class); |
| 431 | + |
| 432 | + List<WithNestedListOfUUIDs> results1 = stream1 // |
| 433 | + .filter(WithNestedListOfUUIDs$.UUIDS.notEq(uuid1, uuid2)).collect(Collectors.toList()); |
| 434 | + |
| 435 | + List<String> ids1 = results1.stream().map(WithNestedListOfUUIDs::getId).collect(Collectors.toList()); |
| 436 | + assertThat(ids1).containsExactly("withNestedListOfUUIDs2"); |
| 437 | + |
| 438 | + SearchStream<WithNestedListOfUUIDs> stream2 = es.of(WithNestedListOfUUIDs.class); |
| 439 | + |
| 440 | + List<WithNestedListOfUUIDs> results2 = stream2 // |
| 441 | + .filter(WithNestedListOfUUIDs$.UUIDS.notEq(uuid4, uuid5)).collect(Collectors.toList()); |
| 442 | + |
| 443 | + List<String> ids2 = results2.stream().map(WithNestedListOfUUIDs::getId).collect(Collectors.toList()); |
| 444 | + assertThat(ids2).containsExactly("withNestedListOfUUIDs1"); |
| 445 | + |
| 446 | + SearchStream<WithNestedListOfUUIDs> stream3 = es.of(WithNestedListOfUUIDs.class); |
| 447 | + |
| 448 | + List<WithNestedListOfUUIDs> results3 = stream3 // |
| 449 | + .filter(WithNestedListOfUUIDs$.UUIDS.notEq(uuid1, uuid4)).collect(Collectors.toList()); |
| 450 | + |
| 451 | + List<String> ids3 = results3.stream().map(WithNestedListOfUUIDs::getId).collect(Collectors.toList()); |
| 452 | + assertThat(ids3).isEmpty(); |
| 453 | + } |
| 454 | + |
| 455 | + // ULIDs Tests |
| 456 | + |
| 457 | + @Test void testFindByNestedListOfUlidsValuesIn() { |
| 458 | + SearchStream<WithNestedListOfUlids> stream1 = es.of(WithNestedListOfUlids.class); |
| 459 | + |
| 460 | + List<WithNestedListOfUlids> results1 = stream1 // |
| 461 | + .filter(WithNestedListOfUlids$.ULIDS.in(ulid1)).collect(Collectors.toList()); |
| 462 | + |
| 463 | + List<String> ids1 = results1.stream().map(WithNestedListOfUlids::getId).collect(Collectors.toList()); |
| 464 | + assertThat(ids1).contains("withNestedListOfUlids1"); |
| 465 | + |
| 466 | + SearchStream<WithNestedListOfUlids> stream2 = es.of(WithNestedListOfUlids.class); |
| 467 | + |
| 468 | + List<WithNestedListOfUlids> results2 = stream2 // |
| 469 | + .filter(WithNestedListOfUlids$.ULIDS.in(ulid1, ulid4)).collect(Collectors.toList()); |
| 470 | + |
| 471 | + List<String> ids2 = results2.stream().map(WithNestedListOfUlids::getId).collect(Collectors.toList()); |
| 472 | + assertThat(ids2).contains("withNestedListOfUlids1", "withNestedListOfUlids2"); |
| 473 | + |
| 474 | + SearchStream<WithNestedListOfUlids> stream3 = es.of(WithNestedListOfUlids.class); |
| 475 | + |
| 476 | + List<WithNestedListOfUlids> results3 = stream3 // |
| 477 | + .filter(WithNestedListOfUlids$.ULIDS.in(ulid1, ulid4)).collect(Collectors.toList()); |
| 478 | + |
| 479 | + List<String> ids3 = results3.stream().map(WithNestedListOfUlids::getId).collect(Collectors.toList()); |
| 480 | + assertThat(ids3).contains("withNestedListOfUlids1", "withNestedListOfUlids2"); |
| 481 | + } |
| 482 | + |
| 483 | + @Test void testFindByNestedListOfUlidsValuesNotEq() { |
| 484 | + SearchStream<WithNestedListOfUlids> stream1 = es.of(WithNestedListOfUlids.class); |
| 485 | + |
| 486 | + List<WithNestedListOfUlids> results1 = stream1 // |
| 487 | + .filter(WithNestedListOfUlids$.ULIDS.notEq(ulid1, ulid2)).collect(Collectors.toList()); |
| 488 | + |
| 489 | + List<String> ids1 = results1.stream().map(WithNestedListOfUlids::getId).collect(Collectors.toList()); |
| 490 | + assertThat(ids1).containsExactly("withNestedListOfUlids2"); |
| 491 | + |
| 492 | + SearchStream<WithNestedListOfUlids> stream2 = es.of(WithNestedListOfUlids.class); |
| 493 | + |
| 494 | + List<WithNestedListOfUlids> results2 = stream2 // |
| 495 | + .filter(WithNestedListOfUlids$.ULIDS.notEq(ulid4, ulid5)).collect(Collectors.toList()); |
| 496 | + |
| 497 | + List<String> ids2 = results2.stream().map(WithNestedListOfUlids::getId).collect(Collectors.toList()); |
| 498 | + assertThat(ids2).containsExactly("withNestedListOfUlids1"); |
| 499 | + |
| 500 | + SearchStream<WithNestedListOfUlids> stream3 = es.of(WithNestedListOfUlids.class); |
| 501 | + |
| 502 | + List<WithNestedListOfUlids> results3 = stream3 // |
| 503 | + .filter(WithNestedListOfUlids$.ULIDS.notEq(ulid1, ulid4)).collect(Collectors.toList()); |
| 504 | + |
| 505 | + List<String> ids3 = results3.stream().map(WithNestedListOfUlids::getId).collect(Collectors.toList()); |
| 506 | + assertThat(ids3).isEmpty(); |
| 507 | + } |
365 | 508 | }
|
0 commit comments