Skip to content

Commit b6fa4c8

Browse files
committedMay 6, 2019
DATAES-568 - Polishing.
Add package-info and nullability annotations to org.springframework.data.elasticsearch.core.mapping. Extract method to avoid excessive nesting. Add ticket references/convert old references to test methods. Move test models to inner classes. Use static imports for JSON Assert. Formatting. Original pull request: #281.
·
6.0.0-M33.2.0.M4
1 parent 66b77ec commit b6fa4c8

12 files changed

+332
-337
lines changed
 

‎src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import org.elasticsearch.search.suggest.SuggestBuilder;
9090
import org.slf4j.Logger;
9191
import org.slf4j.LoggerFactory;
92+
9293
import org.springframework.beans.BeansException;
9394
import org.springframework.context.ApplicationContext;
9495
import org.springframework.context.ApplicationContextAware;
@@ -224,7 +225,7 @@ public <T> boolean putMapping(Class<T> clazz) {
224225
}
225226
try {
226227
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
227-
return putMapping(clazz, mappingBuilder.buildMapping(clazz));
228+
return putMapping(clazz, mappingBuilder.buildPropertyMapping(clazz));
228229
} catch (Exception e) {
229230
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
230231
}
@@ -497,8 +498,7 @@ public <T> Page<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultM
497498
@Override
498499
public <T> CloseableIterator<T> stream(CriteriaQuery query, Class<T> clazz) {
499500
final long scrollTimeInMillis = TimeValue.timeValueMinutes(1).millis();
500-
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz), clazz,
501-
resultsMapper);
501+
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz), clazz, resultsMapper);
502502
}
503503

504504
@Override
@@ -509,8 +509,7 @@ public <T> CloseableIterator<T> stream(SearchQuery query, Class<T> clazz) {
509509
@Override
510510
public <T> CloseableIterator<T> stream(SearchQuery query, final Class<T> clazz, final SearchResultMapper mapper) {
511511
final long scrollTimeInMillis = TimeValue.timeValueMinutes(1).millis();
512-
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz, mapper), clazz,
513-
mapper);
512+
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz, mapper), clazz, mapper);
514513
}
515514

