jdaugherty commented on code in PR #15002:
URL: https://github.com/apache/grails-core/pull/15002#discussion_r2294199663


##########
grails-testing-support-core/src/main/groovy/org/grails/test/support/GrailsTestSessionInterceptor.groovy:
##########
@@ -0,0 +1,187 @@
+/*
+ *  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.test.support
+
+import grails.testing.mixin.integration.WithSession
+import org.grails.datastore.mapping.core.connections.ConnectionSource
+import org.hibernate.FlushMode
+import org.hibernate.Session
+import org.hibernate.SessionFactory
+import org.springframework.context.ApplicationContext
+import org.springframework.orm.hibernate5.SessionHolder
+import 
org.springframework.transaction.support.TransactionSynchronizationManager
+import groovy.transform.CompileStatic
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+/**
+ * Binds Hibernate sessions to the test thread without starting transactions.
+ * This mimics the OISV (Open Session In View) pattern used in running 
applications.
+ */
+@CompileStatic
+class GrailsTestSessionInterceptor {
+    
+    private static final Logger LOG = 
LoggerFactory.getLogger(GrailsTestSessionInterceptor)

Review Comment:
   This is a groovy class, is there a reason you can't use `@Slf4j` ?



##########
grails-test-core/src/main/groovy/org/grails/test/support/GrailsTestInterceptor.groovy:
##########
@@ -30,6 +30,7 @@ class GrailsTestInterceptor {
     private String[] testClassSuffixes
 
     private GrailsTestTransactionInterceptor transactionInterceptor
+    private GrailsTestSessionInterceptor sessionInterceptor

Review Comment:
   This is not compiling.



##########
grails-testing-support-core/src/main/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension:
##########
@@ -1 +1 @@
-org.grails.testing.spock.TestingSupportExtension
+org.grails.test.spock.WithSessionSpecExtension

Review Comment:
   What about the original extension?  Why are we replacing the old behavior 
instead of augmenting it? 



##########
grails-test-core/src/main/groovy/org/grails/test/spock/IntegrationSpecConfigurerExtension.groovy:
##########
@@ -60,7 +60,10 @@ class IntegrationSpecConfigurerExtension implements 
IAnnotationDrivenExtension<A
 
         IntegrationSpecMethodInterceptor(ApplicationContext 
applicationContext) {
             this.applicationContext = applicationContext
-            this.mode = new GrailsTestMode(autowire: true, wrapInTransaction: 
true, wrapInRequestEnvironment: true)
+            // By default, bind session for integration tests to match 
application behavior

Review Comment:
   The application behavior depends if OSIV is configured and if hibernate is 
used.  We should have our tests default to best behaviors, or even better, 
detect the configuration and then only apply it based on the application 
configuration.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@grails.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to