DATAES-209 - Dynamic mapping using @Mapping Annotation at field level
fix test fix comment in test
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
|
||||
/**
|
||||
* Sample FieldDynamicMappingEntity for test dynamic mapping using @Mapping Annotation at field level
|
||||
*
|
||||
* @author Ted Liang
|
||||
*/
|
||||
@Document(indexName = "test-field-mapping-index", type = "test-field-mapping-type")
|
||||
public class FieldDynamicMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Mapping(mappingPath = "/mappings/test-field-mappings.json")
|
||||
private byte[] file;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public byte[] getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(byte[] file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repositories.setting;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.FieldDynamicMappingEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
||||
|
||||
/**
|
||||
* FieldDynamicMappingEntityRepository
|
||||
*
|
||||
* @author Ted Liang
|
||||
*/
|
||||
public interface FieldDynamicMappingEntityRepository extends ElasticsearchCrudRepository<FieldDynamicMappingEntity, String> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repositories.setting;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.entities.FieldDynamicMappingEntity;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* FieldDynamicMappingEntityRepositoryTests
|
||||
*
|
||||
* @author Ted Liang
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:dynamic-settings-test.xml")
|
||||
public class FieldDynamicMappingEntityRepositoryTests {
|
||||
|
||||
@Autowired
|
||||
private FieldDynamicMappingEntityRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(FieldDynamicMappingEntity.class);
|
||||
elasticsearchTemplate.createIndex(FieldDynamicMappingEntity.class);
|
||||
elasticsearchTemplate.putMapping(FieldDynamicMappingEntity.class);
|
||||
elasticsearchTemplate.refresh(FieldDynamicMappingEntity.class, true);
|
||||
}
|
||||
|
||||
/*
|
||||
DATAES-209
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateMappingWithMappingAnnotationAtFieldLevel() {
|
||||
//given
|
||||
|
||||
//then
|
||||
Map mapping = elasticsearchTemplate.getMapping(FieldDynamicMappingEntity.class);
|
||||
assertThat(mapping, is(notNullValue()));
|
||||
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
assertThat(properties, is(notNullValue()));
|
||||
|
||||
assertThat(properties.containsKey("file"), is(true));
|
||||
Map file = (Map) properties.get("file");
|
||||
assertThat(file, is(notNullValue()));
|
||||
assertThat(((String) file.get("type")), is("string"));
|
||||
|
||||
assertThat(file.containsKey("fields"), is(true));
|
||||
Map fields = (Map) file.get("fields");
|
||||
assertThat(fields, is(notNullValue()));
|
||||
|
||||
assertThat(fields.containsKey("content"), is(true));
|
||||
Map content = (Map) fields.get("content");
|
||||
assertThat(content, is(notNullValue()));
|
||||
|
||||
assertThat((String)content.get("type"), is("string"));
|
||||
assertThat((String)content.get("term_vector"), is("with_positions_offsets"));
|
||||
assertThat((Boolean)content.get("store"), is(Boolean.TRUE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user