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:53:09 UTC
(grails-core) 28/40: test(h7): expand NamingStrategyProvider and DefaultColumnNameFetcher coverage to 100%
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 353b0640f9b8865f16297062d39c00305defb303
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Apr 8 00:11:17 2026 -0500
test(h7): expand NamingStrategyProvider and DefaultColumnNameFetcher coverage to 100%
NamingStrategyProvider (L40, L69):
- Add getPhysicalNamingStrategy(null) test → L40 (null/blank key → DEFAULT)
- Add getPhysicalNamingStrategy("") test → L40 (blank key → DEFAULT)
- Add configureNamingStrategy with HashMap.class → L69 fallback to
PhysicalNamingStrategySnakeCaseImpl when instance is not PhysicalNamingStrategy
DefaultColumnNameFetcher (L75-L78):
- Add DCFNOwner/DCFNKid/DCFNSubKid domain hierarchy where DCFNSubKid
inherits a true ManyToOne 'parent' property from DCFNKid
- Test getDefaultColumnName for inherited bidirectional ManyToOne uses
owner root entity class name prefix (L75-L78)
Co-authored-by: Copilot <22...@users.noreply.github.com>
---
.../DefaultColumnNameFetcherSpec.groovy | 36 ++++++++++++++++++++++
.../NamingStrategyProviderSpec.groovy | 35 +++++++++++++++++++++
2 files changed, 71 insertions(+)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
index 995c7e97a4..443778e606 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
@@ -84,6 +84,26 @@ class DefaultColumnNameFetcherSpec extends HibernateGormDatastoreSpec {
then:
columnName == 'name'
}
+ void "getDefaultColumnName for inherited true ManyToOne uses owner root entity prefix (L75-L78)"() {
+ given:
+ def namingStrategy = grailsDomainBinder.getNamingStrategy()
+ def backticksRemover = new BackticksRemover()
+ def fetcher = new DefaultColumnNameFetcher(namingStrategy, backticksRemover)
+
+ createPersistentEntity(DCFNOwner, grailsDomainBinder)
+ createPersistentEntity(DCFNKid, grailsDomainBinder)
+ def entity = createPersistentEntity(DCFNSubKid, grailsDomainBinder)
+
+ def property = entity.getPropertyByName("parent")
+
+ when:
+ def columnName = fetcher.getDefaultColumnName(property)
+
+ then:
+ // The inherited bidirectional ManyToOne path (L75-L78) prepends the owner root entity name
+ columnName.endsWith("_id")
+ !columnName.startsWith("parent") // must have entity prefix, not just "parent_id"
+ }
}
// --- Test Domain Classes ---
@@ -98,6 +118,22 @@ class SpecBaseEntity {
AssociatedEntity bidirectionalManyToOne
}
+@Entity
+class DCFNOwner {
+ static hasMany = [kids: DCFNKid]
+}
+
+@Entity
+class DCFNKid {
+ DCFNOwner parent
+ static belongsTo = [parent: DCFNOwner]
+}
+
+@Entity
+class DCFNSubKid extends DCFNKid {
+ String extra
+}
+
@Entity
class AManyToManyEntity {
String name
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/NamingStrategyProviderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/NamingStrategyProviderSpec.groovy
index 58635c7082..240977193a 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/NamingStrategyProviderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/NamingStrategyProviderSpec.groovy
@@ -107,6 +107,41 @@ class NamingStrategyProviderSpec extends HibernateGormDatastoreSpec {
then:
strategy instanceof MockPhysicalNamingStrategy
}
+
+ void "getPhysicalNamingStrategy with null name returns default strategy (L40)"() {
+ given:
+ def provider = new NamingStrategyProvider()
+
+ when:
+ def strategy = provider.getPhysicalNamingStrategy(null)
+
+ then:
+ strategy instanceof PhysicalNamingStrategySnakeCaseImpl
+ }
+
+ void "getPhysicalNamingStrategy with blank name returns default strategy (L40)"() {
+ given:
+ def provider = new NamingStrategyProvider()
+
+ when:
+ def strategy = provider.getPhysicalNamingStrategy(" ")
+
+ then:
+ strategy instanceof PhysicalNamingStrategySnakeCaseImpl
+ }
+
+ void "configureNamingStrategy with non-PhysicalNamingStrategy class falls back to snake_case (L69)"() {
+ given:
+ def provider = new NamingStrategyProvider()
+
+ when:
+ // HashMap is not a PhysicalNamingStrategy — triggers L69 fallback
+ provider.configureNamingStrategy("fallback", HashMap.class)
+ def strategy = provider.getPhysicalNamingStrategy("sessionFactory_fallback")
+
+ then:
+ strategy instanceof PhysicalNamingStrategySnakeCaseImpl
+ }
}
class MockPhysicalNamingStrategy implements PhysicalNamingStrategy {