DATAES-562 - Custom name attribute for @Field mapping in ElasticsearchEntityMapper.

Original pull request: #270
This commit is contained in:
P.J.Meisch
2019-04-13 10:06:15 +02:00
committed by xhaggi
parent 17d9022181
commit e7857e874f
4 changed files with 74 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.core.mapping;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.Score;
import org.springframework.data.mapping.MappingException;
@@ -25,20 +26,49 @@ import org.springframework.data.mapping.MappingException;
* Unit tests for {@link SimpleElasticsearchPersistentProperty}.
*
* @author Oliver Gierke
* @author Peter-Josef Meisch
*/
public class SimpleElasticsearchPersistentPropertyUnitTests {
private final SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
@Test // DATAES-462
public void rejectsScorePropertyOfTypeOtherthanFloat() {
SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
assertThatExceptionOfType(MappingException.class) //
.isThrownBy(() -> context.getRequiredPersistentEntity(InvalidScoreProperty.class)) //
.withMessageContaining("scoreProperty");
}
@Test // DATAES-562
public void fieldAnnotationWithNameSetsFieldname() {
final SimpleElasticsearchPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(FieldNameProperty.class);
final ElasticsearchPersistentProperty persistentProperty = persistentEntity.getPersistentProperty("fieldProperty");
assertThat(persistentProperty).isNotNull();
assertThat(persistentProperty.getFieldName()).isEqualTo("by-name");
}
@Test // DATAES-562
public void fieldAnnotationWithValueSetsFieldname() {
final SimpleElasticsearchPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(FieldValueProperty.class);
final ElasticsearchPersistentProperty persistentProperty = persistentEntity.getPersistentProperty("fieldProperty");
assertThat(persistentProperty).isNotNull();
assertThat(persistentProperty.getFieldName()).isEqualTo("by-value");
}
static class InvalidScoreProperty {
@Score String scoreProperty;
}
static class FieldNameProperty {
@Field(name = "by-name") String fieldProperty;
}
static class FieldValueProperty {
@Field(value = "by-value") String fieldProperty;
}
}