|
31 | 31 | import org.elasticsearch.action.index.IndexRequest;
|
32 | 32 | import org.elasticsearch.action.update.UpdateRequest;
|
33 | 33 | import org.elasticsearch.common.xcontent.XContentType;
|
| 34 | +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; |
34 | 35 | import org.junit.jupiter.api.Test;
|
35 | 36 | import org.springframework.data.annotation.Id;
|
36 | 37 | import org.springframework.data.elasticsearch.annotations.Document;
|
|
55 | 56 | * @author Sascha Woo
|
56 | 57 | * @author Don Wellington
|
57 | 58 | * @author Peter-Josef Meisch
|
| 59 | + * @author Massimiliano Poggi |
58 | 60 | */
|
59 | 61 | @SpringIntegrationTest
|
60 | 62 | @ContextConfiguration(classes = { ElasticsearchRestTemplateConfiguration.class })
|
@@ -100,6 +102,31 @@ public void shouldUseUpsertOnUpdate() throws IOException {
|
100 | 102 | assertThat(request.upsertRequest()).isNotNull();
|
101 | 103 | }
|
102 | 104 |
|
| 105 | + @Test // DATAES-693 |
| 106 | + public void shouldReturnSourceWhenRequested() throws IOException { |
| 107 | + // given |
| 108 | + Map<String, Object> doc = new HashMap<>(); |
| 109 | + doc.put("id", "1"); |
| 110 | + doc.put("message", "test"); |
| 111 | + |
| 112 | + UpdateRequest updateRequest = new UpdateRequest() |
| 113 | + .doc(doc) |
| 114 | + .fetchSource(FetchSourceContext.FETCH_SOURCE); |
| 115 | + |
| 116 | + UpdateQuery updateQuery = new UpdateQueryBuilder() // |
| 117 | + .withClass(SampleEntity.class) // |
| 118 | + .withId("1") // |
| 119 | + .withUpdateRequest(updateRequest).build(); |
| 120 | + |
| 121 | + // when |
| 122 | + UpdateRequest request = (UpdateRequest) ReflectionTestUtils // |
| 123 | + .invokeMethod(elasticsearchTemplate, "prepareUpdate", updateQuery); |
| 124 | + |
| 125 | + // then |
| 126 | + assertThat(request).isNotNull(); |
| 127 | + assertThat(request.fetchSource()).isEqualTo(FetchSourceContext.FETCH_SOURCE); |
| 128 | + } |
| 129 | + |
103 | 130 | @Data
|
104 | 131 | @Builder
|
105 | 132 | @Document(indexName = "test-index-sample-core-rest-template", type = "test-type", shards = 1, replicas = 0,
|
|
0 commit comments