|
| 1 | +/* |
| 2 | + * Copyright 2019-2021 the original author or 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 | + * https://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 | + |
| 17 | +package org.springframework.boot.actuate.endpoint.annotation; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.springframework.aot.context.bootstrap.generator.infrastructure.nativex.NativeConfigurationRegistry; |
| 21 | +import org.springframework.aot.context.bootstrap.generator.infrastructure.nativex.NativeReflectionEntry; |
| 22 | +import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
| 23 | +import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
| 24 | +import org.springframework.boot.actuate.health.Health; |
| 25 | +import org.springframework.boot.actuate.health.HealthContributor; |
| 26 | +import org.springframework.boot.actuate.health.HealthIndicator; |
| 27 | +import org.springframework.nativex.hint.Flag; |
| 28 | + |
| 29 | +import java.util.List; |
| 30 | + |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
| 32 | + |
| 33 | +/** |
| 34 | + * Tests for {@link HealthIndicatorNativeConfigurationProcessor}. |
| 35 | + * |
| 36 | + * @author Olivier Boudet |
| 37 | + */ |
| 38 | +class HealthIndicatorNativeConfigurationProcessorTests { |
| 39 | + |
| 40 | + @Test |
| 41 | + void registerHealthIndicator() { |
| 42 | + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); |
| 43 | + beanFactory.registerBeanDefinition("noise", BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition()); |
| 44 | + beanFactory.registerBeanDefinition("healthIndicator", BeanDefinitionBuilder.rootBeanDefinition(TestHealthIndicator.class).getBeanDefinition()); |
| 45 | + NativeConfigurationRegistry registry = process(beanFactory); |
| 46 | + List<NativeReflectionEntry> entries = registry.reflection().getEntries(); |
| 47 | + assertThat(entries).anySatisfy((entry) -> { |
| 48 | + assertThat(entry.getType()).isEqualTo(TestHealthIndicator.class); |
| 49 | + assertThat(entry.getFlags()).contains(Flag.allDeclaredConstructors); |
| 50 | + }); |
| 51 | + assertThat(entries).hasSize(1); |
| 52 | + } |
| 53 | + |
| 54 | + private NativeConfigurationRegistry process(DefaultListableBeanFactory beanFactory) { |
| 55 | + NativeConfigurationRegistry registry = new NativeConfigurationRegistry(); |
| 56 | + new HealthIndicatorNativeConfigurationProcessor().process(beanFactory, registry); |
| 57 | + return registry; |
| 58 | + } |
| 59 | + |
| 60 | + @SuppressWarnings("unused") |
| 61 | + static class TestHealthIndicator implements HealthIndicator { |
| 62 | + |
| 63 | + @Override |
| 64 | + public Health health() { |
| 65 | + return Health.up().build(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments