You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/04/09 14:52:47 UTC
(grails-core) 06/40: test(h7): expand HibernateConnectionSourceFactory coverage to 18 tests
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch 8.0.x-hibernate7-dev
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 473d3982cb89b3058371bdb76ee150283e993e7c
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Tue Apr 7 14:01:18 2026 -0500
test(h7): expand HibernateConnectionSourceFactory coverage to 18 tests
Added 11 new tests covering: getBytecodeProvider, setHibernateEventListeners,
setInterceptor, setDataSourceConnectionSourceFactory, getConnectionSourcesConfigurationKey,
setApplicationContext (stores context as both applicationContext and messageSource),
buildRuntimeSettings, buildSettings (isDefaultDataSource true and false branches),
buildConfiguration with naming strategy, buildConfiguration with interceptor applied.
Co-authored-by: Copilot <22...@users.noreply.github.com>
---
JACOCO_COVERAGE_VIOLATIONS.md | 2 +-
.../HibernateConnectionSourceFactorySpec.groovy | 151 +++++++++++++++++++++
2 files changed, 152 insertions(+), 1 deletion(-)
diff --git a/JACOCO_COVERAGE_VIOLATIONS.md b/JACOCO_COVERAGE_VIOLATIONS.md
index e34f4e6566..e67018d32b 100644
--- a/JACOCO_COVERAGE_VIOLATIONS.md
+++ b/JACOCO_COVERAGE_VIOLATIONS.md
@@ -19,7 +19,7 @@ Generated on: 2026-04-06 16:49:20
| org.grails.orm.hibernate.cfg.HibernateCompositeIdentity | 68.00% | X
| org.grails.orm.hibernate.HibernateDatastore | 68.53% | X |
| org.grails.orm.hibernate.cfg.CacheConfig.Usage | 69.70% | X
-| org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory | 69.84% |
+| org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory | 69.84% | X |
| org.grails.orm.hibernate.cfg.GrailsHibernateUtil | 71.03% | X
| org.grails.orm.hibernate.cfg.DiscriminatorConfig | 72.22% | X
| org.grails.orm.hibernate.GrailsHibernateTemplate | 72.43% | R
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceFactorySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceFactorySpec.groovy
index 4bd8abb21f..441dac73c4 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceFactorySpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceFactorySpec.groovy
@@ -23,9 +23,15 @@ import grails.gorm.specs.HibernateGormDatastoreSpec
import org.grails.datastore.mapping.core.DatastoreUtils
import org.grails.datastore.mapping.core.connections.ConnectionSource
import org.grails.datastore.mapping.core.exceptions.ConfigurationException
+import org.grails.orm.hibernate.HibernateEventListeners
import org.grails.orm.hibernate.cfg.HibernateMappingContext
+import org.grails.orm.hibernate.cfg.Settings
+import org.grails.orm.hibernate.proxy.GrailsBytecodeProvider
+import org.hibernate.Interceptor
+import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
import org.hibernate.cfg.Configuration
import org.hibernate.dialect.H2Dialect
+import org.springframework.context.ApplicationContext
import org.springframework.context.support.StaticMessageSource
/**
@@ -139,6 +145,151 @@ class HibernateConnectionSourceFactorySpec extends HibernateGormDatastoreSpec {
expect:
getMappingContext().getPersistentEntity(Foo.name) != null
}
+
+ void "getBytecodeProvider returns the provider passed to the constructor"() {
+ given:
+ def provider = new GrailsBytecodeProvider()
+ def factory = new HibernateConnectionSourceFactory(provider, Foo)
+
+ expect:
+ factory.getBytecodeProvider().is(provider)
+ }
+
+ void "setHibernateEventListeners stores the event listeners"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def listeners = new HibernateEventListeners()
+
+ when:
+ factory.setHibernateEventListeners(listeners)
+
+ then:
+ factory.@hibernateEventListeners.is(listeners)
+ }
+
+ void "setInterceptor stores the interceptor"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def interceptor = Mock(Interceptor)
+
+ when:
+ factory.setInterceptor(interceptor)
+
+ then:
+ factory.@interceptor.is(interceptor)
+ }
+
+ void "setDataSourceConnectionSourceFactory stores the factory"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def dscFactory = new org.grails.datastore.gorm.jdbc.connections.DataSourceConnectionSourceFactory()
+
+ when:
+ factory.setDataSourceConnectionSourceFactory(dscFactory)
+
+ then:
+ factory.@dataSourceConnectionSourceFactory.is(dscFactory)
+ }
+
+ void "getConnectionSourcesConfigurationKey returns SETTING_DATASOURCES"() {
+ expect:
+ new HibernateConnectionSourceFactory(Foo).getConnectionSourcesConfigurationKey() == Settings.SETTING_DATASOURCES
+ }
+
+ void "setApplicationContext stores the context and uses it as messageSource"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def ctx = Mock(ApplicationContext)
+
+ when:
+ factory.setApplicationContext(ctx)
+
+ then:
+ factory.@applicationContext.is(ctx)
+ factory.@messageSource.is(ctx)
+ }
+
+ void "buildRuntimeSettings builds HibernateConnectionSourceSettings from PropertyResolver"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def resolver = DatastoreUtils.createPropertyResolver(h2Config())
+
+ when:
+ def settings = factory.buildRuntimeSettings(ConnectionSource.DEFAULT, resolver, null)
+
+ then:
+ settings != null
+ settings instanceof HibernateConnectionSourceSettings
+ }
+
+ void "buildSettings for default datasource builds settings without prefix"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def resolver = DatastoreUtils.createPropertyResolver(h2Config())
+
+ when:
+ def settings = factory.buildSettings(ConnectionSource.DEFAULT, resolver, null, true)
+
+ then:
+ settings != null
+ settings instanceof HibernateConnectionSourceSettings
+ }
+
+ void "buildSettings for named datasource builds settings with datasource prefix"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def resolver = DatastoreUtils.createPropertyResolver(h2Config())
+
+ when:
+ def settings = factory.buildSettings('secondary', resolver, null, false)
+
+ then:
+ settings != null
+ settings instanceof HibernateConnectionSourceSettings
+ }
+
+ void "buildConfiguration with a naming strategy configures it on the configuration"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def settings = new HibernateConnectionSourceSettings()
+ settings.hibernate.naming_strategy = PhysicalNamingStrategyStandardImpl
+ def dsConfig = DatastoreUtils.createPropertyResolver([
+ 'dataSource.url' : "jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000",
+ 'dataSource.dbCreate' : 'update',
+ 'dataSource.dialect' : H2Dialect.name,
+ 'hibernate.hbm2ddl.auto' : 'create',
+ ])
+ def dsCs = new org.grails.datastore.gorm.jdbc.connections.DataSourceConnectionSourceFactory()
+ .create(ConnectionSource.DEFAULT, dsConfig)
+
+ when:
+ def config = factory.buildConfiguration(ConnectionSource.DEFAULT, dsCs, settings)
+
+ then:
+ config != null
+ }
+
+ void "buildConfiguration with an interceptor applies it to the configuration"() {
+ given:
+ def factory = new HibernateConnectionSourceFactory(Foo)
+ def interceptor = Mock(Interceptor)
+ factory.setInterceptor(interceptor)
+ def settings = new HibernateConnectionSourceSettings()
+ def dsConfig = DatastoreUtils.createPropertyResolver([
+ 'dataSource.url' : "jdbc:h2:mem:grailsDB;LOCK_TIMEOUT=10000",
+ 'dataSource.dbCreate' : 'update',
+ 'dataSource.dialect' : H2Dialect.name,
+ 'hibernate.hbm2ddl.auto' : 'create',
+ ])
+ def dsCs = new org.grails.datastore.gorm.jdbc.connections.DataSourceConnectionSourceFactory()
+ .create(ConnectionSource.DEFAULT, dsConfig)
+
+ when:
+ def config = factory.buildConfiguration(ConnectionSource.DEFAULT, dsCs, settings)
+
+ then:
+ config != null
+ }
}
@Entity