516515
private <T> CloseableIterator<T> doStream(final long scrollTimeInMillis, final ScrolledPage<T> page,
@@ -1453,8 +1452,7 @@ List<AliasMetaData> convertAliasResponse(String aliasResponse) {
14531452
node = node.findValue("aliases");
14541453

14551454
Map<String, AliasData> aliasData = mapper.readValue(mapper.writeValueAsString(node),
1456-
new TypeReference<Map<String, AliasData>>() {
1457-
});
1455+
new TypeReference<Map<String, AliasData>>() {});
14581456

14591457
Iterable<Map.Entry<String, AliasData>> aliasIter = aliasData.entrySet();
14601458
List<AliasMetaData> aliasMetaDataList = new ArrayList<AliasMetaData>();

‎src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public <T> boolean putMapping(Class<T> clazz) {
206206
}
207207
try {
208208
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
209-
return putMapping(clazz, mappingBuilder.buildMapping(clazz));
209+
return putMapping(clazz, mappingBuilder.buildPropertyMapping(clazz));
210210
} catch (Exception e) {
211211
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
212212
}

‎src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java

Lines changed: 95 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,25 @@
2727
import org.elasticsearch.common.xcontent.XContentType;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
30+
3031
import org.springframework.core.io.ClassPathResource;
3132
import org.springframework.data.annotation.Transient;
32-
import org.springframework.data.elasticsearch.annotations.*;
33+
import org.springframework.data.elasticsearch.annotations.CompletionContext;
34+
import org.springframework.data.elasticsearch.annotations.CompletionField;
35+
import org.springframework.data.elasticsearch.annotations.DateFormat;
36+
import org.springframework.data.elasticsearch.annotations.DynamicTemplates;
37+
import org.springframework.data.elasticsearch.annotations.Field;
38+
import org.springframework.data.elasticsearch.annotations.FieldType;
39+
import org.springframework.data.elasticsearch.annotations.GeoPointField;
40+
import org.springframework.data.elasticsearch.annotations.InnerField;
41+
import org.springframework.data.elasticsearch.annotations.Mapping;
42+
import org.springframework.data.elasticsearch.annotations.MultiField;
3343
import org.springframework.data.elasticsearch.core.completion.Completion;
3444
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
3545
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
3646
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
3747
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
3848
import org.springframework.data.mapping.PropertyHandler;
39-
import org.springframework.data.mapping.model.SimpleTypeHolder;
4049
import org.springframework.data.util.TypeInformation;
4150
import org.springframework.lang.Nullable;
4251
import org.springframework.util.StringUtils;
@@ -61,34 +70,33 @@
6170
*/
6271
class MappingBuilder {
6372

64-
public static final String FIELD_DATA = "fielddata";
65-
public static final String FIELD_STORE = "store";
66-
public static final String FIELD_TYPE = "type";
67-
public static final String FIELD_INDEX = "index";
68-
public static final String FIELD_FORMAT = "format";
69-
public static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
70-
public static final String FIELD_INDEX_ANALYZER = "analyzer";
71-
public static final String FIELD_NORMALIZER = "normalizer";
72-
public static final String FIELD_PROPERTIES = "properties";
73-
public static final String FIELD_PARENT = "_parent";
74-
public static final String FIELD_COPY_TO = "copy_to";
75-
public static final String FIELD_CONTEXT_NAME = "name";
76-
public static final String FIELD_CONTEXT_TYPE = "type";
77-
public static final String FIELD_CONTEXT_PRECISION = "precision";
78-
public static final String FIELD_DYNAMIC_TEMPLATES = "dynamic_templates";
79-
80-
public static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
81-
public static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
82-
public static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
83-
public static final String COMPLETION_CONTEXTS = "contexts";
84-
85-
public static final String TYPE_VALUE_KEYWORD = "keyword";
86-
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
87-
public static final String TYPE_VALUE_COMPLETION = "completion";
88-
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
89-
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
73+
private static final String FIELD_DATA = "fielddata";
74+
private static final String FIELD_STORE = "store";
75+
private static final String FIELD_TYPE = "type";
76+
private static final String FIELD_INDEX = "index";
77+
private static final String FIELD_FORMAT = "format";
78+
private static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
79+
private static final String FIELD_INDEX_ANALYZER = "analyzer";
80+
private static final String FIELD_NORMALIZER = "normalizer";
81+
private static final String FIELD_PROPERTIES = "properties";
82+
private static final String FIELD_PARENT = "_parent";
83+
private static final String FIELD_COPY_TO = "copy_to";
84+
private static final String FIELD_CONTEXT_NAME = "name";
85+
private static final String FIELD_CONTEXT_TYPE = "type";
86+
private static final String FIELD_CONTEXT_PRECISION = "precision";
87+
private static final String FIELD_DYNAMIC_TEMPLATES = "dynamic_templates";
88+
89+
private static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
90+
private static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
91+
private static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
92+
private static final String COMPLETION_CONTEXTS = "contexts";
93+
94+
private static final String TYPE_VALUE_KEYWORD = "keyword";
95+
private static final String TYPE_VALUE_GEO_POINT = "geo_point";
96+
private static final String TYPE_VALUE_COMPLETION = "completion";
97+
9098
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchRestTemplate.class);
91-
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = SimpleTypeHolder.DEFAULT;
99+
92100
private final ElasticsearchConverter elasticsearchConverter;
93101

94102
MappingBuilder(ElasticsearchConverter elasticsearchConverter) {
@@ -101,7 +109,7 @@ class MappingBuilder {
101109
* @return JSON string
102110
* @throws IOException
103111
*/
104-
String buildMapping(Class<?> clazz) throws IOException {
112+
String buildPropertyMapping(Class<?> clazz) throws IOException {
105113

106114
ElasticsearchPersistentEntity<?> entity = elasticsearchConverter.getMappingContext()
107115
.getRequiredPersistentEntity(clazz);
@@ -157,70 +165,76 @@ private void mapEntity(XContentBuilder builder, @Nullable ElasticsearchPersisten
157165
return;
158166
}
159167

160-
if (property.isAnnotationPresent(Mapping.class)) {
168+
buildPropertyMapping(builder, isRootObject, property);
169+
} catch (IOException e) {
170+
logger.warn("error mapping property with name {}", property.getName(), e);
171+
}
172+
});
173+
}
161174

162-
String mappingPath = property.getRequiredAnnotation(Mapping.class).mappingPath();
163-
if (!StringUtils.isEmpty(mappingPath)) {
175+
if (writeNestedProperties) {
176+
builder.endObject().endObject();
177+
}
178+
}
164179

165-
ClassPathResource mappings = new ClassPathResource(mappingPath);
166-
if (mappings.exists()) {
167-
builder.rawField(property.getFieldName(), mappings.getInputStream(), XContentType.JSON);
168-
return;
169-
}
170-
}
171-
}
180+
private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
181+
ElasticsearchPersistentProperty property) throws IOException {
172182

173-
boolean isGeoPointProperty = isGeoPointProperty(property);
174-
boolean isCompletionProperty = isCompletionProperty(property);
175-
boolean isNestedOrObjectProperty = isNestedOrObjectProperty(property);
183+
if (property.isAnnotationPresent(Mapping.class)) {
176184

177-
Field fieldAnnotation = property.findAnnotation(Field.class);
178-
if (!isGeoPointProperty && !isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {
185+
String mappingPath = property.getRequiredAnnotation(Mapping.class).mappingPath();
186+
if (!StringUtils.isEmpty(mappingPath)) {
179187

180-
if (fieldAnnotation == null) {
181-
return;
182-
}
188+
ClassPathResource mappings = new ClassPathResource(mappingPath);
189+
if (mappings.exists()) {
190+
builder.rawField(property.getFieldName(), mappings.getInputStream(), XContentType.JSON);
191+
return;
192+
}
193+
}
194+
}
183195

184-
Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
185-
ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
186-
? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
187-
: null;
196+
boolean isGeoPointProperty = isGeoPointProperty(property);
197+
boolean isCompletionProperty = isCompletionProperty(property);
198+
boolean isNestedOrObjectProperty = isNestedOrObjectProperty(property);
188199

189-
mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty,
190-
fieldAnnotation.type(), fieldAnnotation);
200+
Field fieldAnnotation = property.findAnnotation(Field.class);
201+
if (!isGeoPointProperty && !isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {
191202

192-
if (isNestedOrObjectProperty) {
193-
return;
194-
}
195-
}
203+
if (fieldAnnotation == null) {
204+
return;
205+
}
196206

197-
MultiField multiField = property.findAnnotation(MultiField.class);
207+
Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
208+
ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
209+
? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
210+
: null;
198211

199-
if (isGeoPointProperty) {
200-
applyGeoPointFieldMapping(builder, property);
201-
return;
202-
}
212+
mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty,
213+
fieldAnnotation.type(), fieldAnnotation);
203214

204-
if (isCompletionProperty) {
205-
CompletionField completionField = property.findAnnotation(CompletionField.class);
206-
applyCompletionFieldMapping(builder, property, completionField);
207-
}
215+
if (isNestedOrObjectProperty) {
216+
return;
217+
}
218+
}
208219

209-
if (isRootObject && fieldAnnotation != null && property.isIdProperty()) {
210-
applyDefaultIdFieldMapping(builder, property);
211-
} else if (multiField != null) {
212-
addMultiFieldMapping(builder, property, multiField, isNestedOrObjectProperty);
213-
} else if (fieldAnnotation != null) {
214-
addSingleFieldMapping(builder, property, fieldAnnotation, isNestedOrObjectProperty);
215-
}
216-
} catch (IOException e) {
217-
logger.warn("error mapping property with name {}", property.getName(), e);
218-
}
219-
});
220+
MultiField multiField = property.findAnnotation(MultiField.class);
221+
222+
if (isGeoPointProperty) {
223+
applyGeoPointFieldMapping(builder, property);
224+
return;
220225
}
221226

