diff --git a/app1/grails-app/services/functionaltests/ContextLoaderService.groovy b/app1/grails-app/services/functionaltests/ContextLoaderService.groovy new file mode 100644 index 00000000..f8f00c04 --- /dev/null +++ b/app1/grails-app/services/functionaltests/ContextLoaderService.groovy @@ -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 + } +} diff --git a/app1/src/integration-test/groovy/functionaltests/ContextLoadingSpec.groovy b/app1/src/integration-test/groovy/functionaltests/ContextLoadingSpec.groovy new file mode 100644 index 00000000..3e459836 --- /dev/null +++ b/app1/src/integration-test/groovy/functionaltests/ContextLoadingSpec.groovy @@ -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 + + } +} diff --git a/app1/src/integration-test/resources/AppCtx.xml b/app1/src/integration-test/resources/AppCtx.xml new file mode 100644 index 00000000..ab42cdc7 --- /dev/null +++ b/app1/src/integration-test/resources/AppCtx.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file