From 911d800ff89de36d9511d1830b678eef512a2c87 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 14 May 2010 12:17:17 +0300 Subject: [PATCH] add tests for path mappings --- .../path/PathXContentMapperTests.java | 53 +++++++++++++++++++ .../mapper/xcontent/path/test-mapping.json | 22 ++++++++ 2 files changed, 75 insertions(+) create mode 100644 modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/PathXContentMapperTests.java create mode 100644 modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/test-mapping.json diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/PathXContentMapperTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/PathXContentMapperTests.java new file mode 100644 index 00000000000..e7cbc252b48 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/PathXContentMapperTests.java @@ -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()); + } +} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/test-mapping.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/test-mapping.json new file mode 100644 index 00000000000..994a6b7b786 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/path/test-mapping.json @@ -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"} + } + } + } + } +} \ No newline at end of file