1 15 package org.apache.tapestry.services.impl; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.test.HiveMindTestCase; 19 20 26 public class TestExpressionCache extends HiveMindTestCase 27 { 28 public void testValidExpression() 29 { 30 ExpressionCacheImpl ec = new ExpressionCacheImpl(); 31 32 Object 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 c1 = ec.getCompiledExpression("foo + bar"); 42 Object c2 = ec.getCompiledExpression("zip.zap.zoom"); 43 Object 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 c1 = ec.getCompiledExpression("foo + bar"); 69 70 ec.resetEventDidOccur(); 71 72 Object c2 = ec.getCompiledExpression("foo + bar"); 73 74 assertNotSame(c1, c2); 75 } 76 77 } | Popular Tags |