Author: henning
Date: Sun Nov 19 11:28:11 2006
New Revision: 476892

URL: http://svn.apache.org/viewvc?view=rev&rev=476892
Log:
Testcase for VELTOOLS-66 (Test driven development whoo hooo!) =:-) 

Added:
    
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java
   (with props)

Added: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java?view=auto&rev=476892
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java
 (added)
+++ 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java
 Sun Nov 19 11:28:11 2006
@@ -0,0 +1,144 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.    
+ */
+
+import java.lang.reflect.Method;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PrivilegedAction;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.runtime.RuntimeInstance;
+import org.apache.velocity.test.BaseTestCase;
+import org.apache.velocity.util.introspection.Introspector;
+
+/**
+ * Test Case for <a 
href="http://issues.apache.org/jira/browse/VELTOOLS-66";>Velocity Tools Issue 
66</a>.
+ */
+public class VelTools66TestCase
+        extends BaseTestCase
+{
+    public VelTools66TestCase(final String name)
+       throws Exception
+    {
+        super(name);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(VelTools66TestCase.class);
+    }
+
+    public void setUp()
+            throws Exception
+    {
+        Velocity.init();
+        System.setSecurityManager(new TestSecurityManager());
+        
+    }
+    
+    public void tearDown()
+    {
+       System.setSecurityManager(null);
+    }
+
+    public void testVelTools66()
+       throws Exception
+    {
+       Method verifyMethod = TestInterface.class.getMethod("getTestValue", new 
Class[0]);
+       
+       
+       RuntimeInstance ri = new RuntimeInstance();
+       Introspector introspector = ri.getIntrospector();
+       
+       Method testMethod = introspector.getMethod(TestObject.class, 
"getTestValue", new Object[0]);
+       assertNotNull(testMethod);
+       assertEquals("Method object does not match!", verifyMethod, testMethod);
+    }
+    
+    public static interface TestInterface
+    {
+       String getTestValue();
+       
+       void setTestValue(String testValue);
+    }
+    
+    public static final class TestObject
+       implements TestInterface
+    {
+       String testValue = null;
+       
+       public TestObject()
+       {
+       }
+       
+       public String getTestValue()
+       {
+           return testValue;
+       }
+       
+       public void setTestValue(final String testValue)
+       {
+           this.testValue = testValue;
+       }
+    }
+    
+    public static final class TestSecurityManager extends SecurityManager
+    {
+       public TestSecurityManager()
+       {
+           super();
+       }
+
+        public void checkMemberAccess(final Class c, final int i)
+        {
+            System.out.println("checkMemberAccess(" + c.getName() + ", " + i + 
")");
+            
+            if (c.equals(TestObject.class))
+            {
+               throw new AccessControlException("You are not allowed to access 
TestObject directly!");
+            }
+        }
+
+        public void checkRead(final String file)
+        {
+            System.out.println("checkRead(" + file + ")");
+        }
+        
+        public void checkPackageAccess(final String s)
+        {
+            System.out.println("checkPackageAccess(" + s + ")");
+        }
+
+        public void checkPropertyAccess(final String s)
+        {
+            System.out.println("checkPropertyAccess(" + s + ")");
+        }
+
+        public void checkPermission(final Permission p)
+        {
+            System.out.println("checkPermission(" + p + ")");
+        }
+    }
+}

Propchange: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/VelTools66TestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to