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:12 UTC

(grails-core) 31/40: test(h7): expand MapSecondPassBinder and HibernateHqlQuery coverage

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 e11ad2dfcb283aa5d82a1b9e0890b83b5b1b6265
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Apr 8 08:56:29 2026 -0500

    test(h7): expand MapSecondPassBinder and HibernateHqlQuery coverage
    
    Co-authored-by: Copilot <22...@users.noreply.github.com>
---
 .../secondpass/MapSecondPassBinderSpec.groovy      | 40 +++++++++++++++++++++
 .../hibernate/query/HibernateHqlQuerySpec.groovy   | 42 ++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
index abbcc71c0c..cc49729bdc 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
@@ -20,6 +20,8 @@
 package org.grails.orm.hibernate.cfg.domainbinding.secondpass
 
 import grails.gorm.specs.HibernateGormDatastoreSpec
+import org.grails.orm.hibernate.cfg.ColumnConfig
+import org.grails.orm.hibernate.cfg.PropertyConfig
 import org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentEntity
 import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty
 
@@ -397,6 +399,44 @@ class MapSecondPassBinderSpec extends HibernateGormDatastoreSpec {
         expect:
         mapBinder.getSingleColumnConfig(propertyConfig) == column
     }
+
+    void "bindMapSecondPass applies column config when mappedForm has indexColumn"() {
+        given:
+        def binder = getGrailsDomainBinder()
+        def collector = getCollector()
+        def metadataBuildingContext = binder.getMetadataBuildingContext()
+        def binders = getBinders(binder)
+        def mapBinder = binders.collectionBinder.mapSecondPassBinder
+
+        def ownerEntity = getPersistentEntity(MapSPBOwner) as GrailsHibernatePersistentEntity
+        def attrsProp = ownerEntity.getPropertyByName("attributes") as HibernateToManyProperty
+
+        def rootClass = new RootClass(metadataBuildingContext)
+        rootClass.setEntityName(ownerEntity.name)
+        rootClass.setClassName(ownerEntity.name)
+        rootClass.setJpaEntityName(ownerEntity.name)
+        rootClass.setTable(collector.addTable(null, null, "MAPSPB_OWNER3", null, false, metadataBuildingContext))
+        collector.addEntityBinding(rootClass)
+
+        def map = new org.hibernate.mapping.Map(metadataBuildingContext, rootClass)
+        map.setRole("${ownerEntity.name}.attributes3".toString())
+        map.setCollectionTable(rootClass.getTable())
+        attrsProp.setCollection(map)
+
+        and: "inject an indexColumn config into the mapped form"
+        def indexPc = new PropertyConfig()
+        def colConfig = new ColumnConfig()
+        colConfig.name = "custom_idx_col"
+        indexPc.columns << colConfig
+        attrsProp.getHibernateMappedForm().indexColumn = indexPc
+
+        when:
+        mapBinder.bindMapSecondPass(attrsProp)
+
+        then:
+        noExceptionThrown()
+        map.index != null
+    }
 }
 
 @grails.gorm.annotation.Entity
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy
index c8814e8a77..75aa7a616e 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy
@@ -286,6 +286,48 @@ class HibernateHqlQuerySpec extends HibernateGormDatastoreSpec {
         noExceptionThrown()
         query.list().size() == 1
     }
+
+    void "populateQuerySettings accepts max as non-Integer (String) via ConversionService"() {
+        when:
+        def results = buildHqlQuery("from HibernateHqlQuerySpecBook", [:], null, [max: "2"]).list()
+        then:
+        results.size() == 2
+    }
+
+    void "getHibernateTemplate returns non-null HibernateTemplate"() {
+        expect:
+        buildHqlQuery("from HibernateHqlQuerySpecBook").getHibernateTemplate() != null
+    }
+
+    void "populateQuerySettings applies flushMode arg"() {
+        when:
+        buildHqlQuery("from HibernateHqlQuerySpecBook", [:], null, [flushMode: org.hibernate.FlushMode.COMMIT]).list()
+        then:
+        noExceptionThrown()
+    }
+
+    void "populateQuerySettings with lock:true applies pessimistic write lock mode"() {
+        when:
+        def results = buildHqlQuery("from HibernateHqlQuerySpecBook", [:], null, [lock: true]).list()
+        then:
+        noExceptionThrown()
+        results.size() == 3
+    }
+
+    void "populateQueryWithNamedArguments handles array value"() {
+        given:
+        def query = buildHqlQuery("from HibernateHqlQuerySpecBook b where b.title in (:titles)",
+                [titles: ["The Hobbit", "Fellowship"].toArray(new String[0])])
+        when:
+        def results = query.list()
+        then:
+        results.size() == 2
+    }
+
+    void "getQuery returns non-null for SELECT queries"() {
+        expect:
+        buildHqlQuery("from HibernateHqlQuerySpecBook").getQuery() != null
+    }
 }
 
 @Entity