KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > variables > PreparedVariableResolverTestCase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.treeprocessor.variables;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.cocoon.SitemapComponentTestCase;
23 import org.apache.cocoon.components.treeprocessor.InvokeContext;
24 import org.apache.cocoon.environment.mock.MockRequest;
25 import org.apache.cocoon.sitemap.PatternException;
26
27 /**
28  * Test case for the nested variant of the PreparedVariableResolver
29  *
30  * @author <a HREF="mailto:uv@upaya.co.uk">Upayavira</a>
31  * @version CVS $Id: PreparedVariableResolverTestCase.java 55454 2004-10-24 18:02:39Z cziegeler $
32  */

33 public class PreparedVariableResolverTestCase extends SitemapComponentTestCase {
34
35     public void testNestedExpressions() throws Exception JavaDoc {
36         String JavaDoc expr = "{request-param:{request-param:foo}}";
37         MockRequest request = getRequest();
38         request.reset();
39         request.addParameter("foo", "bar");
40         request.addParameter("bar", "123");
41         InvokeContext context = new InvokeContext(true);
42         context.enableLogging(getLogger());
43         
44         Map JavaDoc sitemapElements = new HashMap JavaDoc();
45         context.pushMap("sitemap", sitemapElements);
46         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
47         assertEquals("123", resolver.resolve(context, getObjectModel()));
48     }
49
50     public void testNestedModuleAndSitemapExpressions() throws Exception JavaDoc {
51         String JavaDoc expr = "{request-param:f{1}}";
52         MockRequest request = getRequest();
53         request.reset();
54         request.addParameter("foo", "123");
55         InvokeContext context = new InvokeContext(true);
56         context.enableLogging(getLogger());
57         
58         Map JavaDoc sitemapElements = new HashMap JavaDoc();
59         sitemapElements.put("1", "oo");
60         context.pushMap("sitemap", sitemapElements);
61         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
62         assertEquals("123", resolver.resolve(context, getObjectModel()));
63     }
64     
65     public void testAnchors() throws PatternException {
66         String JavaDoc expr = "{#label:name}";
67         
68         InvokeContext context = new InvokeContext(true);
69         context.enableLogging(getLogger());
70         
71         Map JavaDoc sitemapElements = new HashMap JavaDoc();
72         sitemapElements.put("name", "123");
73         context.pushMap("label", sitemapElements);
74         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
75         assertEquals("123", resolver.resolve(context, getObjectModel()));
76     }
77     
78     public void testSitemapVariables() throws PatternException {
79         String JavaDoc expr = "123{1}";
80         
81         InvokeContext context = new InvokeContext(true);
82         context.enableLogging(getLogger());
83
84         Map JavaDoc sitemapElements = new HashMap JavaDoc();
85         sitemapElements.put("1", "abc");
86         context.pushMap("label", sitemapElements);
87         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
88         assertEquals("123abc", resolver.resolve(context, getObjectModel()));
89     }
90
91     public void testSitemapVariablesWithText() throws PatternException {
92         String JavaDoc expr = "123{1}/def";
93     
94         InvokeContext context = new InvokeContext(true);
95         context.enableLogging(getLogger());
96
97         Map JavaDoc sitemapElements = new HashMap JavaDoc();
98         sitemapElements.put("1", "abc");
99         context.pushMap("label", sitemapElements);
100         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
101         assertEquals("123abc/def", resolver.resolve(context, getObjectModel()));
102     }
103     
104     public void testPrefixedSitemapVariable() throws PatternException {
105         String JavaDoc expr = "123{sitemap:1}/def";
106     
107         InvokeContext context = new InvokeContext(true);
108         context.enableLogging(getLogger());
109
110         Map JavaDoc sitemapElements = new HashMap JavaDoc();
111         sitemapElements.put("1", "abc");
112         context.pushMap("label", sitemapElements);
113         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
114         assertEquals("123abc/def", resolver.resolve(context, getObjectModel()));
115     }
116
117     public void testMultilevelSitemapVariables() throws PatternException {
118         String JavaDoc expr = "from {../1} to {1}";
119         
120         InvokeContext context = new InvokeContext(true);
121         context.enableLogging(getLogger());
122
123         Map JavaDoc sitemapElements;
124         sitemapElements = new HashMap JavaDoc();
125         sitemapElements.put("1", "juliet");
126         context.pushMap("label1", sitemapElements);
127         
128         sitemapElements = new HashMap JavaDoc();
129         sitemapElements.put("1", "oscar");
130         context.pushMap("label2", sitemapElements);
131
132         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
133         assertEquals("from juliet to oscar", resolver.resolve(context, getObjectModel()));
134     }
135
136     public void testRootSitemapVariables() throws PatternException {
137         String JavaDoc expr = "from {/1} to {1}";
138         
139         InvokeContext context = new InvokeContext(true);
140         context.enableLogging(getLogger());
141
142         Map JavaDoc sitemapElements;
143         sitemapElements = new HashMap JavaDoc();
144         sitemapElements.put("1", "juliet");
145         context.pushMap("label1", sitemapElements);
146         
147         sitemapElements = new HashMap JavaDoc();
148         sitemapElements.put("1", "oscar");
149         context.pushMap("label2", sitemapElements);
150
151         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
152         assertEquals("from juliet to oscar", resolver.resolve(context, getObjectModel()));
153     }
154     
155     public void testColonInTextContent() throws PatternException {
156         String JavaDoc expr = "http://cocoon.apache.org";
157         
158         InvokeContext context = new InvokeContext(true);
159         context.enableLogging(getLogger());
160
161         Map JavaDoc sitemapElements;
162         sitemapElements = new HashMap JavaDoc();
163         context.pushMap("label", sitemapElements);
164         
165         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
166         assertEquals("http://cocoon.apache.org", resolver.resolve(context, getObjectModel()));
167     }
168     
169     public void testColonBeginningTextContent() throws PatternException {
170         String JavaDoc expr = ":colon-starts-this";
171         
172         InvokeContext context = new InvokeContext(true);
173         context.enableLogging(getLogger());
174
175         Map JavaDoc sitemapElements;
176         sitemapElements = new HashMap JavaDoc();
177         context.pushMap("label", sitemapElements);
178         
179         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
180         assertEquals(":colon-starts-this", resolver.resolve(context, getObjectModel()));
181     }
182     
183     public void testEmbeddedColon() throws PatternException {
184         String JavaDoc expr = "{1}:{1}";
185         
186         InvokeContext context = new InvokeContext(true);
187         context.enableLogging(getLogger());
188
189         Map JavaDoc sitemapElements;
190         sitemapElements = new HashMap JavaDoc();
191         sitemapElements.put("1", "abc");
192         context.pushMap("label", sitemapElements);
193         
194         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
195         assertEquals("abc:abc", resolver.resolve(context, getObjectModel()));
196     }
197
198     public void testEscapedBraces() throws PatternException {
199         String JavaDoc expr = "This is a \\{brace\\}";
200         
201         InvokeContext context = new InvokeContext(true);
202         context.enableLogging(getLogger());
203
204         Map JavaDoc sitemapElements;
205         sitemapElements = new HashMap JavaDoc();
206         context.pushMap("label", sitemapElements);
207
208         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
209         assertEquals("This is a {brace}", resolver.resolve(context, getObjectModel()));
210     }
211
212     public void testModuleWithoutOption() throws PatternException {
213         String JavaDoc expr = "{baselink:}";
214         InvokeContext context = new InvokeContext(true);
215         context.enableLogging(getLogger());
216         
217         Map JavaDoc sitemapElements = new HashMap JavaDoc();
218         context.pushMap("sitemap", sitemapElements);
219         PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
220         assertEquals("", resolver.resolve(context, getObjectModel()));
221     }
222 }
223
Popular Tags