|
|
|
@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; |
|
|
|
import org.postgresql.xa.PGXADataSource; |
|
|
|
import org.postgresql.xa.PGXADataSource; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
|
|
|
|
|
|
import org.springframework.boot.jdbc.DatabaseDriver; |
|
|
|
import org.springframework.boot.jdbc.XADataSourceWrapper; |
|
|
|
import org.springframework.boot.jdbc.XADataSourceWrapper; |
|
|
|
import org.springframework.boot.test.context.FilteredClassLoader; |
|
|
|
import org.springframework.boot.test.context.FilteredClassLoader; |
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
|
|
@ -35,6 +36,7 @@ import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
import static org.mockito.BDDMockito.given; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -95,8 +97,16 @@ class XADataSourceAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void shouldUseConnectionDetailsIfAvailable() { |
|
|
|
void shouldUseConnectionDetailsIfAvailable() { |
|
|
|
|
|
|
|
JdbcConnectionDetails connectionDetails = mock(JdbcConnectionDetails.class); |
|
|
|
|
|
|
|
given(connectionDetails.getUsername()).willReturn("user-1"); |
|
|
|
|
|
|
|
given(connectionDetails.getPassword()).willReturn("password-1"); |
|
|
|
|
|
|
|
given(connectionDetails.getJdbcUrl()).willReturn("jdbc:postgresql://postgres.example.com:12345/database-1"); |
|
|
|
|
|
|
|
given(connectionDetails.getDriverClassName()).willReturn(DatabaseDriver.POSTGRESQL.getDriverClassName()); |
|
|
|
|
|
|
|
given(connectionDetails.getXaDataSourceClassName()) |
|
|
|
|
|
|
|
.willReturn(DatabaseDriver.POSTGRESQL.getXaDataSourceClassName()); |
|
|
|
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(XADataSourceAutoConfiguration.class)) |
|
|
|
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(XADataSourceAutoConfiguration.class)) |
|
|
|
.withUserConfiguration(FromProperties.class, JdbcConnectionDetailsConfiguration.class) |
|
|
|
.withUserConfiguration(FromProperties.class) |
|
|
|
|
|
|
|
.withBean(JdbcConnectionDetails.class, () -> connectionDetails) |
|
|
|
.run((context) -> { |
|
|
|
.run((context) -> { |
|
|
|
MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class); |
|
|
|
MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class); |
|
|
|
PGXADataSource dataSource = (PGXADataSource) wrapper.getXaDataSource(); |
|
|
|
PGXADataSource dataSource = (PGXADataSource) wrapper.getXaDataSource(); |
|
|
|
|