|
18 | 18 | import static org.assertj.core.api.Assertions.*;
|
19 | 19 | import static org.elasticsearch.index.query.QueryBuilders.*;
|
20 | 20 | import static org.skyscreamer.jsonassert.JSONAssert.*;
|
21 |
| -import static org.springframework.data.elasticsearch.annotations.FieldType.*; |
22 | 21 | import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
23 | 22 |
|
24 |
| -import java.lang.Object; |
25 | 23 | import java.time.Duration;
|
26 | 24 | import java.util.Collections;
|
27 | 25 | import java.util.HashMap;
|
|
37 | 35 | import org.json.JSONException;
|
38 | 36 | import org.junit.jupiter.api.DisplayName;
|
39 | 37 | import org.junit.jupiter.api.Test;
|
40 |
| -import org.springframework.data.annotation.Id; |
| 38 | +import org.springframework.context.annotation.Bean; |
| 39 | +import org.springframework.context.annotation.Configuration; |
| 40 | +import org.springframework.context.annotation.Import; |
41 | 41 | import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
42 |
| -import org.springframework.data.elasticsearch.annotations.Document; |
43 |
| -import org.springframework.data.elasticsearch.annotations.Field; |
44 | 42 | import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
45 | 43 | import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
46 | 44 | import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
47 | 45 | import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
48 | 46 | import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
49 |
| -import org.springframework.lang.Nullable; |
| 47 | +import org.springframework.data.elasticsearch.utils.IndexNameProvider; |
50 | 48 | import org.springframework.test.context.ContextConfiguration;
|
51 | 49 |
|
52 | 50 | /**
|
|
64 | 62 | * @author Peter-Josef Meisch
|
65 | 63 | * @author Farid Faoudi
|
66 | 64 | */
|
67 |
| -@ContextConfiguration(classes = { ElasticsearchRestTemplateConfiguration.class }) |
| 65 | +@ContextConfiguration(classes = { ElasticsearchRestTemplateTests.Config.class }) |
68 | 66 | @DisplayName("ElasticsearchRestTemplate")
|
69 | 67 | public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {
|
70 | 68 |
|
| 69 | + @Configuration |
| 70 | + @Import({ ElasticsearchRestTemplateConfiguration.class }) |
| 71 | + static class Config { |
| 72 | + @Bean |
| 73 | + IndexNameProvider indexNameProvider() { |
| 74 | + return new IndexNameProvider("rest-template"); |
| 75 | + } |
| 76 | + } |
| 77 | + |
71 | 78 | @Test
|
72 | 79 | public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
73 | 80 |
|
74 | 81 | // when
|
75 | 82 | org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
|
76 | 83 | .create();
|
77 | 84 | UpdateQuery updateQuery = UpdateQuery.builder(nextIdAsString()).withDocument(document).build();
|
78 |
| - assertThatThrownBy(() -> operations.update(updateQuery, index)) |
| 85 | + assertThatThrownBy(() -> operations.update(updateQuery, IndexCoordinates.of(indexNameProvider.indexName()))) |
79 | 86 | .isInstanceOf(UncategorizedElasticsearchException.class);
|
80 | 87 | }
|
81 | 88 |
|
82 |
| - @Document(indexName = "test-index-sample-core-rest-template") |
83 |
| - static class SampleEntity { |
84 |
| - @Nullable @Id private String id; |
85 |
| - @Nullable |
86 |
| - @Field(type = Text, store = true, fielddata = true) private String type; |
87 |
| - |
88 |
| - @Nullable |
89 |
| - public String getId() { |
90 |
| - return id; |
91 |
| - } |
92 |
| - |
93 |
| - public void setId(@Nullable String id) { |
94 |
| - this.id = id; |
95 |
| - } |
96 |
| - |
97 |
| - @Nullable |
98 |
| - public String getType() { |
99 |
| - return type; |
100 |
| - } |
101 |
| - |
102 |
| - public void setType(@Nullable String type) { |
103 |
| - this.type = type; |
104 |
| - } |
105 |
| - } |
106 |
| - |
107 | 89 | @Test // DATAES-768
|
108 | 90 | void shouldUseAllOptionsFromUpdateQuery() {
|
109 | 91 | Map<String, Object> doc = new HashMap<>();
|
|
0 commit comments