Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test cases for grails/grails-core#11056 #13

Open
wants to merge 1 commit into
base: 3.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package functionaltests

import grails.util.Holders

import org.springframework.context.support.GenericApplicationContext
import org.springframework.context.support.GenericXmlApplicationContext
import org.springframework.core.io.Resource

class ContextLoaderService {

GenericApplicationContext loadContext(Resource appCtxResource) {
GenericApplicationContext context = new GenericXmlApplicationContext()
context.setParent(Holders.grailsApplication.mainContext)
context.load(appCtxResource)
context.refresh()
context
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package functionaltests

import grails.core.GrailsApplication
import grails.gorm.transactions.Rollback
import grails.test.mixin.integration.Integration
import grails.util.Holders
import groovy.util.logging.Slf4j

import org.example.MyBean
import org.springframework.context.support.GenericApplicationContext
import org.springframework.core.io.ClassPathResource
import spock.lang.Specification

@Integration
@Rollback
@Slf4j
class ContextLoadingSpec extends Specification {

ContextLoaderService contextLoaderService

void "test managing child app context"() {

given:
ClassPathResource myAppCtx = new ClassPathResource("AppCtx.xml")

when:
GrailsApplication application = Holders.getGrailsApplication()

then:
application != null

when:
GenericApplicationContext context = contextLoaderService.loadContext(myAppCtx)
MyBean bean = context.getBean("myBean", MyBean)

then:
bean != null
Holders.getGrailsApplication() == application

when:
context.close()

then:
Holders.getGrailsApplication() == application

}
}
9 changes: 9 additions & 0 deletions app1/src/integration-test/resources/AppCtx.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="myBean" class="org.example.MyBean"/>

</beans>