| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2012-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.jdbc;  | 
 | 18 | + | 
 | 19 | +import javax.sql.DataSource;  | 
 | 20 | + | 
 | 21 | +import org.junit.jupiter.api.Test;  | 
 | 22 | + | 
 | 23 | +import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer;  | 
 | 24 | +import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitialization;  | 
 | 25 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext;  | 
 | 26 | +import org.springframework.context.annotation.Bean;  | 
 | 27 | +import org.springframework.context.annotation.Configuration;  | 
 | 28 | +import org.springframework.context.annotation.Import;  | 
 | 29 | +import org.springframework.core.io.ResourceLoader;  | 
 | 30 | + | 
 | 31 | +import static org.assertj.core.api.Assertions.assertThat;  | 
 | 32 | + | 
 | 33 | +/**  | 
 | 34 | + * Tests for the configuration of dependencies on {@link AbstractDataSourceInitializer}  | 
 | 35 | + * beans.  | 
 | 36 | + *  | 
 | 37 | + * @author Andy Wilkinson  | 
 | 38 | + */  | 
 | 39 | +class AbstractDataSourceInitializerDependencyConfigurationTests {  | 
 | 40 | + | 
 | 41 | +	@Test  | 
 | 42 | +	void beanThatDependsOnDatabaseInitializationDependsOnAbstractDataSourceInitializerBeans() {  | 
 | 43 | +		try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(  | 
 | 44 | +				TestConfiguration.class)) {  | 
 | 45 | +			assertThat(context.getBeanFactory().getBeanDefinition("dependsOnDataSourceInitialization").getDependsOn())  | 
 | 46 | +					.contains("initializer");  | 
 | 47 | +		}  | 
 | 48 | +	}  | 
 | 49 | + | 
 | 50 | +	@Import(DatabaseInitializationDependencyConfigurer.class)  | 
 | 51 | +	@Configuration(proxyBeanMethods = false)  | 
 | 52 | +	static class TestConfiguration {  | 
 | 53 | + | 
 | 54 | +		@Bean  | 
 | 55 | +		DataSource dataSource() {  | 
 | 56 | +			return DataSourceBuilder.create().build();  | 
 | 57 | +		}  | 
 | 58 | + | 
 | 59 | +		@Bean  | 
 | 60 | +		@DependsOnDatabaseInitialization  | 
 | 61 | +		String dependsOnDataSourceInitialization() {  | 
 | 62 | +			return "test";  | 
 | 63 | +		}  | 
 | 64 | + | 
 | 65 | +		@Bean  | 
 | 66 | +		AbstractDataSourceInitializer initializer(DataSource dataSource, ResourceLoader resourceLoader) {  | 
 | 67 | +			return new AbstractDataSourceInitializer(dataSource, resourceLoader) {  | 
 | 68 | + | 
 | 69 | +				@Override  | 
 | 70 | +				protected String getSchemaLocation() {  | 
 | 71 | +					return null;  | 
 | 72 | +				}  | 
 | 73 | + | 
 | 74 | +				@Override  | 
 | 75 | +				protected DataSourceInitializationMode getMode() {  | 
 | 76 | +					return DataSourceInitializationMode.NEVER;  | 
 | 77 | +				}  | 
 | 78 | + | 
 | 79 | +			};  | 
 | 80 | +		}  | 
 | 81 | + | 
 | 82 | +	}  | 
 | 83 | + | 
 | 84 | +}  | 
0 commit comments