001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest.transparency;
005:
006: import com.tc.exception.TCNonPortableObjectError;
007: import com.tc.object.config.ConfigLockLevel;
008: import com.tc.object.config.ConfigVisitor;
009: import com.tc.object.config.DSOClientConfigHelper;
010: import com.tc.object.config.Root;
011: import com.tc.simulator.app.ApplicationConfig;
012: import com.tc.simulator.listener.ListenerProvider;
013: import com.tctest.runner.AbstractTransparentApp;
014:
015: import java.util.HashMap;
016: import java.util.Map;
017:
018: public class InnerClassInstrumentationTestApp extends
019: AbstractTransparentApp {
020:
021: private static final String INSTRUMENTED_KEY = "instrumented";
022: private static final String NOT_INSTRUMENTED_KEY = "not instrumented";
023:
024: private final Map root = new HashMap();
025:
026: public InnerClassInstrumentationTestApp(String appId,
027: ApplicationConfig config, ListenerProvider listenerProvider) {
028: super (appId, config, listenerProvider);
029: }
030:
031: public static void visitL1DSOConfig(ConfigVisitor visitor,
032: DSOClientConfigHelper config) {
033: String testClassName = InnerClassInstrumentationTestApp.class
034: .getName();
035: config.addIncludePattern(testClassName);
036: config.addIncludePattern(MyInstrumentedInnerClass.class
037: .getName());
038:
039: config
040: .addIncludePattern(InnerInnerExtendsInstrumentedClass.class
041: .getName());
042: config
043: .addIncludePattern(InnerInnerExtendsInstrumentedClass.InnerInnerClass.class
044: .getName());
045: config
046: .addIncludePattern(InnerInnerExtendsInstrumentedClass.InnerInnerClass.InnerInnerInnerClass.class
047: .getName());
048:
049: config.addIncludePattern(MyNonInstrumentedInnerSubclass.class
050: .getName());
051:
052: config
053: .addIncludePattern(InnerInnerExtendsNonInstrumentedClass.class
054: .getName());
055: config
056: .addIncludePattern(InnerInnerExtendsNonInstrumentedClass.InnerInnerClass.class
057: .getName());
058: config
059: .addIncludePattern(InnerInnerExtendsNonInstrumentedClass.InnerInnerClass.InnerInnerInnerClass.class
060: .getName());
061:
062: config
063: .addIncludePattern(InnerInnerStaticExtendsInstrumentedClass.class
064: .getName());
065: config
066: .addIncludePattern(InnerInnerStaticExtendsInstrumentedClass.InnerInnerClass.class
067: .getName());
068:
069: config
070: .addIncludePattern(InnerInnerStaticExtendsNonInstrumentedClass.class
071: .getName());
072: config
073: .addIncludePattern(InnerInnerStaticExtendsNonInstrumentedClass.InnerInnerClass.class
074: .getName());
075:
076: config
077: .addIncludePattern(AnonymousInstrumentedInnerInnerClass.class
078: .getName());
079: config
080: .addIncludePattern(new AnonymousInstrumentedInnerInnerClass()
081: .getInnerInnerClassName());
082: config
083: .addIncludePattern(AnonymousNonInstrumentedInnerInnerClass.class
084: .getName());
085: config
086: .addIncludePattern(new AnonymousNonInstrumentedInnerInnerClass()
087: .getInnerInnerClassName());
088: config.addRoot(new Root(testClassName, "root", "root"), true);
089: config.addAutolock("* " + testClassName + ".*(..)",
090: ConfigLockLevel.WRITE);
091: }
092:
093: public void run() {
094: synchronized (root) {
095: root.put(INSTRUMENTED_KEY, new MyInstrumentedInnerClass());
096: try {
097: root.put(NOT_INSTRUMENTED_KEY,
098: new MyNonInstrumentedInnerClass());
099: throw new AssertionError(
100: "This should have thrown an exception!");
101: } catch (TCNonPortableObjectError t) {
102: // expected.
103: }
104: root.put(INSTRUMENTED_KEY,
105: new InnerInnerExtendsInstrumentedClass());
106: try {
107: root.put(NOT_INSTRUMENTED_KEY,
108: new MyNonInstrumentedInnerSubclass());
109: throw new AssertionError(
110: "This should have thrown an exception!");
111: } catch (TCNonPortableObjectError t) {
112: // expected.
113: }
114:
115: try {
116: root.put(NOT_INSTRUMENTED_KEY,
117: new InnerInnerExtendsNonInstrumentedClass());
118: throw new AssertionError(
119: "This should have thrown an exception!");
120: } catch (TCNonPortableObjectError t) {
121: // expected.
122: }
123:
124: root.put(INSTRUMENTED_KEY,
125: new InnerInnerStaticExtendsInstrumentedClass());
126:
127: try {
128: root
129: .put(
130: NOT_INSTRUMENTED_KEY,
131: new InnerInnerStaticExtendsNonInstrumentedClass());
132: throw new AssertionError(
133: "This should have thrown an exception!");
134: } catch (TCNonPortableObjectError t) {
135: // expected.
136: }
137:
138: root.put(INSTRUMENTED_KEY,
139: new AnonymousInstrumentedInnerInnerClass());
140:
141: try {
142: root.put(NOT_INSTRUMENTED_KEY,
143: new AnonymousNonInstrumentedInnerInnerClass());
144: throw new AssertionError(
145: "This should have thrown an exception!");
146: } catch (TCNonPortableObjectError t) {
147: // expected.
148: }
149: }
150: }
151:
152: private static class MyNonInstrumentedInnerClass {
153: //
154: }
155:
156: private static class MyInstrumentedInnerClass {
157: //
158: }
159:
160: private static final class InnerInnerExtendsInstrumentedClass {
161: private final InnerInnerClass inner = new InnerInnerClass();
162:
163: // This method is to remove eclipse warning.
164: public Object getInner() {
165: return inner;
166: }
167:
168: private class InnerInnerClass extends MyInstrumentedInnerClass {
169: private final InnerInnerInnerClass innerInner = new InnerInnerInnerClass();
170:
171: // This method is to remove eclipse warning.
172: public Object getInnerInner() {
173: return innerInner;
174: }
175:
176: private class InnerInnerInnerClass extends
177: MyInstrumentedInnerClass {
178: //
179: }
180: }
181: }
182:
183: private static final class InnerInnerStaticExtendsInstrumentedClass {
184: private final InnerInnerClass inner = new InnerInnerClass();
185:
186: // This method is to remove eclipse warning.
187: public Object getInner() {
188: return inner;
189: }
190:
191: private static class InnerInnerClass extends
192: MyInstrumentedInnerClass {
193: //
194: }
195: }
196:
197: private static final class MyNonInstrumentedInnerSubclass extends
198: MyNonInstrumentedInnerClass {
199: //
200: }
201:
202: private static final class InnerInnerExtendsNonInstrumentedClass {
203: private final InnerInnerClass inner = new InnerInnerClass();
204:
205: // This method is to remove eclipse warning.
206: public Object getInner() {
207: return inner;
208: }
209:
210: private class InnerInnerClass extends MyInstrumentedInnerClass {
211: private final InnerInnerInnerClass innerInner = new InnerInnerInnerClass();
212:
213: // This method is to remove eclipse warning.
214: public Object getInnerInner() {
215: return innerInner;
216: }
217:
218: private class InnerInnerInnerClass extends
219: MyNonInstrumentedInnerClass {
220: //
221: }
222: }
223: }
224:
225: private static final class InnerInnerStaticExtendsNonInstrumentedClass {
226: private final InnerInnerClass inner = new InnerInnerClass();
227:
228: // This method is to remove eclipse warning.
229: public Object getInner() {
230: return inner;
231: }
232:
233: private static class InnerInnerClass extends
234: MyNonInstrumentedInnerClass {
235: //
236: }
237: }
238:
239: private static final class AnonymousInstrumentedInnerInnerClass
240: extends MyInstrumentedInnerClass {
241: public String getInnerInnerClassName() {
242: return innerInner.getClass().getName();
243: }
244:
245: public final MyInstrumentedInnerClass innerInner = new MyInstrumentedInnerClass() {
246: //
247: };
248: }
249:
250: private static final class AnonymousNonInstrumentedInnerInnerClass
251: extends MyInstrumentedInnerClass {
252: public String getInnerInnerClassName() {
253: return innerInner.getClass().getName();
254: }
255:
256: public final MyNonInstrumentedInnerClass innerInner = new MyNonInstrumentedInnerClass() {
257: //
258: };
259: }
260: }
|