tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r495990 [2/2] - in /tapestry/tapestry4/branches/ognl-integration: ./ tapestry-examples/TimeTracker/ tapestry-examples/Workbench/src/context/ tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/ tapestry-examples/Workbench/src...
Date Sat, 13 Jan 2007 22:40:52 GMT
Modified: tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/binding/TestExpressionBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/binding/TestExpressionBinding.java?view=diff&rev=495990&r1=495989&r2=495990
==============================================================================
--- tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/binding/TestExpressionBinding.java
(original)
+++ tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/binding/TestExpressionBinding.java
Sat Jan 13 14:40:50 2007
@@ -17,6 +17,9 @@
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 
+import ognl.Node;
+import ognl.enhance.ExpressionAccessor;
+
 import org.apache.hivemind.Location;
 import org.apache.tapestry.BindingException;
 import org.apache.tapestry.IComponent;
@@ -35,24 +38,27 @@
 public class TestExpressionBinding extends BindingTestCase
 {
 
-    public void testInvariant()
+    public void test_Invariant()
     {   
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
         IComponent component = newMock(IComponent.class);
         Location l = fabricateLocation(1);
         
-        Object compiled = new Object();
+        Node compiled = newMock(Node.class);
+        ExpressionAccessor accessor = newMock(ExpressionAccessor.class);
         
         Object expressionValue = "EXPRESSION-VALUE";
         
         ValueConverter vc = newValueConverter();
         
-        expect(ec.getCompiledExpression("exp")).andReturn(compiled);
+        expect(ec.getCompiledExpression(component, "exp")).andReturn(compiled);
+        
+        expect(compiled.getAccessor()).andReturn(accessor);
         
-        expect(ev.isConstant("exp")).andReturn(true);
+        expect(ev.isConstant(component, "exp")).andReturn(true);
         
-        expect(ev.readCompiled(component, compiled)).andReturn(expressionValue);
+        expect(ev.readCompiled(component, accessor)).andReturn(expressionValue);
         
         expect(component.getExtendedId()).andReturn("Foo/bar.baz");
         
@@ -65,13 +71,13 @@
         
         // A second time, to test the 'already initialized'
         // code path.
-
+        
         assertEquals(true, b.isInvariant());
-
+        
         // Get the object, which should be cached.
 
         assertSame(expressionValue, b.getObject());
-
+        
         assertSame(component, b.getComponent());
 
         assertEquals("ExpressionBinding[Foo/bar.baz exp]", b.toString());
@@ -79,27 +85,30 @@
         verify();
     }
 
-    public void testVariant()
+    public void test_Variant()
     {
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
         Location l = fabricateLocation(1);
         
         IComponent component = newComponent();
-        Object compiled = new Object();
+        Node compiled = newMock(Node.class);
+        ExpressionAccessor accessor = newMock(ExpressionAccessor.class);
 
         Object expressionValue1 = new Object();
         Object expressionValue2 = new Object();
 
         ValueConverter vc = newValueConverter();
         
-        expect(ec.getCompiledExpression("exp")).andReturn(compiled);
-
-        expect(ev.isConstant("exp")).andReturn(false);
+        expect(ec.getCompiledExpression(component, "exp")).andReturn(compiled);
+        
+        expect(compiled.getAccessor()).andReturn(accessor);
+        
+        expect(ev.isConstant(component, "exp")).andReturn(false);
 
-        expect(ev.readCompiled(component, compiled)).andReturn(expressionValue1);
+        expect(ev.readCompiled(component, accessor)).andReturn(expressionValue1);
 
-        expect(ev.readCompiled(component, compiled)).andReturn(expressionValue2);
+        expect(ev.readCompiled(component, accessor)).andReturn(expressionValue2);
         
         replay();
         
@@ -118,24 +127,27 @@
         verify();
     }
 
-    public void testSetObject()
+    public void test_Set_Object()
     {
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
         Location l = fabricateLocation(1);
         
         IComponent component = newComponent();
-        Object compiled = new Object();
+        Node compiled = newMock(Node.class);
+        ExpressionAccessor accessor = newMock(ExpressionAccessor.class);
 
         ValueConverter vc = newValueConverter();
-
-        expect(ec.getCompiledExpression("exp")).andReturn(compiled);
-
-        expect(ev.isConstant("exp")).andReturn(false);
+        
+        expect(ec.getCompiledExpression(component, "exp")).andReturn(compiled);
+        
+        expect(compiled.getAccessor()).andReturn(accessor);
+        
+        expect(ev.isConstant(component, "exp")).andReturn(false);
 
         Object newValue = new Object();
 
-        ev.writeCompiled(component, compiled, newValue);
+        ev.writeCompiled(component, accessor, newValue);
 
         replay();
 
@@ -147,20 +159,23 @@
         verify();
     }
 
-    public void testSetObjectInvariant()
+    public void test_Set_Object_Invariant()
     {
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
         Location l = fabricateLocation(1);
         
         IComponent component = newComponent("Foo/bar.baz");
-        Object compiled = new Object();
+        Node compiled = newMock(Node.class);
+        ExpressionAccessor accessor = newMock(ExpressionAccessor.class);
         
         ValueConverter vc = newValueConverter();
 
-        expect(ec.getCompiledExpression("exp")).andReturn(compiled);
-
-        expect(ev.isConstant("exp")).andReturn(true);
+        expect(ec.getCompiledExpression(component, "exp")).andReturn(compiled);
+        
+        expect(compiled.getAccessor()).andReturn(accessor);
+        
+        expect(ev.isConstant(component, "exp")).andReturn(true);
 
         replay();
 
@@ -182,26 +197,29 @@
         verify();
     }
 
-    public void testSetObjectFailure()
+    public void test_Set_Object_Failure()
     {
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
         Location l = fabricateLocation(1);
         
         IComponent component = newComponent();
-        Object compiled = new Object();
+        Node compiled = newMock(Node.class);
+        ExpressionAccessor accessor = newMock(ExpressionAccessor.class);
 
         ValueConverter vc = newValueConverter();
 
-        expect(ec.getCompiledExpression("exp")).andReturn(compiled);
-
-        expect(ev.isConstant("exp")).andReturn(false);
+        expect(ec.getCompiledExpression(component, "exp")).andReturn(compiled);
+        
+        expect(compiled.getAccessor()).andReturn(accessor);
+        
+        expect(ev.isConstant(component, "exp")).andReturn(false);
 
         Object newValue = new Object();
 
         RuntimeException innerException = new RuntimeException("Failure");
 
-        ev.writeCompiled(component, compiled, newValue);
+        ev.writeCompiled(component, accessor, newValue);
         expectLastCall().andThrow(innerException);
 
         replay();
@@ -223,7 +241,7 @@
         verify();
     }
 
-    public void testCompileExpressionFailure()
+    public void test_Compile_Expression_Failure()
     {
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
@@ -234,7 +252,7 @@
 
         Throwable innerException = new RuntimeException("Failure");
 
-        expect(ec.getCompiledExpression("exp")).andThrow(innerException);
+        expect(ec.getCompiledExpression(component, "exp")).andThrow(innerException);
 
         replay();
 
@@ -255,24 +273,27 @@
         verify();
     }
 
-    public void testResolveExpressionFailure()
+    public void test_Resolve_Expression_Failure()
     {
         ExpressionEvaluator ev = newMock(ExpressionEvaluator.class);
         ExpressionCache ec = newMock(ExpressionCache.class);
         Location l = fabricateLocation(1);
         
         IComponent component = newComponent();
-        Object compiled = new Object();
+        Node compiled = newMock(Node.class);
+        ExpressionAccessor accessor = newMock(ExpressionAccessor.class);
 
         ValueConverter vc = newValueConverter();
 
-        expect(ec.getCompiledExpression("exp")).andReturn(compiled);
-
-        expect(ev.isConstant("exp")).andReturn(false);
+        expect(ec.getCompiledExpression(component, "exp")).andReturn(compiled);
+        
+        expect(compiled.getAccessor()).andReturn(accessor);
+        
+        expect(ev.isConstant(component, "exp")).andReturn(false);
 
         Throwable innerException = new RuntimeException("Failure");
 
-        ev.readCompiled(component, compiled);
+        ev.readCompiled(component, accessor);
         expectLastCall().andThrow(innerException);
 
         replay();

Added: tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/BasicObject.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/BasicObject.java?view=auto&rev=495990
==============================================================================
--- tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/BasicObject.java
(added)
+++ tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/BasicObject.java
Sat Jan 13 14:40:50 2007
@@ -0,0 +1,35 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry.services.impl;
+
+
+/**
+ * Basic class for testing ognl expression resolution.
+ */
+public class BasicObject
+{
+    private String _stringValue = "foo";
+    
+    public BasicObject(){}
+    
+    public String getValue()
+    {
+        return _stringValue;
+    }
+    
+    public void setValue(String value)
+    {
+        _stringValue = value;
+    }
+}

Modified: tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestExpressionCache.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestExpressionCache.java?view=diff&rev=495990&r1=495989&r2=495990
==============================================================================
--- tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestExpressionCache.java
(original)
+++ tapestry/tapestry4/branches/ognl-integration/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestExpressionCache.java
Sat Jan 13 14:40:50 2007
@@ -14,8 +14,13 @@
 
 package org.apache.tapestry.services.impl;
 
+import static org.easymock.EasyMock.expect;
+import ognl.Node;
+import ognl.OgnlContext;
+
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.services.ExpressionEvaluator;
 import org.testng.annotations.Test;
 
 /**
@@ -27,7 +32,7 @@
 @Test
 public class TestExpressionCache extends BaseComponentTestCase
 {
-    public void testValidExpression()
+    public void test_Valid_Expression()
     {
         ExpressionCacheImpl ec = new ExpressionCacheImpl();
 
@@ -36,10 +41,10 @@
         assertNotNull(compiled);
     }
 
-    public void testCaching()
+    public void test_Caching()
     {
         ExpressionCacheImpl ec = new ExpressionCacheImpl();
-
+        
         Object c1 = ec.getCompiledExpression("foo + bar");
         Object c2 = ec.getCompiledExpression("zip.zap.zoom");
         Object c3 = ec.getCompiledExpression("foo + bar");
@@ -48,7 +53,32 @@
         assertNotSame(c1, c2);
     }
 
-    public void testInvalidExpression()
+    public void test_Compiled_Caching()
+    {
+        ExpressionEvaluator evaluator = newMock(ExpressionEvaluator.class);
+        ExpressionCacheImpl ec = new ExpressionCacheImpl();
+        ec.setEvaluator(evaluator);
+        
+        BasicObject target = new BasicObject();
+        OgnlContext context = new OgnlContext();
+        
+        expect(evaluator.createContext(target)).andReturn(context);
+        
+        replay();
+        
+        Node e1 = (Node)ec.getCompiledExpression(target, "value");
+        
+        assertNotNull(e1.getAccessor());
+        assertEquals(e1.getAccessor().get(context, target), "foo");
+        
+        Node e2 = (Node)ec.getCompiledExpression(target, "value");
+        
+        assertSame(e1, e2);
+        
+        verify();
+    }
+    
+    public void test_Invalid_Expression()
     {
         ExpressionCacheImpl ec = new ExpressionCacheImpl();
 
@@ -62,18 +92,29 @@
             assertExceptionSubstring(ex, "Unable to parse OGNL expression 'foo and bar and'");
         }
     }
-
-    public void testClearCache()
+    
+    public void test_Clear_Cache()
     {
+        ExpressionEvaluator evaluator = newMock(ExpressionEvaluator.class);
         ExpressionCacheImpl ec = new ExpressionCacheImpl();
-
-        Object c1 = ec.getCompiledExpression("foo + bar");
-
+        ec.setEvaluator(evaluator);
+        
+        BasicObject target = new BasicObject();
+        OgnlContext context = new OgnlContext();
+        
+        expect(evaluator.createContext(target)).andReturn(context).anyTimes();
+        
+        replay();
+        
+        Node e1 = (Node)ec.getCompiledExpression(target, "value");
+        
         ec.resetEventDidOccur();
-
-        Object c2 = ec.getCompiledExpression("foo + bar");
-
-        assertNotSame(c1, c2);
+        
+        Node e2 = (Node)ec.getCompiledExpression(target, "value");
+        
+        assertNotSame(e1, e2);
+        
+        verify();
     }
 
-}
\ No newline at end of file
+}



Mime
View raw message