add tests for path mappings

This commit is contained in:
kimchy 2010-05-14 12:17:17 +03:00
parent fcf3697e51
commit 911d800ff8
2 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,53 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you 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.elasticsearch.index.mapper.xcontent.path;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapper;
import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser;
import org.testng.annotations.Test;
import java.io.IOException;
import static org.elasticsearch.util.io.Streams.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class PathXContentMapperTests {
@Test public void testPathMapping() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/path/test-mapping.json");
XContentDocumentMapper docMapper = (XContentDocumentMapper) new XContentDocumentMapperParser(new AnalysisService(new Index("test"))).parse(mapping);
assertThat(docMapper.mappers().indexName("first1"), notNullValue());
assertThat(docMapper.mappers().indexName("name1.first1"), nullValue());
assertThat(docMapper.mappers().indexName("last1"), notNullValue());
assertThat(docMapper.mappers().indexName("name1.last1"), nullValue());
assertThat(docMapper.mappers().indexName("first2"), nullValue());
assertThat(docMapper.mappers().indexName("name2.first2"), notNullValue());
assertThat(docMapper.mappers().indexName("last2"), nullValue());
assertThat(docMapper.mappers().indexName("name2.last2"), notNullValue());
}
}

View File

@ -0,0 +1,22 @@
{
"person" : {
"properties" : {
"name1" : {
"type" : "object",
"path" : "just_name",
"properties" : {
"first1" : {"type" : "string", "store" : "yes"},
"last1" : {"type" : "string", "index" : "not_analyzed"}
}
},
"name2" : {
"type" : "object",
"path" : "full",
"properties" : {
"first2" : {"type" : "string", "store" : "yes"},
"last2" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
}
}