1 package org.apache.velocity.test.issues;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.lang.reflect.Method;
23 import java.security.AccessControlException;
24 import java.security.Permission;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.velocity.app.Velocity;
30 import org.apache.velocity.runtime.RuntimeInstance;
31 import org.apache.velocity.runtime.log.NullLogChute;
32 import org.apache.velocity.test.BaseTestCase;
33 import org.apache.velocity.util.introspection.Introspector;
34
35
36
37
38 public class VelTools66TestCase
39 extends BaseTestCase
40 {
41 public VelTools66TestCase(final String name)
42 throws Exception
43 {
44 super(name);
45 }
46
47 public static Test suite()
48 {
49 return new TestSuite(VelTools66TestCase.class);
50 }
51
52 public void setUp()
53 throws Exception
54 {
55 Velocity.setProperty(
56 Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());
57
58 Velocity.init();
59 System.setSecurityManager(new TestSecurityManager());
60
61 }
62
63 public void tearDown()
64 {
65 System.setSecurityManager(null);
66 }
67
68 public void testVelTools66()
69 throws Exception
70 {
71 Method verifyMethod = TestInterface.class.getMethod("getTestValue", new Class[0]);
72
73
74 RuntimeInstance ri = new RuntimeInstance();
75 Introspector introspector = ri.getIntrospector();
76
77 Method testMethod = introspector.getMethod(TestObject.class, "getTestValue", new Object[0]);
78 assertNotNull(testMethod);
79 assertEquals("Method object does not match!", verifyMethod, testMethod);
80 }
81
82 public static interface TestInterface
83 {
84 String getTestValue();
85
86 void setTestValue(String testValue);
87 }
88
89 public static final class TestObject
90 implements TestInterface
91 {
92 String testValue = null;
93
94 public TestObject()
95 {
96 }
97
98 public String getTestValue()
99 {
100 return testValue;
101 }
102
103 public void setTestValue(final String testValue)
104 {
105 this.testValue = testValue;
106 }
107 }
108
109 public static final class TestSecurityManager extends SecurityManager
110 {
111 private final Class clazz = TestObject.class;
112
113 public TestSecurityManager()
114 {
115 super();
116 }
117
118 public void checkMemberAccess(final Class c, final int i)
119 {
120 System.out.println("checkMemberAccess(" + c.getName() + ", " + i + ")");
121
122 if (c.equals(clazz))
123 {
124 throw new AccessControlException("You are not allowed to access TestObject directly!");
125 }
126 }
127
128 public void checkRead(final String file)
129 {
130 System.out.println("checkRead(" + file + ")");
131 }
132
133 public void checkPackageAccess(final String s)
134 {
135 System.out.println("checkPackageAccess(" + s + ")");
136 }
137
138 public void checkPropertyAccess(final String s)
139 {
140 System.out.println("checkPropertyAccess(" + s + ")");
141 }
142
143 public void checkPermission(final Permission p)
144 {
145 System.out.println("checkPermission(" + p + ")");
146 }
147 }
148 }