|
| 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 | + |
| 21 | +import org.springframework.aot.context.bootstrap.generator.infrastructure.nativex.NativeConfigurationRegistry; |
| 22 | +import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
| 23 | +import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
| 24 | +import org.springframework.boot.actuate.health.HealthContributor; |
| 25 | +import org.springframework.boot.actuate.health.PingHealthIndicator; |
| 26 | +import org.springframework.nativex.hint.Flag; |
| 27 | + |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; |
| 29 | + |
| 30 | +/** |
| 31 | + * Tests for {@link HealthContributorNativeConfigurationProcessor}. |
| 32 | + * |
| 33 | + * @author Olivier Boudet |
| 34 | + */ |
| 35 | +class HealthContributorNativeConfigurationProcessorTests { |
| 36 | + |
| 37 | + @Test |
| 38 | + void registerHealthIndicator() { |
| 39 | + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); |
| 40 | + beanFactory.registerBeanDefinition("noise", BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition()); |
| 41 | + beanFactory.registerBeanDefinition("healthIndicator", BeanDefinitionBuilder.rootBeanDefinition(PingHealthIndicator.class).getBeanDefinition()); |
| 42 | + NativeConfigurationRegistry registry = process(beanFactory); |
| 43 | + assertThat(registry.reflection().getEntries()).singleElement().satisfies((entry) -> { |
| 44 | + assertThat(entry.getType()).isEqualTo(PingHealthIndicator.class); |
| 45 | + assertThat(entry.getFlags()).contains(Flag.allDeclaredConstructors); |
| 46 | + }); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void registerHealthContributor() { |
| 51 | + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); |
| 52 | + beanFactory.registerBeanDefinition("noise", BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition()); |
| 53 | + beanFactory.registerBeanDefinition("healthContributor", BeanDefinitionBuilder.rootBeanDefinition(HealthContributor.class).getBeanDefinition()); |
| 54 | + NativeConfigurationRegistry registry = process(beanFactory); |
| 55 | + assertThat(registry.reflection().getEntries()).singleElement().satisfies((entry) -> { |
| 56 | + assertThat(entry.getType()).isEqualTo(HealthContributor.class); |
| 57 | + assertThat(entry.getFlags()).contains(Flag.allDeclaredConstructors); |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + private NativeConfigurationRegistry process(DefaultListableBeanFactory beanFactory) { |
| 62 | + NativeConfigurationRegistry registry = new NativeConfigurationRegistry(); |
| 63 | + new HealthContributorNativeConfigurationProcessor().process(beanFactory, registry); |
| 64 | + return registry; |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments