KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > TestExpressionCache


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

15 package org.apache.tapestry.services.impl;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.test.HiveMindTestCase;
19
20 /**
21  * Tests for {@link org.apache.tapestry.services.impl.ExpressionCacheImpl}.
22  *
23  * @author Howard M. Lewis Ship
24  * @since 4.0
25  */

26 public class TestExpressionCache extends HiveMindTestCase
27 {
28     public void testValidExpression()
29     {
30         ExpressionCacheImpl ec = new ExpressionCacheImpl();
31
32         Object JavaDoc compiled = ec.getCompiledExpression("foo ? bar : baz");
33
34         assertNotNull(compiled);
35     }
36
37     public void testCaching()
38     {
39         ExpressionCacheImpl ec = new ExpressionCacheImpl();
40
41         Object JavaDoc c1 = ec.getCompiledExpression("foo + bar");
42         Object JavaDoc c2 = ec.getCompiledExpression("zip.zap.zoom");
43         Object JavaDoc c3 = ec.getCompiledExpression("foo + bar");
44
45         assertSame(c1, c3);
46         assertNotSame(c1, c2);
47     }
48
49     public void testInvalidExpression()
50     {
51         ExpressionCacheImpl ec = new ExpressionCacheImpl();
52
53         try
54         {
55             ec.getCompiledExpression("foo and bar and");
56             unreachable();
57         }
58         catch (ApplicationRuntimeException ex)
59         {
60             assertExceptionSubstring(ex, "Unable to parse OGNL expression 'foo and bar and'");
61         }
62     }
63
64     public void testClearCache()
65     {
66         ExpressionCacheImpl ec = new ExpressionCacheImpl();
67
68         Object JavaDoc c1 = ec.getCompiledExpression("foo + bar");
69
70         ec.resetEventDidOccur();
71
72         Object JavaDoc c2 = ec.getCompiledExpression("foo + bar");
73
74         assertNotSame(c1, c2);
75     }
76
77 }
Popular Tags