|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.search.aggregations.support; |
| 21 | + |
| 22 | +import org.elasticsearch.common.io.stream.AbstractWriteableEnumTestCase; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | + |
| 26 | +import static org.hamcrest.Matchers.equalTo; |
| 27 | + |
| 28 | +public class ValuesSourceTypeTests extends AbstractWriteableEnumTestCase { |
| 29 | + |
| 30 | + public ValuesSourceTypeTests() { |
| 31 | + super(ValuesSourceType::fromStream); |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public void testValidOrdinals() { |
| 36 | + assertThat(ValuesSourceType.ANY.ordinal(), equalTo(0)); |
| 37 | + assertThat(ValuesSourceType.NUMERIC.ordinal(), equalTo(1)); |
| 38 | + assertThat(ValuesSourceType.BYTES.ordinal(), equalTo(2)); |
| 39 | + assertThat(ValuesSourceType.GEOPOINT.ordinal(), equalTo(3)); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public void testFromString() { |
| 44 | + assertThat(ValuesSourceType.fromString("any"), equalTo(ValuesSourceType.ANY)); |
| 45 | + assertThat(ValuesSourceType.fromString("numeric"), equalTo(ValuesSourceType.NUMERIC)); |
| 46 | + assertThat(ValuesSourceType.fromString("bytes"), equalTo(ValuesSourceType.BYTES)); |
| 47 | + assertThat(ValuesSourceType.fromString("geopoint"), equalTo(ValuesSourceType.GEOPOINT)); |
| 48 | + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ValuesSourceType.fromString("does_not_exist")); |
| 49 | + assertThat(e.getMessage(), |
| 50 | + equalTo("No enum constant org.elasticsearch.search.aggregations.support.ValuesSourceType.DOES_NOT_EXIST")); |
| 51 | + expectThrows(NullPointerException.class, () -> ValuesSourceType.fromString(null)); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public void testReadFrom() throws IOException { |
| 56 | + assertReadFromStream(0, ValuesSourceType.ANY); |
| 57 | + assertReadFromStream(1, ValuesSourceType.NUMERIC); |
| 58 | + assertReadFromStream(2, ValuesSourceType.BYTES); |
| 59 | + assertReadFromStream(3, ValuesSourceType.GEOPOINT); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public void testWriteTo() throws IOException { |
| 64 | + assertWriteToStream(ValuesSourceType.ANY, 0); |
| 65 | + assertWriteToStream(ValuesSourceType.NUMERIC, 1); |
| 66 | + assertWriteToStream(ValuesSourceType.BYTES, 2); |
| 67 | + assertWriteToStream(ValuesSourceType.GEOPOINT, 3); |
| 68 | + } |
| 69 | +} |
0 commit comments