|
|
@ -33,6 +33,7 @@ import javax.transaction.Transaction;
|
|
|
|
import javax.transaction.TransactionManager;
|
|
|
|
import javax.transaction.TransactionManager;
|
|
|
|
import javax.transaction.UserTransaction;
|
|
|
|
import javax.transaction.UserTransaction;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.zaxxer.hikari.HikariDataSource;
|
|
|
|
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
|
|
|
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +53,7 @@ import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -75,12 +77,12 @@ public class HibernateJpaAutoConfigurationTests
|
|
|
|
contextRunner().withPropertyValues("spring.datasource.data:classpath:/city.sql",
|
|
|
|
contextRunner().withPropertyValues("spring.datasource.data:classpath:/city.sql",
|
|
|
|
// Missing:
|
|
|
|
// Missing:
|
|
|
|
"spring.datasource.schema:classpath:/ddl.sql").run((context) -> {
|
|
|
|
"spring.datasource.schema:classpath:/ddl.sql").run((context) -> {
|
|
|
|
assertThat(context).hasFailed();
|
|
|
|
assertThat(context).hasFailed();
|
|
|
|
assertThat(context.getStartupFailure())
|
|
|
|
assertThat(context.getStartupFailure())
|
|
|
|
.hasMessageContaining("ddl.sql");
|
|
|
|
.hasMessageContaining("ddl.sql");
|
|
|
|
assertThat(context.getStartupFailure())
|
|
|
|
assertThat(context.getStartupFailure())
|
|
|
|
.hasMessageContaining("spring.datasource.schema");
|
|
|
|
.hasMessageContaining("spring.datasource.schema");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -105,7 +107,7 @@ public class HibernateJpaAutoConfigurationTests
|
|
|
|
"spring.datasource.data:classpath:/city.sql")
|
|
|
|
"spring.datasource.data:classpath:/city.sql")
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
context.getBean(TestInitializedJpaConfiguration.class).called)
|
|
|
|
context.getBean(TestInitializedJpaConfiguration.class).called)
|
|
|
|
.isTrue());
|
|
|
|
.isTrue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -164,7 +166,7 @@ public class HibernateJpaAutoConfigurationTests
|
|
|
|
.getJpaPropertyMap();
|
|
|
|
.getJpaPropertyMap();
|
|
|
|
assertThat((String) jpaPropertyMap
|
|
|
|
assertThat((String) jpaPropertyMap
|
|
|
|
.get("hibernate.transaction.jta.platform"))
|
|
|
|
.get("hibernate.transaction.jta.platform"))
|
|
|
|
.isEqualTo(TestJtaPlatform.class.getName());
|
|
|
|
.isEqualTo(TestJtaPlatform.class.getName());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -194,6 +196,62 @@ public class HibernateJpaAutoConfigurationTests
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void providerDisablesAutoCommitIsConfigured() {
|
|
|
|
|
|
|
|
contextRunner().withPropertyValues(
|
|
|
|
|
|
|
|
"spring.datasource.type:" + HikariDataSource.class.getName(),
|
|
|
|
|
|
|
|
"spring.datasource.hikari.auto-commit:false").run((context) -> {
|
|
|
|
|
|
|
|
Map<String, Object> jpaProperties = context
|
|
|
|
|
|
|
|
.getBean(LocalContainerEntityManagerFactoryBean.class)
|
|
|
|
|
|
|
|
.getJpaPropertyMap();
|
|
|
|
|
|
|
|
assertThat(jpaProperties).contains(entry(
|
|
|
|
|
|
|
|
"hibernate.connection.provider_disables_autocommit", "true"));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void providerDisablesAutoCommitIsNotConfiguredIfAutoCommitIsEnabled() {
|
|
|
|
|
|
|
|
contextRunner().withPropertyValues(
|
|
|
|
|
|
|
|
"spring.datasource.type:" + HikariDataSource.class.getName(),
|
|
|
|
|
|
|
|
"spring.datasource.hikari.auto-commit:true").run((context) -> {
|
|
|
|
|
|
|
|
Map<String, Object> jpaProperties = context
|
|
|
|
|
|
|
|
.getBean(LocalContainerEntityManagerFactoryBean.class)
|
|
|
|
|
|
|
|
.getJpaPropertyMap();
|
|
|
|
|
|
|
|
assertThat(jpaProperties).doesNotContainKeys(
|
|
|
|
|
|
|
|
"hibernate.connection.provider_disables_autocommit");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void providerDisablesAutoCommitIsNotConfiguredIfPropertyIsSet() {
|
|
|
|
|
|
|
|
contextRunner().withPropertyValues(
|
|
|
|
|
|
|
|
"spring.datasource.type:" + HikariDataSource.class.getName(),
|
|
|
|
|
|
|
|
"spring.datasource.hikari.auto-commit:false",
|
|
|
|
|
|
|
|
"spring.jpa.properties.hibernate.connection.provider_disables_autocommit=false"
|
|
|
|
|
|
|
|
).run((context) -> {
|
|
|
|
|
|
|
|
Map<String, Object> jpaProperties = context
|
|
|
|
|
|
|
|
.getBean(LocalContainerEntityManagerFactoryBean.class)
|
|
|
|
|
|
|
|
.getJpaPropertyMap();
|
|
|
|
|
|
|
|
assertThat(jpaProperties).contains(entry(
|
|
|
|
|
|
|
|
"hibernate.connection.provider_disables_autocommit", "false"));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void providerDisablesAutoCommitIsNotConfiguredWihJta() {
|
|
|
|
|
|
|
|
contextRunner()
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(JtaAutoConfiguration.class))
|
|
|
|
|
|
|
|
.withPropertyValues(
|
|
|
|
|
|
|
|
"spring.datasource.type:" + HikariDataSource.class.getName(),
|
|
|
|
|
|
|
|
"spring.datasource.hikari.auto-commit:false").run((context) -> {
|
|
|
|
|
|
|
|
Map<String, Object> jpaProperties = context
|
|
|
|
|
|
|
|
.getBean(LocalContainerEntityManagerFactoryBean.class)
|
|
|
|
|
|
|
|
.getJpaPropertyMap();
|
|
|
|
|
|
|
|
assertThat(jpaProperties).doesNotContainKeys(
|
|
|
|
|
|
|
|
"hibernate.connection.provider_disables_autocommit");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@TestAutoConfigurationPackage(City.class)
|
|
|
|
@TestAutoConfigurationPackage(City.class)
|
|
|
|
static class TestInitializedJpaConfiguration {
|
|
|
|
static class TestInitializedJpaConfiguration {
|
|
|
|