222-
if (writeNestedProperties) {
223-
builder.endObject().endObject();
227+
if (isCompletionProperty) {
228+
CompletionField completionField = property.findAnnotation(CompletionField.class);
229+
applyCompletionFieldMapping(builder, property, completionField);
230+
}
231+
232+
if (isRootObject && fieldAnnotation != null && property.isIdProperty()) {
233+
applyDefaultIdFieldMapping(builder, property);
234+
} else if (multiField != null) {
235+
addMultiFieldMapping(builder, property, multiField, isNestedOrObjectProperty);
236+
} else if (fieldAnnotation != null) {
237+
addSingleFieldMapping(builder, property, fieldAnnotation, isNestedOrObjectProperty);
224238
}
225239
}
226240

@@ -321,6 +335,7 @@ private void addMultiFieldMapping(XContentBuilder builder, ElasticsearchPersiste
321335

322336
private void addFieldMappingParameters(XContentBuilder builder, Object annotation, boolean nestedOrObjectField)
323337
throws IOException {
338+
324339
boolean index = true;
325340
boolean store = false;
326341
boolean fielddata = false;

‎src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchMappingContext.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.data.mapping.model.Property;
2323
import org.springframework.data.mapping.model.SimpleTypeHolder;
2424
import org.springframework.data.util.TypeInformation;
25+
import org.springframework.lang.Nullable;
2526

2627
/**
2728
* SimpleElasticsearchMappingContext
@@ -30,10 +31,11 @@
3031
* @author Mohsin Husen
3132
* @author Mark Paluch
3233
*/
33-
public class SimpleElasticsearchMappingContext extends
34-
AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> implements ApplicationContextAware {
34+
public class SimpleElasticsearchMappingContext
35+
extends AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty>
36+
implements ApplicationContextAware {
3537

36-
private ApplicationContext context;
38+
private @Nullable ApplicationContext context;
3739

3840
@Override
3941
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {

‎src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,22 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
5555
private final StandardEvaluationContext context;
5656
private final SpelExpressionParser parser;
5757

58-
private String indexName;
59-
private String indexType;
58+
private @Nullable String indexName;
59+
private @Nullable String indexType;
6060
private boolean useServerConfiguration;
6161
private short shards;
6262
private short replicas;
63-
private String refreshInterval;
64-
private String indexStoreType;
65-
private String parentType;
66-
private ElasticsearchPersistentProperty parentIdProperty;
67-
private ElasticsearchPersistentProperty scoreProperty;
68-
private String settingPath;
63+
private @Nullable String refreshInterval;
64+
private @Nullable String indexStoreType;
65+
private @Nullable String parentType;
66+
private @Nullable ElasticsearchPersistentProperty parentIdProperty;
67+
private @Nullable ElasticsearchPersistentProperty scoreProperty;
68+
private @Nullable String settingPath;
6969
private VersionType versionType;
7070
private boolean createIndexAndMapping;
7171

7272
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
73+
7374
super(typeInformation);
7475
this.context = new StandardEvaluationContext();
7576
this.parser = new SpelExpressionParser();
@@ -104,7 +105,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
104105
@Override
105106
public String getIndexName() {
106107

107-
if(indexName != null) {
108+
if (indexName != null) {
108109
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
109110
return expression.getValue(context, String.class);
110111
}
@@ -115,7 +116,7 @@ public String getIndexName() {
115116
@Override
116117
public String getIndexType() {
117118

118-
if(indexType != null) {
119+
if (indexType != null) {
119120
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
120121
return expression.getValue(context, String.class);
121122
}
@@ -192,9 +193,10 @@ public void addPersistentProperty(ElasticsearchPersistentProperty property) {
192193
ElasticsearchPersistentProperty parentProperty = this.parentIdProperty;
193194

194195
if (parentProperty != null) {
195-
throw new MappingException(
196-
String.format("Attempt to add parent property %s but already have property %s registered "
197-
+ "as parent property. Check your mapping configuration!", property.getField(), parentProperty.getField()));
196+
throw new MappingException(String.format(
197+
"Attempt to add parent property %s but already have property %s registered "
198+
+ "as parent property. Check your mapping configuration!",
199+
property.getField(), parentProperty.getField()));
198200
}
199201

200202
Parent parentAnnotation = property.findAnnotation(Parent.class);
@@ -203,26 +205,27 @@ public void addPersistentProperty(ElasticsearchPersistentProperty property) {
203205
}
204206

205207
if (property.isScoreProperty()) {
206-
208+
207209
ElasticsearchPersistentProperty scoreProperty = this.scoreProperty;
208210

209211
if (scoreProperty != null) {
210-
throw new MappingException(
211-
String.format("Attempt to add score property %s but already have property %s registered "
212-
+ "as score property. Check your mapping configuration!", property.getField(), scoreProperty.getField()));
212+
throw new MappingException(String.format(
213+
"Attempt to add score property %s but already have property %s registered "
214+
+ "as score property. Check your mapping configuration!",
215+
property.getField(), scoreProperty.getField()));
213216
}
214217

215218
this.scoreProperty = property;
216219
}
217220
}
218-
219-
/*
221+
222+
/*
220223
* (non-Javadoc)
221224
* @see org.springframework.data.mapping.model.BasicPersistentEntity#setPersistentPropertyAccessorFactory(org.springframework.data.mapping.model.PersistentPropertyAccessorFactory)
222225
*/
223226
@Override
224227
public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory) {
225-
228+
226229
// Do nothing to avoid the usage of ClassGeneratingPropertyAccessorFactory for now
227230
// DATACMNS-1322 switches to proper immutability behavior which Spring Data Elasticsearch
228231
// cannot yet implement

‎src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
2828
import org.springframework.data.mapping.model.Property;
2929
import org.springframework.data.mapping.model.SimpleTypeHolder;
30+
import org.springframework.lang.Nullable;
3031
import org.springframework.util.StringUtils;
3132

3233
/**
@@ -47,7 +48,7 @@ public class SimpleElasticsearchPersistentProperty extends
4748
private final boolean isScore;
4849
private final boolean isParent;
4950
private final boolean isId;
50-
private final String annotatedFieldName;
51+
private final @Nullable String annotatedFieldName;
5152

5253
public SimpleElasticsearchPersistentProperty(Property property,
5354
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
@@ -59,20 +60,21 @@ public SimpleElasticsearchPersistentProperty(Property property,
5960
this.isScore = isAnnotationPresent(Score.class);
6061
this.isParent = isAnnotationPresent(Parent.class);
6162

62-
if (isVersionProperty() && getType() != Long.class) {
63+
if (isVersionProperty() && !getType().equals(Long.class)) {
6364
throw new MappingException(String.format("Version property %s must be of type Long!", property.getName()));
6465
}
6566

66-
if (isScore && !Arrays.asList(Float.TYPE, Float.class).contains(getType())) {
67+
if (isScore && !getType().equals(Float.TYPE) && !getType().equals(Float.class)) {
6768
throw new MappingException(
6869
String.format("Score property %s must be either of type float or Float!", property.getName()));
6970
}
7071

71-
if (isParent && getType() != String.class) {
72+
if (isParent && !getType().equals(String.class)) {
7273
throw new MappingException(String.format("Parent property %s must be of type String!", property.getName()));
7374
}
7475
}
7576

77+
@Nullable
7678
private String getAnnotatedFieldName() {
7779

7880
if (isAnnotationPresent(Field.class)) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
/**
3+
* Infrastructure for the Elasticsearch document-to-object mapping subsystem.
4+
*/
5+
@org.springframework.lang.NonNullApi
6+
package org.springframework.data.elasticsearch.core.mapping;

‎src/test/java/org/springframework/data/elasticsearch/core/MappingBuilderTests.java

Lines changed: 172 additions & 70 deletions
Large diffs are not rendered by default.

‎src/test/java/org/springframework/data/elasticsearch/core/SimpleDynamicTemplatesMappingTests.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.springframework.data.elasticsearch.core;
22

3+
import static org.junit.Assert.*;
4+
35
import java.io.IOException;
46

5-
import org.junit.Assert;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
9+
810
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntity;
911
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntityTwo;
1012
import org.springframework.test.context.ContextConfiguration;
@@ -20,26 +22,30 @@
2022
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
2123
public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests {
2224

23-
@Test
25+
@Test // DATAES-568
2426
public void testCorrectDynamicTemplatesMappings() throws IOException {
25-
String mapping = getMappingBuilder().buildMapping(SampleDynamicTemplatesEntity.class);
27+
28+
String mapping = getMappingBuilder().buildPropertyMapping(SampleDynamicTemplatesEntity.class);
2629

2730
String EXPECTED_MAPPING_ONE = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":"
2831
+ "[{\"with_custom_analyzer\":{"
2932
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
3033
+ "\"path_match\":\"names.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}}";
31-
Assert.assertEquals(EXPECTED_MAPPING_ONE, mapping);
34+
35+
assertEquals(EXPECTED_MAPPING_ONE, mapping);
3236
}
3337

34-
@Test
38+
@Test // DATAES-568
3539
public void testCorrectDynamicTemplatesMappingsTwo() throws IOException {
36-
String mapping = getMappingBuilder().buildMapping(SampleDynamicTemplatesEntityTwo.class);
40+
41+
String mapping = getMappingBuilder().buildPropertyMapping(SampleDynamicTemplatesEntityTwo.class);
3742
String EXPECTED_MAPPING_TWO = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":"
3843
+ "[{\"with_custom_analyzer\":{"
3944
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
4045
+ "\"path_match\":\"names.*\"}}," + "{\"participantA1_with_custom_analyzer\":{"
4146
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
4247
+ "\"path_match\":\"participantA1.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}}";
43-
Assert.assertEquals(EXPECTED_MAPPING_TWO, mapping);
48+
49+
assertEquals(EXPECTED_MAPPING_TWO, mapping);
4450
}
4551
}

‎src/test/java/org/springframework/data/elasticsearch/core/SimpleElasticsearchDateMappingTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
*/
1616
package org.springframework.data.elasticsearch.core;
1717

18+
import static org.junit.Assert.*;
19+
1820
import java.io.IOException;
1921

20-
import org.junit.Assert;
2122
import org.junit.Test;
23+
2224
import org.springframework.data.elasticsearch.entities.SampleDateMappingEntity;
2325

2426
/**
@@ -34,11 +36,11 @@ public class SimpleElasticsearchDateMappingTests extends MappingContextBaseTests
3436
+ "\"defaultFormatDate\":{\"store\":false,\"type\":\"date\"},\"basicFormatDate\":{\"store\":false,\""
3537
+ "type\":\"date\",\"format\":\"basic_date\"}}}}";
3638

37-
@Test
39+
@Test // DATAES-568
3840
public void testCorrectDateMappings() throws IOException {
3941

40-
String mapping = getMappingBuilder().buildMapping(SampleDateMappingEntity.class);
42+
String mapping = getMappingBuilder().buildPropertyMapping(SampleDateMappingEntity.class);
4143

42-
Assert.assertEquals(EXPECTED_MAPPING, mapping);
44+
assertEquals(EXPECTED_MAPPING, mapping);
4345
}
4446
}

‎src/test/java/org/springframework/data/elasticsearch/entities/FieldNameEntity.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

‎src/test/java/org/springframework/data/elasticsearch/entities/MinimalChildEntity.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.