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 52e55831a008702ed33335cb52a9e64159ce5c77
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Thu Mar 5 16:40:49 2026 -0600

    hibernate7: spec for HibernateDatastoreConnectionSourcesRegistrar
---
 ...eDatastoreConnectionSourcesRegistrarSpec.groovy | 76 ++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/support/HibernateDatastoreConnectionSourcesRegistrarSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/support/HibernateDatastoreConnectionSourcesRegistrarSpec.groovy
new file mode 100644
index 0000000000..d5e7debc1b
--- /dev/null
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/support/HibernateDatastoreConnectionSourcesRegistrarSpec.groovy
@@ -0,0 +1,76 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.orm.hibernate.support
+
+import grails.gorm.specs.HibernateGormDatastoreSpec
+import org.grails.datastore.gorm.bootstrap.support.InstanceFactoryBean
+import org.grails.datastore.mapping.config.Settings
+import org.grails.datastore.mapping.core.connections.ConnectionSource
+import org.hibernate.SessionFactory
+import org.springframework.beans.factory.support.DefaultListableBeanFactory
+import org.springframework.transaction.PlatformTransactionManager
+
+import javax.sql.DataSource
+
+class HibernateDatastoreConnectionSourcesRegistrarSpec extends 
HibernateGormDatastoreSpec {
+
+    def "test postProcessBeanDefinitionRegistry registers expected beans"() {
+        given:
+        def registry = new DefaultListableBeanFactory()
+        def dataSourceNames = [Settings.SETTING_DATASOURCE, 'readOnly']
+        def registrar = new 
HibernateDatastoreConnectionSourcesRegistrar(dataSourceNames)
+
+        when:
+        registrar.postProcessBeanDefinitionRegistry(registry)
+
+        then:
+        // Default dataSource bean
+        registry.containsBeanDefinition(Settings.SETTING_DATASOURCE)
+        def defaultDs = registry.getBeanDefinition(Settings.SETTING_DATASOURCE)
+        defaultDs.beanClass == InstanceFactoryBean
+        defaultDs.targetType == DataSource
+        defaultDs.constructorArgumentValues.genericArgumentValues[0].value == 
"#{dataSourceConnectionSourceFactory.create('dataSource', environment).source}"
+
+        // Secondary dataSource bean
+        
registry.containsBeanDefinition("${Settings.SETTING_DATASOURCE}_readOnly")
+        def readOnlyDs = 
registry.getBeanDefinition("${Settings.SETTING_DATASOURCE}_readOnly")
+        readOnlyDs.beanClass == InstanceFactoryBean
+        readOnlyDs.targetType == DataSource
+        readOnlyDs.constructorArgumentValues.genericArgumentValues[0].value == 
"#{dataSourceConnectionSourceFactory.create('readOnly', environment).source}"
+
+        // Secondary sessionFactory bean
+        registry.containsBeanDefinition("sessionFactory_readOnly")
+        def readOnlySf = registry.getBeanDefinition("sessionFactory_readOnly")
+        readOnlySf.beanClass == InstanceFactoryBean
+        readOnlySf.targetType == SessionFactory
+        readOnlySf.constructorArgumentValues.genericArgumentValues[0].value == 
"#{hibernateDatastore.getDatastoreForConnection('readOnly').sessionFactory}"
+
+        // Secondary transactionManager bean
+        registry.containsBeanDefinition("transactionManager_readOnly")
+        def readOnlyTm = 
registry.getBeanDefinition("transactionManager_readOnly")
+        readOnlyTm.beanClass == InstanceFactoryBean
+        readOnlyTm.targetType == PlatformTransactionManager
+        readOnlyTm.constructorArgumentValues.genericArgumentValues[0].value == 
"#{hibernateDatastore.getDatastoreForConnection('readOnly').transactionManager}"
+
+        // Default sessionFactory and transactionManager should NOT be 
registered by this registrar
+        // (they are usually registered elsewhere for the default connection)
+        !registry.containsBeanDefinition("sessionFactory_dataSource")
+        !registry.containsBeanDefinition("transactionManager_dataSource")
+    }
+}

Reply via email to