1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
/*******************************************************************************
* Copyright (c) 2005 IBM
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*
* Contributors:
* Andy Clement initial implementation
*******************************************************************************/
package org.aspectj.systemtest.ajc150;
import java.util.List;
import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.testing.XMLBasedAjcTestCase;
import junit.framework.Test;
public class DeclareAnnotationTests extends XMLBasedAjcTestCase {
public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(DeclareAnnotationTests.class);
}
protected java.net.URL getSpecFile() {
return getClassResource("ajc150.xml");
}
// parsing the various forms of declare @
public void testDeclareAnnotationParsing() {
runTest("basic declare annotation parse test");
}
// declare @type
// declare @type for one simple annotation on one specific type
public void testAtType_OneAnnotationHittingOneType_Src() {
runTest("declare @type 1");
}
// declare @type for one simple annotation to multiple types
public void testAtType_OneAnnotationHittingMultipleTypes_Src() {
runTest("declare @type 2");
}
// declare @type for one simple annotation and a pointcut that matches on it
public void testAtType_PointcutMatchingOnDeclaredAnnotation() {
runTest("declare @type - with matching pointcut");
}
// binary weaving declare @type, one annotation on one type
public void testAtType_OneAnnotationHittingOneType_Bin() {
runTest("declare @type - binary weaving");
}
// an annotation with multiple values (all the primitives and string)
// is declared upon a single type
public void testAtType_ComplexAnnotation_BinWeaving() {
runTest("declare @type - complex annotation - binary weaving");
}
public void testAtType_ComplexAnnotation_SrcWeaving() {
runTest("declare @type - complex annotation - source weaving");
}
// two annotations are declared on a type
public void testAtType_TwoAnnotationsOnOneType_BinWeaving() {
runTest("declare @type - two annotations hit one type - binary weaving");
}
public void testAtType_TwoAnnotationsOnOneType_SrcWeaving() {
runTest("declare @type - two annotations hit one type - source weaving");
}
// decp and deca can interact, let's try some variants that should
// result in the same thing
public void testAtType_InteractingWithDeclareParents1_BinWeaving() {
runTest("declare @type - declare parents interactions (order 1) - binary weaving");
}
public void testAtType_InteractingWithDeclareParents1_SrcWeaving() {
runTest("declare @type - declare parents interactions (order 1) - source weaving");
}
public void testAtType_InteractingWithDeclareParents2_BinWeaving() {
runTest("declare @type - declare parents interactions (order 2) - binary weaving");
}
public void testAtType_InteractingWithDeclareParents2_SrcWeaving() {
runTest("declare @type - declare parents interactions (order 2) - source weaving");
}
public void testAtType_InteractingWithDeclareParents3_BinWeaving() {
runTest("declare @type - declare parents interactions (order 3) - binary weaving");
}
public void testAtType_InteractingWithDeclareParents3_SrcWeaving() {
runTest("declare @type - declare parents interactions (order 3) - source weaving");
}
public void testAtType_InteractingWithDeclareParents4_BinWeaving() {
runTest("declare @type - declare parents interactions (order 4) - binary weaving");
}
public void testAtType_InteractingWithDeclareParents4_SrcWeaving() {
runTest("declare @type - declare parents interactions (order 4) - source weaving");
}
public void testAtType_AnnotatingAlreadyAnnotatedType_BinWeaving() {
runTest("declare @type - annotating an already annotated type - binary weaving");
}
public void testAtType_AnnotatingAlreadyAnnotatedType_SrcWeaving() {
runTest("declare @type - annotating an already annotated type - source weaving");
}
// testing for error messages when exact type patterns used
// public void testAtType_UsingWrongAnnotationOnAType_BinWeaving()
// runTest("declare @type - annotations with different targets - binary weaving");
// }
public void testAtType_UsingWrongAnnotationOnAType_SrcWeaving() {
runTest("declare @type - annotations with different targets - source weaving");
}
// testing for the lint message when non exact patterns used
// public void testAtType_UsingWrongAnnotationOnAType_TypeSpecifiedByPattern_BinWeaving() {
// runTest("declare @type - annotations with different targets (using type patterns) - binary weaving");
// }
public void testAtType_UsingWrongAnnotationOnAType_TypeSpecifiedByPattern_SrcWeaving() {
runTest("declare @type - annotations with different targets (using type patterns) - source weaving");
}
// testing how multiple decAtType/decps interact when they rely on each other
public void testAtType_ComplexDecpDecAtTypeInteractions_BinWeaving() {
runTest("declare @type - complex decp decAtType interactions - binary weaving");
}
public void testAtType_ComplexDecpDecAtTypeInteractions_SrcWeaving() {
runTest("declare @type - complex decp decAtType interactions - source weaving");
}
public void testAtType_PuttingIncorrectAnnosOnTypes_SrcWeaving() {
runTest("declare @type - trying to put annotation targetting annos on normal types - source weaving");
}
public void testAtType_PuttingIncorrectAnnosOnTypes_BinWeaving() {
runTest("declare @type - trying to put annotation targetting annos on normal types - binary weaving");
}
public void testAtType_PuttingIncorrectAnnosOnTypesWithPatterns_SrcWeaving() {
runTest("declare @type - trying to put annotation targetting annos on normal types (uses pattern) - source weaving");
}
public void testAtType_PuttingIncorrectAnnosOnTypesWithPatterns_BinWeaving() {
runTest("declare @type - trying to put annotation targetting annos on normal types (uses pattern) - binary weaving");
}
// I think this fails because of a freaky JDT compiler bug ...
// public void testAtType_UsingClassOrEnumElementValuesInAnnotations_SrcWeaving() {
// runTest("declare @type - covering enum and class element values - source weaving");
// }
public void testAtType_UsingClassOrEnumElementValuesInAnnotations_BinWeaving() {
runTest("declare @type - covering enum and class element values - binary weaving");
}
// ///////////////////////////////////////////////////////////////////////////////
// declare @field
public void testAtField_SimpleSource() {
runTest("declare @field - simple source weaving");
}
public void testAtField_SimpleBinary() {
runTest("declare @field - simple binary weaving");
}
// lint warning
public void testAtField_TwoTheSameOnOneSource() {
runTest("declare @field - two the same on one - source weaving");
}
// lint warning
public void testAtField_TwoTheSameOnOneBinary() {
runTest("declare @field - two the same on one - binary weaving");
}
public void testAtField_TwoDifferentOnOneSource() {
runTest("declare @field - two different on one - source weaving");
}
public void testAtField_TwoDifferentOnOneBinary() {
runTest("declare @field - two different on one - binary weaving");
}
public void testAtField_WrongTargetSource() {
runTest("declare @field - wrong target - source weaving");
}
// Can't do a test like this - as verification of the declare @ is
// done when the aspect is first compiled.
// public void testAtField_WrongTargetBinary() {
// runTest("declare @field - wrong target - binary weaving");
// }
public void testAtField_RightTargetSource() {
runTest("declare @field - right target - source weaving");
}
public void testAtField_RightTargetBinary() {
runTest("declare @field - right target - binary weaving");
}
public void testAtField_RecursiveSource() {
runTest("declare @field - recursive application - source weaving");
}
public void testAtField_RecursiveBinary() {
runTest("declare @field - recursive application - binary weaving");
}
public void testAtField_RecursiveOtherOrderSource() {
runTest("declare @field - recursive application (other order) - source weaving");
}
public void testAtField_RecursiveOtherOrderBinary() {
runTest("declare @field - recursive application (other order) - binary weaving");
}
// ///////////////////////////////////////////////////////////////////////////////
// declare @method
public void testAtMethod_SimpleSource() {
runTest("declare @method - simple source weaving");
}
public void testAtMethod_SimpleBinary() {
runTest("declare @method - simple binary weaving");
}
// ///////////////////////////////////////////////////////////////////////////////
// declare @constructor
public void testAtCtor_SimpleSource() {
runTest("declare @constructor - simple source weaving");
}
public void testAtCtor_SimpleBinary() {
runTest("declare @constructor - simple binary weaving");
}
// ///////////////////////////////////////////////////////////////////////////////
// declare @method @constructor
public void testAtMethodCtor_WrongTargetSource() {
runTest("declare @method @ctor - wrong target - source weaving");
}
public void testAtMethodCtor_RightTargetSource() {
runTest("declare @method @ctor - right target - source weaving");
}
public void testAtMethodCtor_RightTargetBinary() {
runTest("declare @method @ctor - right target - binary weaving");
}
// lint warning
public void testAtMethodCtor_TwoTheSameOnOneSource() {
runTest("declare @method @ctor - two the same on one - source weaving");
}
// lint warning
public void testAtMethodCtor_TwoTheSameOnOneBinary() {
runTest("declare @method @ctor - two the same on one - binary weaving");
}
public void testAtMethodCtor_TwoDifferentOnOneSource() {
runTest("declare @method @ctor - two different on one - source weaving");
}
public void testAtMethodCtor_TwoDifferentOnOneBinary() {
runTest("declare @method @ctor - two different on one - binary weaving");
}
// to debug this test, uncomment the first line which will give you a nice
// dump of the structure model in c:/debug.txt
public void testStructureModel() {
// AsmManager.setReporting("c:/debug.txt",true,true,true,true);
runTest("declare all annotations on one class - source weaving");
if (getCurrentTest().canRunOnThisVM()) {
IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
IProgramElement ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_TYPE,
"declare @type: p.q.DeathByAnnotations : @Colored(\"red\")");
assertTrue("Couldn't find 'declare @type' element in the tree", ipe != null);
List<IRelationship> l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l != null && l.size() > 0);
ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,
"declare @method: * m*(..) : @Fruit(\"tomato\")");
assertTrue("Couldn't find 'declare @method element in the tree", ipe != null);
l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l.size() > 0);
ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR,
"declare @constructor: p.q.DeathByAnnotations.new(..) : @Fruit(\"tomato\")");
assertTrue("Couldn't find 'declare @constructor element in the tree", ipe != null);
l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l.size() > 0);
ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD,
"declare @field: * p.q.DeathByAnnotations.* : @Material(\"wood\")");
assertTrue("Couldn't find 'declare @field element in the tree", ipe != null);
l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l.size() > 0);
}
}
public void testDeclareTypeMisspelled() {
runTest("declare @Type (should be @type)");
}
}
|