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.runtime.log.NullLogChute;
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.setProperty(
                Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());

        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
    {
        private final Class clazz = TestObject.class;

	public TestSecurityManager()
	{
	    super();
	}

        public void checkMemberAccess(final Class c, final int i)
        {
            System.out.println("checkMemberAccess(" + c.getName() + ", " + i + ")");
            
            if (c.equals(clazz))
            {
        	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 + ")");
        }
    }
}

@@ -1580,25 +1580,32 @@
 g name)%0A    
-%09
+        
 throws Excep
@@ -2058,17 +2058,24 @@
 )%0A    %7B%0A
-%09
+        
 System.s
@@ -2139,25 +2139,32 @@
 ols66()%0A    
-%09
+        
 throws Excep
@@ -2174,17 +2174,24 @@
 n%0A    %7B%0A
-%09
+        
 Method v
@@ -2269,13 +2269,34 @@
 %5D);%0A
-%09%0A%09%0A%09
+        %0A        %0A        
 Runt
@@ -2335,17 +2335,24 @@
 ance();%0A
-%09
+        
 Introspe
@@ -2393,19 +2393,33 @@
 ctor();%0A
-%09%0A%09
+        %0A        
 Method t
@@ -2503,17 +2503,24 @@
 ct%5B0%5D);%0A
-%09
+        
 assertNo
@@ -2538,17 +2538,24 @@
 ethod);%0A
-%09
+        
 assertEq
@@ -2674,25 +2674,32 @@
 rface%0A    %7B%0A
-%09
+        
 String getTe
@@ -2709,19 +2709,33 @@
 alue();%0A
-%09%0A%09
+        %0A        
 void set
@@ -2819,17 +2819,24 @@
 ect%0A    
-%09
+        
 implemen
@@ -2858,17 +2858,24 @@
 e%0A    %7B%0A
-%09
+        
 String t
@@ -2891,19 +2891,33 @@
 = null;%0A
-%09%0A%09
+        %0A        
 public T
@@ -2932,17 +2932,45 @@
 t()%0A
-%09%7B%0A%09%7D%0A%09%0A%09
+        %7B%0A        %7D%0A        %0A        
 publ
@@ -2994,20 +2994,34 @@
 Value()%0A
-%09%7B%0A%09
+        %7B%0A        
     retu
@@ -3038,14 +3038,35 @@
 ue;%0A
-%09%7D%0A%09%0A%09
+        %7D%0A        %0A        
 publ
@@ -3110,20 +3110,34 @@
 tValue)%0A
-%09%7B%0A%09
+        %7B%0A        
     this
@@ -3160,17 +3160,24 @@
 tValue;%0A
-%09
+        
 %7D%0A    %7D%0A
@@ -3316,17 +3316,24 @@
 class;%0A%0A
-%09
+        
 public T
@@ -3357,12 +3357,26 @@
 r()%0A
-%09%7B%0A%09
+        %7B%0A        
     
@@ -3384,17 +3384,24 @@
 uper();%0A
-%09
+        
 %7D%0A%0A     
@@ -3628,9 +3628,16 @@
     
-%09
+        
 thro

remove tabs, reformat code.