|
25 | 25 | import lombok.Data;
|
26 | 26 | import lombok.NoArgsConstructor;
|
27 | 27 |
|
| 28 | +import java.io.IOException; |
28 | 29 | import java.lang.Long;
|
29 | 30 | import java.util.ArrayList;
|
30 | 31 | import java.util.Arrays;
|
31 | 32 | import java.util.Collections;
|
32 | 33 | import java.util.List;
|
33 | 34 | import java.util.Optional;
|
| 35 | +import java.util.stream.Collectors; |
34 | 36 |
|
35 | 37 | import org.junit.jupiter.api.AfterEach;
|
36 | 38 | import org.junit.jupiter.api.BeforeEach;
|
|
56 | 58 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
57 | 59 | import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
58 | 60 | import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
| 61 | +import org.springframework.data.util.StreamUtils; |
59 | 62 | import org.springframework.test.context.ContextConfiguration;
|
60 | 63 |
|
61 | 64 | /**
|
@@ -361,6 +364,14 @@ public void shouldReturnResultsForGivenSearchQuery() {
|
361 | 364 | @Test
|
362 | 365 | public void shouldDeleteAll() {
|
363 | 366 |
|
| 367 | + // given |
| 368 | + String documentId = randomNumeric(5); |
| 369 | + SampleEntity sampleEntity = new SampleEntity(); |
| 370 | + sampleEntity.setId(documentId); |
| 371 | + sampleEntity.setMessage("hello world."); |
| 372 | + sampleEntity.setVersion(System.currentTimeMillis()); |
| 373 | + repository.save(sampleEntity); |
| 374 | + |
364 | 375 | // when
|
365 | 376 | repository.deleteAll();
|
366 | 377 |
|
@@ -677,6 +688,32 @@ public void shouldNotFailOnIndexingEmptyList() {
|
677 | 688 | assertThat(savedEntities).hasSize(0);
|
678 | 689 | }
|
679 | 690 |
|
| 691 | + @Test // DATAES-832 |
| 692 | + void shouldNotReturnNullValuesInFindAllById() throws IOException { |
| 693 | + |
| 694 | + // given |
| 695 | + String documentId1 = "id-one"; |
| 696 | + SampleEntity sampleEntity1 = new SampleEntity(); |
| 697 | + sampleEntity1.setId(documentId1); |
| 698 | + repository.save(sampleEntity1); |
| 699 | + String documentId2 = "id-two"; |
| 700 | + SampleEntity sampleEntity2 = new SampleEntity(); |
| 701 | + sampleEntity2.setId(documentId2); |
| 702 | + repository.save(sampleEntity2); |
| 703 | + String documentId3 = "id-three"; |
| 704 | + SampleEntity sampleEntity3 = new SampleEntity(); |
| 705 | + sampleEntity3.setId(documentId3); |
| 706 | + repository.save(sampleEntity3); |
| 707 | + |
| 708 | + Iterable<SampleEntity> allById = repository |
| 709 | + .findAllById(Arrays.asList("id-one", "does-not-exist", "id-two", "where-am-i", "id-three")); |
| 710 | + List<SampleEntity> results = StreamUtils.createStreamFromIterator(allById.iterator()).collect(Collectors.toList()); |
| 711 | + |
| 712 | + assertThat(results).hasSize(3); |
| 713 | + assertThat(results.stream().map(SampleEntity::getId).collect(Collectors.toList())) |
| 714 | + .containsExactlyInAnyOrder("id-one", "id-two", "id-three"); |
| 715 | + } |
| 716 | + |
680 | 717 | private static List<SampleEntity> createSampleEntitiesWithMessage(String message, int numberOfEntities) {
|
681 | 718 |
|
682 | 719 | List<SampleEntity> sampleEntities = new ArrayList<>();
|
|
0 commit comments