You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeclareAnnotationTests.java 12KB

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