Permalink
Browse files

Controller namespacing tests

  • Loading branch information...
1 parent 5f3c20d commit 8984feadf5b6f095c3ccf78d4317a84f5f73c992 @jeffbrown jeffbrown committed with jeffbrown Jul 31, 2012
View
@@ -1,7 +1,13 @@
+.settings
+.classpath
+.project
+bin
+target/
+*.swp
build/*
out/*
.gradle/*
*.iml
*.ipr
*.iws
-.DS_Store
+.DS_Store
@@ -27,6 +27,25 @@ class UrlMappings {
"/containsBean/$beanName"(controller: 'namespaceInspector', action: 'containsBean')
"/beanType/$beanName"(controller: 'namespaceInspector', action: 'beanType')
+ '/pluginOneFirstController' {
+ controller = 'first'
+ action = 'index'
+ plugin = 'namespaceOne'
+ }
+ '/pluginTwoFirstController' {
+ controller = 'first'
+ action = 'index'
+ plugin = 'namespaceTwo'
+ }
+ '/noPluginFirstController' {
+ controller = 'first'
+ action = 'index'
+ }
+ '/noPluginSecondController' {
+ controller = 'second'
+ action = 'index'
+ }
+
"/"(view:"/index")
"500"(view:'/error')
"404"(controller: 'i18nError', action: 'pageNotFound')
@@ -0,0 +1,9 @@
+package namespace
+
+class FirstController {
+
+ def index() {
+ render 'namespace.FirstController index action'
+ }
+}
+
@@ -21,4 +21,30 @@ class NamespaceInspectorController {
}
[tableNames: tableNames]
}
-}
+
+ def redirectToNoPlugin() {
+ redirect action: 'index', controller: 'first'
+ }
+
+ def redirectToPluginOne() {
+ redirect action: 'index', controller: 'first', plugin: 'namespaceOne'
+ }
+
+ def redirectToPluginTwo() {
+ redirect action: 'index', controller: 'first', plugin: 'namespaceTwo'
+ }
+
+ def chainToNoPlugin() {
+ chain controller: 'first', action: 'index'
+ }
+
+ def chainToPluginOne() {
+ chain controller: 'first', action: 'index', plugin: 'pluginOne'
+ }
+
+ def chainToPluginTwo() {
+ chain controller: 'first', action: 'index', plugin: 'pluginTwo'
+ }
+
+ def generateLinksToNamespacedControllers() {}
+}
@@ -0,0 +1,32 @@
+<html>
+<body>
+
+<p>
+<g:link plugin="namespaceTwo" action="index" controller="first">Link To FirstController In namespaceTwo</g:link> should be link to com.namespacetwo.FirstController
+</p>
+<p>
+<g:link plugin="namespaceOne" action="index" controller="first">Link To FirstController In namespaceOne</g:link> should be link to com.namespaceone.FirstController
+</p>
+<p>
+<g:link action="index" controller="first">Link To FirstController In Application</g:link> should be link to namespace.FirstController
+</p>
+<p>
+<g:link action="redirectToNoPlugin">Redirect To FirstController In Application</g:link> should redirect to namespace.FirstController
+</p>
+<p>
+<g:link action="redirectToPluginOne">Redirect To FirstController In namespaceOne</g:link> should redirect to com.namespaceone.FirstController
+</p>
+<p>
+<g:link action="redirectToPluginTwo">Redirect To FirstController In namespaceTwo</g:link> should redirect to com.namespacetwo.FirstController
+</p>
+<p>
+<g:link action="chainToNoPlugin">Chain To FirstController In Application</g:link> should chain to namespace.FirstController
+</p>
+<p>
+<g:link action="chainToPluginOne">Chain To FirstController In namespaceOne</g:link> should chain to com.namespaceone.FirstController
+</p>
+<p>
+<g:link action="chainToPluginTwo">Chain To FirstController In namespaceTwo</g:link> should chain to com.namespacetwo.FirstController
+</p>
+</body>
+</html>
@@ -0,0 +1,8 @@
+package com.namespaceone
+
+class FirstController {
+ def index() {
+ render 'com.namespaceone.FirstController index action'
+ }
+}
+
@@ -0,0 +1,8 @@
+package com.namespaceone
+
+class SecondController {
+ def index() {
+ render 'com.namespaceone.SecondController index action'
+ }
+}
+
@@ -0,0 +1,8 @@
+package com.namespacetwo
+
+class FirstController {
+ def index() {
+ render 'com.namespacetwo.FirstController index action'
+ }
+}
+
@@ -0,0 +1,161 @@
+package grails.functional.tests.web
+
+import grails.functional.tests.BaseApplicationSpec
+import spock.lang.Ignore
+
+class ControllerNamespacingSpec extends BaseApplicationSpec {
+
+ void 'Test link generation'() {
+ when:
+ go 'namespaceInspector/generateLinksToNamespacedControllers'
+
+ then:
+ statusCode == 200
+
+ when:
+ $('a', text:contains('Link To FirstController In namespaceTwo')).click()
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespacetwo.FirstController index action'))
+
+ when:
+ go 'namespaceInspector/generateLinksToNamespacedControllers'
+
+ then:
+ statusCode == 200
+
+ when:
+ $('a', text:contains('Link To FirstController In namespaceOne')).click()
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.FirstController index action'))
+
+ when:
+ go 'namespaceInspector/generateLinksToNamespacedControllers'
+
+ then:
+ statusCode == 200
+
+ when:
+ $('a', text:contains('Link To FirstController In Application')).click()
+
+ then:
+ statusCode == 200
+ $(text: contains('namespace.FirstController index action'))
+ }
+
+ void 'Test controller defined in app and multiple plugins'() {
+ when:
+ go 'first/index'
+
+ then:
+ statusCode == 200
+ $(text: contains('namespace.FirstController index action'))
+
+ when:
+ go 'first'
+
+ then:
+ statusCode == 200
+ $(text: contains('namespace.FirstController index action'))
+
+ when:
+ go 'noPluginFirstController'
+
+ then:
+ statusCode == 200
+ $(text: contains('namespace.FirstController index action'))
+
+ when:
+ go 'pluginOneFirstController'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.FirstController index action'))
+
+ when:
+ go 'pluginTwoFirstController'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespacetwo.FirstController index action'))
+ }
+
+ void 'Test controller defined only in a plugin'() {
+ when:
+ go 'second/index'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.SecondController index action'))
+
+ when:
+ go 'second'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.SecondController index action'))
+
+ when:
+ go 'noPluginSecondController'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.SecondController index action'))
+ }
+
+ void 'Test redirects'() {
+ when:
+ go 'namespaceInspector/redirectToNoPlugin'
+
+ then:
+ statusCode == 200
+ $(text: contains('namespace.FirstController index action'))
+
+ when:
+ go 'namespaceInspector/redirectToPluginOne'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.FirstController index action'))
+
+ when:
+ go 'namespaceInspector/redirectToPluginTwo'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespacetwo.FirstController index action'))
+ }
+
+ @Ignore
+ void 'Test chaining'() {
+ when:
+ go 'namespaceInspector/chainToNoPlugin'
+
+ then:
+ statusCode == 200
+ $(text: contains('namespace.FirstController index action'))
+
+ when:
+ go 'namespaceInspector/chainToPluginOne'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespaceone.FirstController index action'))
+
+ when:
+ go 'namespaceInspector/chainToPluginTwo'
+
+ then:
+ statusCode == 200
+ $(text: contains('com.namespacetwo.FirstController index action'))
+ }
+
+ @Override
+ public String getApplication() {
+ 'kitchen_sink_app'
+ }
+
+}

0 comments on commit 8984fea

Please sign in to comment.