From d67106af4e280706f35ada4c2659368e0d89ab1a Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 12 Jan 2016 14:51:05 +0100 Subject: [PATCH] added specific tests for isIngestEnabled methods --- .../ingest/IngestModuleTests.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 core/src/test/java/org/elasticsearch/ingest/IngestModuleTests.java diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestModuleTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestModuleTests.java new file mode 100644 index 00000000000..c5abb491161 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/ingest/IngestModuleTests.java @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch 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.ingest; + +import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.Matchers.equalTo; + +public class IngestModuleTests extends ESTestCase { + + public void testIsIngestEnabledSettings() { + assertThat(IngestModule.isIngestEnabled(Settings.EMPTY), equalTo(true)); + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", true).build()), equalTo(true)); + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", "true").build()), equalTo(true)); + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", false).build()), equalTo(false)); + + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", "false").build()), equalTo(false)); + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", "off").build()), equalTo(false)); + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", "no").build()), equalTo(false)); + assertThat(IngestModule.isIngestEnabled(Settings.builder().put("node.ingest", "0").build()), equalTo(false)); + } + + public void testIsIngestEnabledAttributes() { + assertThat(IngestModule.isIngestEnabled(ImmutableOpenMap.builder().build()), equalTo(true)); + + ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(); + builder.put("ingest", "true"); + assertThat(IngestModule.isIngestEnabled(builder.build()), equalTo(true)); + + builder = ImmutableOpenMap.builder(); + builder.put("ingest", "false"); + assertThat(IngestModule.isIngestEnabled(builder.build()), equalTo(false)); + + builder = ImmutableOpenMap.builder(); + builder.put("ingest", "off"); + assertThat(IngestModule.isIngestEnabled(builder.build()), equalTo(false)); + + builder = ImmutableOpenMap.builder(); + builder.put("ingest", "no"); + assertThat(IngestModule.isIngestEnabled(builder.build()), equalTo(false)); + + builder = ImmutableOpenMap.builder(); + builder.put("ingest", "0"); + assertThat(IngestModule.isIngestEnabled(builder.build()), equalTo(false)); + } + + public void testIsIngestEnabledMethodsReturnTheSameValue() { + String randomString; + if (randomBoolean()) { + randomString = randomFrom("true", "false", "on", "off", "yes", "no", "0", "1"); + } else { + randomString = randomAsciiOfLengthBetween(1, 5); + } + Settings settings = Settings.builder().put("node.ingest", randomString).build(); + ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(); + builder.put("ingest", randomString); + ImmutableOpenMap attributes = builder.build(); + + assertThat(IngestModule.isIngestEnabled(settings), equalTo(IngestModule.isIngestEnabled(attributes))); + } +}