|
| 1 | +package org.elasticsearch.index.mapper.null_value; |
| 2 | + |
| 3 | +/* |
| 4 | + * Licensed to Elasticsearch under one or more contributor |
| 5 | + * license agreements. See the NOTICE file distributed with |
| 6 | + * this work for additional information regarding copyright |
| 7 | + * ownership. Elasticsearch licenses this file to you under |
| 8 | + * the Apache License, Version 2.0 (the "License"); you may |
| 9 | + * not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | + |
| 22 | + |
| 23 | +import org.elasticsearch.common.settings.ImmutableSettings; |
| 24 | +import org.elasticsearch.common.xcontent.XContentFactory; |
| 25 | +import org.elasticsearch.index.mapper.MapperParsingException; |
| 26 | +import org.elasticsearch.index.service.IndexService; |
| 27 | +import org.elasticsearch.test.ElasticsearchSingleNodeTest; |
| 28 | +import org.junit.Test; |
| 29 | + |
| 30 | +import static org.hamcrest.Matchers.*; |
| 31 | + |
| 32 | +/** |
| 33 | + */ |
| 34 | +public class NullValueTests extends ElasticsearchSingleNodeTest { |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testNullNull_Value() throws Exception { |
| 38 | + IndexService indexService = createIndex("test", ImmutableSettings.settingsBuilder().build()); |
| 39 | + String[] typesToTest = {"integer", "long", "double", "float", "short", "date", "ip", "string", "boolean", "byte"}; |
| 40 | + |
| 41 | + for (String type : typesToTest) { |
| 42 | + String mapping = XContentFactory.jsonBuilder() |
| 43 | + .startObject() |
| 44 | + .startObject("type") |
| 45 | + .startObject("properties") |
| 46 | + .startObject("numeric") |
| 47 | + .field("type", type) |
| 48 | + .field("null_value", (String) null) |
| 49 | + .endObject() |
| 50 | + .endObject() |
| 51 | + .endObject() |
| 52 | + .endObject().string(); |
| 53 | + |
| 54 | + try { |
| 55 | + indexService.mapperService().documentMapperParser().parse(mapping); |
| 56 | + fail("Test should have failed because [null_value] was null."); |
| 57 | + } catch (MapperParsingException e) { |
| 58 | + assertThat(e.getMessage(), equalTo("Property [null_value] cannot be null.")); |
| 59 | + } |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + } |
| 65 | +} |
0 commit comments