|
| 1 | +/* |
| 2 | + * Copyright 2026 Conductor Authors. |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * <p> |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * <p> |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | +package com.netflix.conductor.es7.config; |
| 14 | + |
| 15 | +import org.junit.Test; |
| 16 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 17 | +import org.springframework.context.annotation.Bean; |
| 18 | +import org.springframework.context.annotation.Conditional; |
| 19 | +import org.springframework.context.annotation.Configuration; |
| 20 | + |
| 21 | +import static org.junit.Assert.assertFalse; |
| 22 | +import static org.junit.Assert.assertTrue; |
| 23 | + |
| 24 | +public class ElasticSearchConditionsTest { |
| 25 | + |
| 26 | + private final ApplicationContextRunner contextRunner = |
| 27 | + new ApplicationContextRunner() |
| 28 | + .withUserConfiguration(ConditionalTestConfiguration.class); |
| 29 | + |
| 30 | + @Test |
| 31 | + public void shouldActivateForElasticsearchV7Selector() { |
| 32 | + contextRunner |
| 33 | + .withPropertyValues( |
| 34 | + "conductor.indexing.enabled=true", |
| 35 | + "conductor.indexing.type=elasticsearch", |
| 36 | + "conductor.elasticsearch.version=7") |
| 37 | + .run(context -> assertTrue(context.containsBean("es7Marker"))); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void shouldActivateWhenVersionIsImplicit() { |
| 42 | + contextRunner |
| 43 | + .withPropertyValues( |
| 44 | + "conductor.indexing.enabled=true", "conductor.indexing.type=elasticsearch") |
| 45 | + .run(context -> assertTrue(context.containsBean("es7Marker"))); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void shouldNotActivateWhenIndexingIsDisabled() { |
| 50 | + contextRunner |
| 51 | + .withPropertyValues( |
| 52 | + "conductor.indexing.enabled=false", |
| 53 | + "conductor.indexing.type=elasticsearch", |
| 54 | + "conductor.elasticsearch.version=7") |
| 55 | + .run(context -> assertFalse(context.containsBean("es7Marker"))); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void shouldNotActivateForLegacyVersionPropertyOnly() { |
| 60 | + contextRunner |
| 61 | + .withPropertyValues( |
| 62 | + "conductor.indexing.enabled=true", "conductor.elasticsearch.version=7") |
| 63 | + .run(context -> assertFalse(context.containsBean("es7Marker"))); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void shouldNotActivateForElasticsearch8Selector() { |
| 68 | + contextRunner |
| 69 | + .withPropertyValues( |
| 70 | + "conductor.indexing.enabled=true", "conductor.indexing.type=elasticsearch8") |
| 71 | + .run(context -> assertFalse(context.containsBean("es7Marker"))); |
| 72 | + } |
| 73 | + |
| 74 | + @Configuration(proxyBeanMethods = false) |
| 75 | + @Conditional(ElasticSearchConditions.ElasticSearchV7Enabled.class) |
| 76 | + static class ConditionalTestConfiguration { |
| 77 | + |
| 78 | + @Bean |
| 79 | + Marker es7Marker() { |
| 80 | + return new Marker(); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + static class Marker {} |
| 85 | +} |
0 commit comments