|
| 1 | +/* |
| 2 | + * Copyright 2012-present 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.autoconfigure.jdbc.metadata; |
| 18 | + |
| 19 | +import java.util.Optional; |
| 20 | + |
| 21 | +import com.zaxxer.hikari.HikariDataSource; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +import org.springframework.aot.hint.RuntimeHints; |
| 25 | +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; |
| 26 | +import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration.HikariDataSourcePoolMetadataRuntimeHints; |
| 27 | +import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration; |
| 28 | +import org.springframework.context.annotation.ImportRuntimeHints; |
| 29 | +import org.springframework.core.annotation.MergedAnnotations; |
| 30 | + |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
| 32 | + |
| 33 | +/** |
| 34 | + * Tests for {@link HikariDataSourcePoolMetadataRuntimeHints}. |
| 35 | + * |
| 36 | + * @author Andy Wilkinson |
| 37 | + */ |
| 38 | +class HikariDataSourcePoolMetadataRuntimeHintsTests { |
| 39 | + |
| 40 | + @Test |
| 41 | + @SuppressWarnings("rawtypes") |
| 42 | + void importsRegistrar() { |
| 43 | + Optional<Class[]> imported = MergedAnnotations.from(HikariPoolDataSourceMetadataProviderConfiguration.class) |
| 44 | + .get(ImportRuntimeHints.class) |
| 45 | + .getValue("value", Class[].class); |
| 46 | + assertThat(imported).hasValue(new Class[] { HikariDataSourcePoolMetadataRuntimeHints.class }); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void registersHints() { |
| 51 | + RuntimeHints runtimeHints = new RuntimeHints(); |
| 52 | + new HikariDataSourcePoolMetadataRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader()); |
| 53 | + assertThat(HikariDataSource.class).hasDeclaredFields("pool"); |
| 54 | + assertThat(RuntimeHintsPredicates.reflection().onField(HikariDataSource.class, "pool")).accepts(runtimeHints); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments