Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions grails-test-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation platform(project(':grails-bom'))

api 'org.springframework:spring-tx'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra newline should be removed


api 'org.springframework.boot:spring-boot-test'
// Testing
Expand Down
3 changes: 2 additions & 1 deletion grails-testing-support-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ dependencies {

api project(':grails-databinding')
api project(':grails-datamapping-core')
api project(':grails-test-core')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-core is meant to be the parent to this dependency. Why are you removing it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored grails-test-core dependency in grails-testing-support-core

api project(':grails-core')
api('org.spockframework:spock-core') { transitive = false }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incudes by test-core so it should be unnecessary

api 'org.springframework.boot:spring-boot-test'
api('org.spockframework:spock-spring') { transitive = false }
api 'org.junit.jupiter:junit-jupiter-api'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class WithSessionSpecExtension implements IAnnotationDrivenExtension<WithSession

// Configure datasources from annotation
if (annotation.datasources().length > 0) {
// Create a mock test object with datasources property
def testWrapper = new Expando()
testWrapper.withSession = annotation.datasources() as List
sessionInterceptor.shouldBindSessions(testWrapper)
// Create a simple map with datasources list
def testConfig = [withSession: annotation.datasources() as List]
sessionInterceptor.shouldBindSessions(testConfig)
} else {
// Bind all datasources
sessionInterceptor.shouldBindSessions([withSession: true])
def testConfig = [withSession: true]
sessionInterceptor.shouldBindSessions(testConfig)
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ class GrailsTestSessionInterceptor {
datasourceNames << ConnectionSource.DEFAULT
}

for (name in applicationContext.grailsApplication.config.keySet()) {
if (name.startsWith('dataSource_')) {
datasourceNames << name - 'dataSource_'
// Check for additional datasources by looking for sessionFactory beans
String[] beanNames = applicationContext.getBeanNamesForType(SessionFactory)
for (String beanName : beanNames) {
if (beanName.startsWith('sessionFactory_')) {
String datasourceName = beanName.substring('sessionFactory_'.length())
datasourceNames << datasourceName
}
}

Expand Down Expand Up @@ -88,7 +91,13 @@ class GrailsTestSessionInterceptor {
}

// Check for property-based configuration
def value = test.hasProperty(WITH_SESSION) ? test[WITH_SESSION] : null
def value = null
if (test instanceof Map) {
value = test[WITH_SESSION]
} else if (test.metaClass.hasProperty(test, WITH_SESSION)) {
value = test[WITH_SESSION]
}

if (value instanceof Boolean && value) {
// Bind sessions for all datasources if withSession = true
datasourcesToBind.addAll(sessionFactories.keySet())
Expand Down Expand Up @@ -133,7 +142,7 @@ class GrailsTestSessionInterceptor {

Session session = sessionFactory.openSession()
// Set flush mode to MANUAL to match OISV behavior
session.hibernateFlushMode = FlushMode.MANUAL
session.flushMode = FlushMode.MANUAL

SessionHolder holder = new SessionHolder(session)
TransactionSynchronizationManager.bindResource(sessionFactory, holder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.grails.testing.context.junit4;

import grails.boot.test.GrailsApplicationContextLoader;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -29,7 +29,7 @@
* @author Graeme Rocher
* @since 3.0
*/
@ContextConfiguration(loader = GrailsApplicationContextLoader.class)
@ContextConfiguration(loader = SpringBootContextLoader.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we using the Grails Context?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay we should use the Grails-specific context loader since it provides Grails
application context setup rather than just generic Spring Boot context. The GrailsApplicationContextLoader
extends SpringBootContextLoader but adds Grails-specific initialization through GrailsApp.

@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.grails.testing.spock.TestingSupportExtension
org.grails.test.spock.WithSessionSpecExtension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Loading