|
| 1 | +/* |
| 2 | + * Copyright Java Operator SDK Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.javaoperatorsdk.operator.api.config; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +import io.fabric8.kubernetes.api.model.ConfigMap; |
| 21 | +import io.javaoperatorsdk.operator.api.reconciler.Context; |
| 22 | +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; |
| 23 | +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; |
| 24 | +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | + |
| 28 | +class BaseConfigurationServiceTest { |
| 29 | + |
| 30 | + private final BaseConfigurationService configurationService = new BaseConfigurationService(); |
| 31 | + |
| 32 | + @Test |
| 33 | + void readsTriggerReconcilerOnAllEvents() { |
| 34 | + assertThat( |
| 35 | + configurationService |
| 36 | + .configFor(new AllEventsReconciler()) |
| 37 | + .triggerReconcilerOnAllEvents()) |
| 38 | + .isTrue(); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void readsDeprecatedTriggerReconcilerOnAllEventAttribute() { |
| 43 | + assertThat( |
| 44 | + configurationService |
| 45 | + .configFor(new DeprecatedAllEventsReconciler()) |
| 46 | + .triggerReconcilerOnAllEvents()) |
| 47 | + .isTrue(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void triggerReconcilerOnAllEventsDefaultsToFalse() { |
| 52 | + assertThat( |
| 53 | + configurationService.configFor(new DefaultReconciler()).triggerReconcilerOnAllEvents()) |
| 54 | + .isFalse(); |
| 55 | + } |
| 56 | + |
| 57 | + @ControllerConfiguration(triggerReconcilerOnAllEvents = true) |
| 58 | + private static class AllEventsReconciler implements Reconciler<ConfigMap> { |
| 59 | + @Override |
| 60 | + public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) { |
| 61 | + return UpdateControl.noUpdate(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @SuppressWarnings("removal") |
| 66 | + @ControllerConfiguration(triggerReconcilerOnAllEvent = true) |
| 67 | + private static class DeprecatedAllEventsReconciler implements Reconciler<ConfigMap> { |
| 68 | + @Override |
| 69 | + public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) { |
| 70 | + return UpdateControl.noUpdate(); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + @ControllerConfiguration |
| 75 | + private static class DefaultReconciler implements Reconciler<ConfigMap> { |
| 76 | + @Override |
| 77 | + public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) { |
| 78 | + return UpdateControl.noUpdate(); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments