DATAES-562 - Custom name attribute for @Field mapping in ElasticsearchEntityMapper.
Original pull request: #270
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user