GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / web / mapping / IdUrlMappingTests.groovy
bloba75d018e996b8dfea4bc3542de1073cd838d5970
1 /**
2 * @author Graeme Rocher
3 * @since 1.0
4 *
5 * Created: Sep 20, 2007
6 */
7 package org.codehaus.groovy.grails.web.mapping
9 import org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerTests
10 import org.springframework.core.io.ByteArrayResource
12 class IdUrlMappingTests extends AbstractGrailsControllerTests{
14 def mappingScript = '''
15 mappings {
16 "/emailConfirmation/$id?" {
17 controller = "emailConfirmation"
18 action = "index"
20 "/$id?" {
21 controller = "content"
22 action = "index"
25 '''
27 void onSetUp() {
28 gcl.parseClass('''
29 class EmailConfirmationController {
30 def index = {
31 [result: "ID = " + params.id]
34 class ContentController {
35 def index = {}
37 ''')
39 void testIdInURL() {
40 def res = new ByteArrayResource(mappingScript.bytes)
42 def evaluator = new DefaultUrlMappingEvaluator()
43 def mappings = evaluator.evaluateMappings(res)
45 def holder = new DefaultUrlMappingsHolder(mappings)
46 assert webRequest
48 def infos = holder.matchAll("/emailConfirmation/foo")
49 assert infos
51 infos[0].configure(webRequest)
53 def c = ga.getControllerClass("EmailConfirmationController").newInstance()
55 assertEquals "foo",c.params.id
58 void testIdInParam() {
60 def res = new ByteArrayResource(mappingScript.bytes)
62 def evaluator = new DefaultUrlMappingEvaluator()
63 def mappings = evaluator.evaluateMappings(res)
65 def holder = new DefaultUrlMappingsHolder(mappings)
66 assert webRequest
68 request.addParameter("id", "foo")
69 def infos = holder.matchAll("/emailConfirmation")
70 assert infos
72 infos[0].configure(webRequest)
75 def c = ga.getControllerClass("EmailConfirmationController").newInstance()
77 assertEquals "foo",c.params.id
80 void testMappingWithUrlEncodedCharsInId() {
81 def res = new ByteArrayResource(mappingScript.bytes)
83 def evaluator = new DefaultUrlMappingEvaluator()
84 def mappings = evaluator.evaluateMappings(res)
86 def holder = new DefaultUrlMappingsHolder(mappings)
87 assert webRequest
89 def infos = holder.matchAll("/emailConfirmation/my%20foo")
90 assert infos
92 infos[0].configure(webRequest)
94 def c = ga.getControllerClass("EmailConfirmationController").newInstance()
96 assertEquals "my foo",c.params.id
98 infos = holder.matchAll("/emailConfirmation/my%2Ffoo")
99 assert infos
101 infos[0].configure(webRequest)
103 c = ga.getControllerClass("EmailConfirmationController").newInstance()
105 assertEquals "my/foo",c.params.id