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

(grails-core) 33/40: test(h7): expand MutationQueryDelegate and MultiTenantEventListener 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 ccf8e88a0f798832bc7bb8554555b71dfb0c58f8
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Apr 8 09:21:15 2026 -0500

    test(h7): expand MutationQueryDelegate and MultiTenantEventListener coverage
    
    Co-authored-by: Copilot <22...@users.noreply.github.com>
---
 .../MultiTenantEventListenerSpec.groovy            | 23 ++++++++++++++++++++++
 .../query/MutationQueryDelegateSpec.groovy         | 14 +++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/multitenancy/MultiTenantEventListenerSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/multitenancy/MultiTenantEventListenerSpec.groovy
index 314f22f1a0..730e121309 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/multitenancy/MultiTenantEventListenerSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/multitenancy/MultiTenantEventListenerSpec.groovy
@@ -248,5 +248,28 @@ class MultiTenantEventListenerSpec extends Specification {
         then:
         thrown(TenantException)
     }
+
+    void "onApplicationEvent PreInsertEvent reads tenantId from entity property when currentId is DEFAULT"() {
+        given: "resolver returns DEFAULT connection source id"
+        def resolver     = Mock(org.grails.datastore.mapping.multitenancy.TenantResolver) {
+            resolveTenantIdentifier() >> org.grails.datastore.mapping.core.connections.ConnectionSource.DEFAULT
+        }
+        def tenantId     = Mock(TenantId) { getName() >> "tenantId" }
+        def entity       = Mock(PersistentEntity) {
+            isMultiTenant() >> true
+            getTenantId()   >> tenantId
+        }
+        def entityAccess = Mock(org.grails.datastore.mapping.engine.EntityAccess) {
+            getProperty("tenantId") >> "entity_tenant"
+        }
+        def datastore    = Mock(HibernateDatastore) { getTenantResolver() >> resolver }
+        def event        = new PreInsertEvent(datastore, entity, entityAccess)
+
+        when:
+        listener.onApplicationEvent(event)
+
+        then:
+        1 * entityAccess.setProperty("tenantId", "entity_tenant")
+    }
 }
 
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/MutationQueryDelegateSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/MutationQueryDelegateSpec.groovy
index d2964dc5dd..ced49e7da3 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/MutationQueryDelegateSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/MutationQueryDelegateSpec.groovy
@@ -184,6 +184,20 @@ class MutationQueryDelegateSpec extends HibernateGormDatastoreSpec {
         ex.cause instanceof QueryArgumentException
     }
 
+    void "setParameterList with Object array directly delegates to mutationQuery setParameter"() {
+        given:
+        MutationQuery mq = buildMutationQuery(
+            "DELETE FROM MutationQueryDelegateTestBook WHERE title IN (:titles)"
+        )
+        MutationQueryDelegate delegate = new MutationQueryDelegate(mq)
+
+        when:
+        delegate.setParameterList("titles", ["Book One", "Book Two"] as Object[])
+
+        then:
+        thrown(org.hibernate.query.QueryArgumentException)
+    }
+
     void "list throws UnsupportedOperationException"() {
         given:
         MutationQuery mq = buildMutationQuery(