|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright (c) The original authors |
| 4 | + * |
| 5 | + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + */ |
| 7 | +package io.streamthoughts.jikkou.core.extension; |
| 8 | + |
| 9 | +import io.streamthoughts.jikkou.core.ReconciliationContext; |
| 10 | +import io.streamthoughts.jikkou.core.action.Action; |
| 11 | +import io.streamthoughts.jikkou.core.action.ExecutionResultSet; |
| 12 | +import io.streamthoughts.jikkou.core.annotation.Enabled; |
| 13 | +import io.streamthoughts.jikkou.core.config.Configuration; |
| 14 | +import io.streamthoughts.jikkou.core.converter.Converter; |
| 15 | +import io.streamthoughts.jikkou.core.health.Health; |
| 16 | +import io.streamthoughts.jikkou.core.health.HealthIndicator; |
| 17 | +import io.streamthoughts.jikkou.core.models.HasMetadata; |
| 18 | +import io.streamthoughts.jikkou.core.models.ResourceList; |
| 19 | +import io.streamthoughts.jikkou.core.models.ResourceType; |
| 20 | +import io.streamthoughts.jikkou.core.models.change.ResourceChange; |
| 21 | +import io.streamthoughts.jikkou.core.reconciler.ChangeExecutor; |
| 22 | +import io.streamthoughts.jikkou.core.reconciler.ChangeResult; |
| 23 | +import io.streamthoughts.jikkou.core.reconciler.Collector; |
| 24 | +import io.streamthoughts.jikkou.core.reconciler.Controller; |
| 25 | +import io.streamthoughts.jikkou.core.selector.Selector; |
| 26 | +import java.time.Duration; |
| 27 | +import java.util.Collection; |
| 28 | +import java.util.List; |
| 29 | +import org.jetbrains.annotations.NotNull; |
| 30 | +import org.junit.jupiter.api.Assertions; |
| 31 | +import org.junit.jupiter.api.Test; |
| 32 | + |
| 33 | +class EnabledAnnotationOnExtensionInterfacesTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + void shouldDetectEnabledOnActionInterface() { |
| 37 | + Assertions.assertTrue( |
| 38 | + DefaultExtensionDescriptorFactory.isEnabled(TestAction.class)); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void shouldDetectEnabledOnConverterInterface() { |
| 43 | + Assertions.assertTrue( |
| 44 | + DefaultExtensionDescriptorFactory.isEnabled(TestConverter.class)); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void shouldDetectEnabledOnControllerInterface() { |
| 49 | + Assertions.assertTrue( |
| 50 | + DefaultExtensionDescriptorFactory.isEnabled(TestController.class)); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void shouldDetectEnabledOnCollectorInterface() { |
| 55 | + Assertions.assertTrue( |
| 56 | + DefaultExtensionDescriptorFactory.isEnabled(TestCollector.class)); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void shouldDetectEnabledOnHealthIndicatorInterface() { |
| 61 | + Assertions.assertTrue( |
| 62 | + DefaultExtensionDescriptorFactory.isEnabled(TestHealthIndicator.class)); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + void shouldNotDetectEnabledWhenExtensionHasNoEnabledAnnotation() { |
| 67 | + Assertions.assertFalse( |
| 68 | + DefaultExtensionDescriptorFactory.isEnabled(PlainExtension.class)); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + void shouldHaveEnabledAnnotationOnActionInterface() { |
| 73 | + Assertions.assertTrue(Action.class.isAnnotationPresent(Enabled.class)); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void shouldHaveEnabledAnnotationOnConverterInterface() { |
| 78 | + Assertions.assertTrue(Converter.class.isAnnotationPresent(Enabled.class)); |
| 79 | + } |
| 80 | + |
| 81 | + // -- test stubs |
| 82 | + |
| 83 | + static class TestAction implements Action<HasMetadata> { |
| 84 | + @Override |
| 85 | + public boolean canAccept(@NotNull ResourceType type) { |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public @NotNull ExecutionResultSet<HasMetadata> execute(@NotNull Configuration configuration) { |
| 91 | + return null; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + static class TestConverter implements Converter<HasMetadata, HasMetadata> { |
| 96 | + @Override |
| 97 | + public boolean canAccept(@NotNull ResourceType type) { |
| 98 | + return false; |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public @NotNull List<HasMetadata> apply(@NotNull HasMetadata resource) { |
| 103 | + return List.of(); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + static class TestController implements Controller<HasMetadata> { |
| 108 | + @Override |
| 109 | + public boolean canAccept(@NotNull ResourceType type) { |
| 110 | + return false; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public List<ResourceChange> plan(@NotNull Collection<HasMetadata> resources, |
| 115 | + @NotNull ReconciliationContext context) { |
| 116 | + return List.of(); |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public List<ChangeResult> execute(@NotNull ChangeExecutor executor, |
| 121 | + @NotNull ReconciliationContext context) { |
| 122 | + return List.of(); |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + static class TestCollector implements Collector<HasMetadata> { |
| 127 | + @Override |
| 128 | + public boolean canAccept(@NotNull ResourceType type) { |
| 129 | + return false; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public ResourceList<HasMetadata> listAll(@NotNull Configuration configuration, |
| 134 | + @NotNull Selector selector) { |
| 135 | + return null; |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + static class TestHealthIndicator implements HealthIndicator { |
| 140 | + @Override |
| 141 | + public Health getHealth(Duration timeout) { |
| 142 | + return null; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + static class PlainExtension implements Extension { |
| 147 | + } |
| 148 | +} |
0 commit comments