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.

CoverageTestCase.java 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. /* *******************************************************************
  2. * Copyright (c) 2003 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Mik Kersten initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.tools.ajdoc;
  13. import java.io.File;
  14. import java.util.List;
  15. import org.aspectj.util.LangUtil;
  16. import static org.aspectj.tools.ajdoc.HtmlDecorator.CLOSING_SPAN;
  17. import static org.aspectj.tools.ajdoc.HtmlDecorator.TYPE_NAME_LABEL;
  18. /**
  19. * A long way to go until full coverage, but this is the place to add more.
  20. *
  21. * @author Mik Kersten
  22. */
  23. public class CoverageTestCase extends AjdocTestCase {
  24. protected File file0,file1,aspect1,file2,file3,file4,file5,file6,file7,file8,file9,file10;
  25. protected void setUp() throws Exception {
  26. super.setUp();
  27. initialiseProject("coverage");
  28. createFiles();
  29. }
  30. public void testOptions() {
  31. String[] args = {
  32. "-private",
  33. "-encoding",
  34. "EUCJIS",
  35. "-docencoding",
  36. "EUCJIS",
  37. "-charset",
  38. "UTF-8",
  39. "-classpath",
  40. AjdocTests.ASPECTJRT_PATH.getPath(),
  41. "-d",
  42. getAbsolutePathOutdir(),
  43. file0.getAbsolutePath(),
  44. };
  45. org.aspectj.tools.ajdoc.Main.main(args);
  46. assertTrue(true);
  47. }
  48. /**
  49. * Test the "-public" argument
  50. */
  51. public void testCoveragePublicMode() throws Exception {
  52. File[] files = {file3,file9};
  53. runAjdoc("public","9",files);
  54. // have passed the "public" modifier as well as
  55. // one public and one package visible class. There
  56. // should only be ajdoc for the public class
  57. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/PkgVisibleClass.html");
  58. assertFalse("ajdoc for PkgVisibleClass shouldn't exist because passed" +
  59. " the 'public' flag to ajdoc",htmlFile.exists());
  60. htmlFile = new File(getAbsolutePathOutdir() + "/foo/PlainJava.html");
  61. if (!htmlFile.exists()) {
  62. fail("couldn't find " + htmlFile.getAbsolutePath()
  63. + " - were there compilation errors?");
  64. }
  65. // check there's no private fields within the file, that
  66. // the file contains the getI() method but doesn't contain
  67. // the private ClassBar, Bazz and Jazz classes.
  68. String[] strings = { "private", "getI()","ClassBar", "Bazz", "Jazz"};
  69. List<String> missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
  70. assertEquals("There should be 4 missing strings",4,missing.size());
  71. assertTrue(htmlFile.getName() + " should not contain the private modifier",missing.contains("private"));
  72. assertTrue(htmlFile.getName() + " should not contain the private ClassBar class",missing.contains("ClassBar"));
  73. assertTrue(htmlFile.getName() + " should not contain the private Bazz class",missing.contains("Bazz"));
  74. assertTrue(htmlFile.getName() + " should not contain the private Jazz class",missing.contains("Jazz"));
  75. }
  76. /**
  77. * Test that the ajdoc for an aspect has the title "Aspect"
  78. */
  79. public void testAJdocHasAspectTitle() throws Exception {
  80. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/A.aj")};
  81. runAjdoc("private",AJDocConstants.VERSION,files);
  82. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/A.html");
  83. if (!htmlFile.exists()) {
  84. fail("couldn't find " + htmlFile.getAbsolutePath()+ " - were there compilation errors?");
  85. }
  86. assertTrue(htmlFile.getAbsolutePath() + " should have Aspect A as it's title",
  87. AjdocOutputChecker.containsString(htmlFile,"Aspect A"));
  88. }
  89. /**
  90. * Test that the ajdoc for a class has the title "Class"
  91. */
  92. public void testAJdocHasClassTitle() throws Exception {
  93. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/C.java")};
  94. runAjdoc("private",AJDocConstants.VERSION,files);
  95. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/C.html");
  96. if (!htmlFile.exists()) {
  97. fail("couldn't find " + htmlFile.getAbsolutePath()+ " - were there compilation errors?");
  98. }
  99. assertTrue(htmlFile.getAbsolutePath() + " should have Class C as it's title",
  100. AjdocOutputChecker.containsString(htmlFile,"Class C"));
  101. }
  102. /**
  103. * Test that the ajdoc for an inner aspect is entitled "Aspect" rather
  104. * than "Class", but that the enclosing class is still "Class"
  105. */
  106. public void testInnerAspect() throws Exception {
  107. File[] files = { file1, file2 };
  108. runAjdoc("private", AJDocConstants.VERSION, files);
  109. // Get the HTML file for the inner aspect
  110. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.InnerAspect.html");
  111. if (!htmlFile.exists()) {
  112. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  113. }
  114. // Ensure that the file is entitled "Aspect ClassA.InnerAspect" rather than "Class ClassA.InnerAspect"
  115. String[] strings = new String[] {
  116. // These 2 should be missing because they reference "class", not "aspect"
  117. "Class ClassA.InnerAspect",
  118. "static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>",
  119. // These 2 should be present (i.e. 0 missing) after AJ doc creation
  120. "Aspect ClassA.InnerAspect",
  121. "static aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>"
  122. };
  123. List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile, strings);
  124. StringBuilder buf = new StringBuilder();
  125. buf.append("HTML file = ").append(htmlFile).append("\nMissing strings:\n");
  126. for (String str : missingStrings)
  127. buf.append(str).append("\n");
  128. assertEquals(
  129. "In " + htmlFile.getName() + " there should be 2 missing strings:\n" + buf,
  130. 2, missingStrings.size()
  131. );
  132. assertEquals(
  133. "In " + htmlFile.getName() + " no missing string should be aspect-related:\n" + buf,
  134. 0, missingStrings.stream().filter(s -> s.contains("static aspect")).count()
  135. );
  136. // Get the HTML file for the enclosing class
  137. htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.html");
  138. if (!htmlFile.exists()) {
  139. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  140. }
  141. // Ensure that the file is entitled "Class ClassA" and has not been changed to "Aspect ClassA"
  142. strings = new String[] {
  143. // These 3 should be missing because they reference "aspect", not "class"
  144. "Aspect ClassA</H2>",
  145. "Aspect ClassA</h2>",
  146. "public abstract aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>",
  147. // Of these 3, 2 should be present (i.e. 1 missing) after AJ doc creation
  148. "Class ClassA</h1>",
  149. "Class ClassA</h2>",
  150. "public abstract class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>"
  151. };
  152. missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile, strings);
  153. buf = new StringBuilder();
  154. buf.append("HTML file = ").append(htmlFile).append("\nMissing strings:\n");
  155. for (String str : missingStrings)
  156. buf.append(str).append("\n");
  157. assertEquals(
  158. "In " + htmlFile.getName() + " there should be 4 missing strings:\n" + buf,
  159. 4, missingStrings.size()
  160. );
  161. assertEquals(
  162. "In " + htmlFile.getName() + " 3 missing string should be aspect-related:\n" + buf,
  163. 3, missingStrings.stream().filter(s -> s.contains("abstract aspect") || s.contains("Aspect ClassA")).count()
  164. );
  165. }
  166. /**
  167. * Test that all the different types of advice appear
  168. * with the named pointcut in it's description
  169. */
  170. public void testAdviceNamingCoverage() throws Exception {
  171. File[] files = {file4};
  172. runAjdoc("private",AJDocConstants.VERSION,files);
  173. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdviceNamingCoverage.html");
  174. if (!htmlFile.exists()) {
  175. fail("couldn't find " + htmlFile.getAbsolutePath()
  176. + " - were there compilation errors?");
  177. }
  178. String[] strings = {
  179. "after(): named..",
  180. "afterReturning(int,int): namedWithArgs..",
  181. "afterThrowing(): named..",
  182. "before(): named..",
  183. "around(int): namedWithOneArg..",
  184. "before(int):",
  185. "before(int): named()..",
  186. "before():"};
  187. List<String> missing = AjdocOutputChecker.getMissingStringsInSection(
  188. htmlFile, strings,"ADVICE DETAIL SUMMARY");
  189. assertTrue(htmlFile.getName() + " should contain all advice in the Advice Detail section",missing.isEmpty());
  190. missing = AjdocOutputChecker.getMissingStringsInSection(
  191. htmlFile,strings,"ADVICE SUMMARY");
  192. assertTrue(htmlFile.getName() + " should contain all advice in the Advice Summary section",missing.isEmpty());
  193. }
  194. /**
  195. * Test that all the advises relationships appear in the
  196. * Advice Detail and Advice Summary sections and that
  197. * the links are correct
  198. */
  199. public void testAdvisesRelationshipCoverage() throws Exception {
  200. File[] files = {file4};
  201. runAjdoc("private",AJDocConstants.VERSION,files);
  202. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html");
  203. if (!htmlFile.exists()) {
  204. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  205. }
  206. String[] strings = {
  207. "before(): methodExecutionP..",
  208. "HREF=\"../foo/Point.html#setX(int)\"",
  209. "before(): constructorExecutionP..",
  210. "HREF=\"../foo/Point.html#Point()\"",
  211. "before(): callMethodP..",
  212. "HREF=\"../foo/Point.html#changeX(int)\"",
  213. "before(): callConstructorP..",
  214. "HREF=\"../foo/Point.html#doIt()\"",
  215. "before(): getP..",
  216. "HREF=\"../foo/Point.html#getX()\"",
  217. "before(): setP..",
  218. "HREF=\"../foo/Point.html\"><tt>foo.Point</tt></A>, <A HREF=\"../foo/Point.html#Point()\"><tt>foo.Point.Point</tt></A>, <A HREF=\"../foo/Point.html#setX(int)\"",
  219. "before(): initializationP..",
  220. "HREF=\"../foo/Point.html#Point()\"",
  221. "before(): staticinitializationP..",
  222. "HREF=\"../foo/Point.html\"",
  223. "before(): handlerP..",
  224. "HREF=\"../foo/Point.html#doIt()\""
  225. };
  226. for (int i = 0; i < strings.length - 1; i = i+2) {
  227. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  228. htmlFile,"ADVICE DETAIL SUMMARY",strings[i],
  229. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  230. strings[i+1]);
  231. assertTrue(strings[i] + " should advise " + strings[i+1] +
  232. " in the Advice Detail section", b);
  233. }
  234. for (int i = 0; i < strings.length - 1; i = i+2) {
  235. boolean b = AjdocOutputChecker.summarySectionContainsRel(
  236. htmlFile,"ADVICE SUMMARY",strings[i],
  237. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  238. strings[i+1]);
  239. assertTrue(strings[i] + " should advise " + strings[i+1] +
  240. " in the Advice Summary section", b);
  241. }
  242. }
  243. /**
  244. * Test that the advised by relationship appears in the ajdoc when the
  245. * advice is associated with a method execution pointcut
  246. */
  247. public void testAdvisedByMethodExecution() throws Exception {
  248. File[] files = {file4};
  249. runAjdoc("private",AJDocConstants.VERSION,files);
  250. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  251. if (!htmlFile.exists()) {
  252. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  253. }
  254. String[] strings = {
  255. toName("setX(int)"),
  256. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): methodExecutionP..\""};
  257. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  258. htmlFile,"=== METHOD DETAIL",
  259. strings[0],
  260. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  261. strings[1]);
  262. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  263. b = AjdocOutputChecker.summarySectionContainsRel(
  264. htmlFile,"=== METHOD SUMMARY",
  265. strings[0],
  266. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  267. strings[1]);
  268. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  269. }
  270. /**
  271. * Test that the advised by relationship appears in the ajdoc when the
  272. * advice is associated with a constructor execution pointcut
  273. */
  274. public void testAdvisedByConstructorExecution() throws Exception {
  275. File[] files = {file4};
  276. runAjdoc("private",AJDocConstants.VERSION,files);
  277. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  278. if (!htmlFile.exists()) {
  279. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  280. }
  281. String[] strings = {
  282. LangUtil.isVMGreaterOrEqual(11)?"&lt;init&gt;()":toName("Point()"),
  283. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): constructorExecutionP..\""};
  284. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  285. htmlFile,"=== CONSTRUCTOR DETAIL",
  286. strings[0],
  287. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  288. strings[1]);
  289. assertTrue("the Constructor Detail should have " + strings[0]+" advised by " + strings[1],b);
  290. // Pre-JDK 11:
  291. // This precedes the line containing strings[1]
  292. // <td class="colOne"><code><span class="memberNameLink"><a href="../foo/Point.html#Point--">Point</a></span>()</code>
  293. // On JDK 11:
  294. // This precedes the line containing strings[1]
  295. // <th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E()">Point</a></span>()</code></th>
  296. b = AjdocOutputChecker.summarySectionContainsRel(
  297. htmlFile,"=== CONSTRUCTOR SUMMARY",
  298. LangUtil.isVMGreaterOrEqual(11)?"#%3Cinit%3E()":toName("Point()"),
  299. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  300. strings[1]);
  301. assertTrue("the Constructor Summary should have " + strings[0]+" advised by " + strings[1],b);
  302. }
  303. /**
  304. * Test that the advised by relationship appears in the ajdoc when the
  305. * advice is associated with a method call pointcut
  306. */
  307. public void testAdvisedByMethodCall() throws Exception {
  308. File[] files = {file4};
  309. runAjdoc("private",AJDocConstants.VERSION,files);
  310. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  311. if (!htmlFile.exists()) {
  312. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  313. }
  314. String[] strings = {
  315. toName("changeX(int)"),
  316. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): callMethodP..\""};
  317. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  318. htmlFile,"=== METHOD DETAIL",
  319. strings[0],
  320. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  321. strings[1]);
  322. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  323. b = AjdocOutputChecker.summarySectionContainsRel(
  324. htmlFile,"=== METHOD SUMMARY",
  325. strings[0],
  326. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  327. strings[1]);
  328. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  329. }
  330. /**
  331. * Test that the advised by relationship appears in the ajdoc when the
  332. * advice is associated with a constructor call pointcut
  333. */
  334. public void testAdvisedByConstructorCall() throws Exception {
  335. File[] files = {file4};
  336. runAjdoc("private",AJDocConstants.VERSION,files);
  337. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  338. if (!htmlFile.exists()) {
  339. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  340. }
  341. String[] strings = {
  342. toName("doIt()"),
  343. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): callConstructorP..\""};
  344. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  345. htmlFile,"=== METHOD DETAIL",
  346. strings[0],
  347. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  348. strings[1]);
  349. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  350. b = AjdocOutputChecker.summarySectionContainsRel(
  351. htmlFile,"=== METHOD SUMMARY",
  352. strings[0],
  353. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  354. strings[1]);
  355. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  356. }
  357. /**
  358. * Test that the advised by relationship appears in the ajdoc when the
  359. * advice is associated with a get pointcut
  360. */
  361. public void testAdvisedByGet() throws Exception {
  362. File[] files = {file4};
  363. runAjdoc("private",AJDocConstants.VERSION,files);
  364. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  365. if (!htmlFile.exists()) {
  366. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  367. }
  368. String[] strings = {
  369. toName("getX()"),
  370. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): getP..\""};
  371. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  372. htmlFile,"=== METHOD DETAIL",
  373. strings[0],
  374. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  375. strings[1]);
  376. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  377. b = AjdocOutputChecker.summarySectionContainsRel(
  378. htmlFile,"=== METHOD SUMMARY",
  379. strings[0],
  380. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  381. strings[1]);
  382. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  383. }
  384. /**
  385. * Test that the advised by relationship appears in the ajdoc when the
  386. * advice is associated with a set pointcut
  387. */
  388. public void testAdvisedBySet() throws Exception {
  389. File[] files = {file4};
  390. runAjdoc("private",AJDocConstants.VERSION,files);
  391. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  392. if (!htmlFile.exists()) {
  393. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  394. }
  395. String href = "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): setP..\"";
  396. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  397. htmlFile,"=== METHOD DETAIL",
  398. toName("setX(int)"),
  399. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  400. href);
  401. assertTrue("the Method Detail should have setX(int) advised by " + href,b);
  402. b = AjdocOutputChecker.summarySectionContainsRel(
  403. htmlFile,"=== METHOD SUMMARY",
  404. toName("setX(int)"),
  405. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  406. href);
  407. assertTrue("the Method Summary should have setX(int) advised by " + href,b);
  408. b = AjdocOutputChecker.detailSectionContainsRel(
  409. htmlFile,"=== CONSTRUCTOR DETAIL",
  410. LangUtil.isVMGreaterOrEqual(11)?"&lt;init&gt;()":toName("Point()"),
  411. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  412. href);
  413. assertTrue("the Constructor Detail should have advised by " + href,b);
  414. b = AjdocOutputChecker.summarySectionContainsRel(
  415. htmlFile,"=== CONSTRUCTOR SUMMARY",
  416. LangUtil.isVMGreaterOrEqual(11)?"#%3Cinit%3E()":toName("Point()"),
  417. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  418. href);
  419. assertTrue("the Constructor Summary should have advised by " + href,b);
  420. b = AjdocOutputChecker.classDataSectionContainsRel(
  421. htmlFile,
  422. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  423. href);
  424. assertTrue("The class data section should have 'advised by " + href + "'",b);
  425. }
  426. /**
  427. * Test that the advised by relationship appears in the ajdoc when the
  428. * advice is associated with an initialization pointcut
  429. */
  430. public void testAdvisedByInitialization() throws Exception {
  431. File[] files = {file4};
  432. runAjdoc("private",AJDocConstants.VERSION,files);
  433. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  434. if (!htmlFile.exists()) {
  435. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  436. }
  437. String[] strings = {
  438. LangUtil.isVMGreaterOrEqual(11)?"&lt;init&gt;()":toName("Point()"),
  439. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): initializationP..\""};
  440. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  441. htmlFile,
  442. "=== CONSTRUCTOR DETAIL",
  443. strings[0],
  444. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  445. strings[1]);
  446. assertTrue("the Method Detail should have 'setX(int) advised by ... before()'",b);
  447. b = AjdocOutputChecker.summarySectionContainsRel(
  448. htmlFile,
  449. "=== CONSTRUCTOR SUMMARY",
  450. LangUtil.isVMGreaterOrEqual(11)?"#%3Cinit%3E()":strings[0],
  451. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  452. strings[1]);
  453. assertTrue("the Method Summary should have 'setX(int) advised by ... before()'",b);
  454. }
  455. /**
  456. * Test that the advised by relationship appears in the ajdoc when the
  457. * advice is associated with a staticinitialization pointcut
  458. */
  459. public void testAdvisedByStaticInitialization() throws Exception {
  460. File[] files = {file4};
  461. runAjdoc("private",AJDocConstants.VERSION,files);
  462. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  463. if (!htmlFile.exists()) {
  464. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  465. }
  466. String href = "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): staticinitializationP..\"";
  467. boolean b = AjdocOutputChecker.classDataSectionContainsRel(
  468. htmlFile,
  469. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  470. href);
  471. assertTrue("The class data section should have 'advised by " + href + "'",b);
  472. }
  473. /**
  474. * Test that the advised by relationship appears in the ajdoc when the
  475. * advice is associated with a handler pointcut
  476. */
  477. public void testAdvisedByHandler() throws Exception {
  478. File[] files = {file4};
  479. runAjdoc("private",AJDocConstants.VERSION,files);
  480. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  481. if (!htmlFile.exists()) {
  482. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  483. }
  484. String[] strings = {
  485. toName("doIt()"),
  486. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): handlerP..\""};
  487. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  488. htmlFile,"=== METHOD DETAIL",
  489. strings[0],
  490. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  491. strings[1]);
  492. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  493. b = AjdocOutputChecker.summarySectionContainsRel(
  494. htmlFile,"=== METHOD SUMMARY",
  495. strings[0],
  496. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  497. strings[1]);
  498. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  499. }
  500. private String toName(String name) {
  501. if (!LangUtil.isVMGreaterOrEqual(11)) {
  502. name = name.replace('(','-');
  503. name = name.replace(')','-');
  504. }
  505. return name;
  506. }
  507. /**
  508. * Test that if have two before advice blocks from the same
  509. * aspect affect the same method, then both appear in the ajdoc
  510. */
  511. public void testTwoBeforeAdvice() throws Exception {
  512. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/A2.aj")};
  513. runAjdoc("private",AJDocConstants.VERSION,files);
  514. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/C2.html");
  515. if (!htmlFile.exists()) {
  516. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  517. }
  518. String[] strings = {
  519. toName("amethod()"),
  520. "HREF=\"../pkg/A2.html#before(): p..\"",
  521. "HREF=\"../pkg/A2.html#before(): p2..\""};
  522. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  523. htmlFile,"=== METHOD DETAIL",
  524. strings[0],
  525. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  526. strings[1]);
  527. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  528. b = AjdocOutputChecker.summarySectionContainsRel(
  529. htmlFile,"=== METHOD SUMMARY",
  530. strings[0],
  531. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  532. strings[1]);
  533. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  534. b = AjdocOutputChecker.detailSectionContainsRel(
  535. htmlFile,"=== METHOD DETAIL",
  536. strings[0],
  537. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  538. strings[2]);
  539. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[2],b);
  540. b = AjdocOutputChecker.summarySectionContainsRel(
  541. htmlFile,"=== METHOD SUMMARY",
  542. strings[0],
  543. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  544. strings[2]);
  545. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[2],b);
  546. }
  547. /**
  548. * Test that there are no spurious "advised by" entries
  549. * against the aspect in the ajdoc
  550. */
  551. public void testNoSpuriousAdvisedByRels() throws Exception {
  552. File[] files = {file4};
  553. runAjdoc("private",AJDocConstants.VERSION,files);
  554. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html");
  555. if (!htmlFile.exists()) {
  556. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  557. }
  558. String href = "foo.Point.setX(int)";
  559. boolean b = AjdocOutputChecker.classDataSectionContainsRel(
  560. htmlFile,
  561. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  562. href);
  563. assertFalse("The class data section should not have 'advised by " + href + "'",b);
  564. }
  565. public void testCoverage() {
  566. File[] files = {aspect1,file0,file1,file2,file3,file4,file5,file6,
  567. file7,file8,file9,file10};
  568. runAjdoc("private","1.6",files);
  569. }
  570. /**
  571. * Test that nested aspects appear with "aspect" in their title
  572. * when the ajdoc file is written slightly differently (when it's
  573. * written for this apsect, it's different than for testInnerAspect())
  574. */
  575. public void testNestedAspect() throws Exception {
  576. File[] files = {file9};
  577. runAjdoc("private",AJDocConstants.VERSION,files);
  578. File htmlFile = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.NestedAspect.html");
  579. if (!htmlFile.exists()) {
  580. fail("couldn't find " + htmlFile.getAbsolutePath()
  581. + " - were there compilation errors?");
  582. }
  583. // ensure that the file is entitled "Aspect PkgVisibleClass.NestedAspect" rather
  584. // than "Class PkgVisibleClass.NestedAspect"
  585. String[] strings = null;
  586. strings = new String[] {
  587. "Aspect PkgVisibleClass.NestedAspect",
  588. "static aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>",
  589. "Class PkgVisibleClass.NestedAspect",
  590. "static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>"};
  591. List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
  592. StringBuilder buf = new StringBuilder();
  593. for (String str:missingStrings) {
  594. buf.append(str).append("\n");
  595. }
  596. buf.append("HTMLFILE=\n").append(htmlFile).append("\n");
  597. assertEquals("There should be 2 missing strings",2,missingStrings.size());
  598. assertTrue(htmlFile.getName() + " should not have Class as it's title",missingStrings.contains("Class PkgVisibleClass.NestedAspect"));
  599. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  600. missingStrings.contains("static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>"));
  601. // get the html file for the enclosing class
  602. File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html");
  603. if (!htmlFileClass.exists()) {
  604. fail("couldn't find " + htmlFileClass.getAbsolutePath()
  605. + " - were there compilation errors?");
  606. }
  607. // ensure that the file is entitled "Class PkgVisibleClass" and
  608. // has not been changed to "Aspect PkgVisibleClass"
  609. String[] classStrings = null;
  610. if (LangUtil.isVMGreaterOrEqual(13)) {
  611. classStrings = new String[] {
  612. "Class PkgVisibleClass</h1>",
  613. "class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>",
  614. "Aspect PkgVisibleClass</h2>",
  615. "aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"};
  616. } else {
  617. classStrings = new String[] {
  618. "Class PkgVisibleClass</h2>",
  619. "class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>",
  620. "Aspect PkgVisibleClass</h2>",
  621. "aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"};
  622. }
  623. List<String> classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings);
  624. assertEquals("There should be 2 missing strings",2,classMissing.size());
  625. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",
  626. classMissing.contains("Aspect PkgVisibleClass</h2>"));
  627. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  628. classMissing.contains("aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"));
  629. }
  630. /**
  631. * Test that in the case when you have a nested aspect whose
  632. * name is part of the enclosing class, for example a class called
  633. * ClassWithNestedAspect has nested aspect called NestedAspect,
  634. * that the titles for the ajdoc are correct.
  635. */
  636. public void testNestedAspectWithSimilarName() throws Exception {
  637. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")};
  638. runAjdoc("private",AJDocConstants.VERSION,files);
  639. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html");
  640. if (!htmlFile.exists()) {
  641. fail("couldn't find " + htmlFile.getAbsolutePath()
  642. + " - were there compilation errors?");
  643. }
  644. // ensure that the file is entitled "Aspect ClassWithNestedAspect.NestedAspect"
  645. // rather than "Class ClassWithNestedAspect.NestedAspect"
  646. String[] strings = null;
  647. strings = new String [] {
  648. "Aspect ClassWithNestedAspect.NestedAspect",
  649. "static aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>",
  650. "Class ClassWithNestedAspect.NestedAspect",
  651. "static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>"};
  652. List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
  653. StringBuilder buf = new StringBuilder();
  654. for (String str:missingStrings) {
  655. buf.append(str).append("\n");
  656. }
  657. buf.append("HTMLFILE=\n").append(htmlFile).append("\n");
  658. assertEquals("There should be 2 missing strings",2,missingStrings.size());
  659. assertTrue(htmlFile.getName() + " should not have Class as it's title",missingStrings.contains("Class ClassWithNestedAspect.NestedAspect"));
  660. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  661. missingStrings.contains("static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>"));
  662. // get the html file for the enclosing class
  663. File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html");
  664. if (htmlFileClass == null || !htmlFileClass.exists()) {
  665. fail("couldn't find " + htmlFileClass.getAbsolutePath()
  666. + " - were there compilation errors?");
  667. }
  668. // ensure that the file is entitled "Class ClassWithNestedAspect" and
  669. // has not been changed to "Aspect ClassWithNestedAspect"
  670. String[] classStrings = null;
  671. if (LangUtil.isVMGreaterOrEqual(13)) {
  672. classStrings = new String[] {
  673. "Class ClassWithNestedAspect</h1>",
  674. "public class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>",
  675. "Aspect ClassWithNestedAspect</h2>",
  676. "public aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"};
  677. } else {
  678. classStrings = new String[] {
  679. "Class ClassWithNestedAspect</h2>",
  680. "public class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>",
  681. "Aspect ClassWithNestedAspect</h2>",
  682. "public aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"};
  683. }
  684. List<String> classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings);
  685. assertEquals("There should be 2 missing strings",2,classMissing.size());
  686. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",
  687. classMissing.contains("Aspect ClassWithNestedAspect</h2>"));
  688. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  689. classMissing.contains("public aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"));
  690. }
  691. /**
  692. * Test that everythings being decorated correctly within the ajdoc
  693. * for the aspect when the aspect is a nested aspect
  694. */
  695. public void testAdviceInNestedAspect() throws Exception {
  696. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")};
  697. runAjdoc("private",AJDocConstants.VERSION,files);
  698. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html");
  699. if (!htmlFile.exists()) {
  700. fail("couldn't find " + htmlFile.getAbsolutePath()
  701. + " - were there compilation errors?");
  702. }
  703. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  704. htmlFile,"ADVICE DETAIL SUMMARY",
  705. "before(): p..",
  706. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  707. "HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"");
  708. assertTrue("Should have 'before(): p.. advises HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"" +
  709. "' in the Advice Detail section", b);
  710. b = AjdocOutputChecker.summarySectionContainsRel(
  711. htmlFile,"ADVICE SUMMARY",
  712. "before(): p..",
  713. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  714. "HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"");
  715. assertTrue("Should have 'before(): p.. advises HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"" +
  716. "' in the Advice Summary section", b);
  717. }
  718. /**
  719. * Test that everythings being decorated correctly within the ajdoc
  720. * for the advised class when the aspect is a nested aspect
  721. */
  722. public void testAdvisedByInNestedAspect() throws Exception {
  723. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")};
  724. runAjdoc("private",AJDocConstants.VERSION,files);
  725. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html");
  726. if (!htmlFile.exists()) {
  727. fail("couldn't find " + htmlFile.getAbsolutePath()
  728. + " - were there compilation errors?");
  729. }
  730. boolean b = AjdocOutputChecker.containsString(htmlFile,"POINTCUT SUMMARY ");
  731. assertFalse(htmlFile.getName() + " should not contain a pointcut summary section",b);
  732. b = AjdocOutputChecker.containsString(htmlFile,"ADVICE SUMMARY ");
  733. assertFalse(htmlFile.getName() + " should not contain an adivce summary section",b);
  734. b = AjdocOutputChecker.containsString(htmlFile,"POINTCUT DETAIL ");
  735. assertFalse(htmlFile.getName() + " should not contain a pointcut detail section",b);
  736. b = AjdocOutputChecker.containsString(htmlFile,"ADVICE DETAIL ");
  737. assertFalse(htmlFile.getName() + " should not contain an advice detail section",b);
  738. b = AjdocOutputChecker.detailSectionContainsRel(
  739. htmlFile,"=== METHOD DETAIL",
  740. toName("amethod()"),
  741. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  742. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"");
  743. assertTrue("Should have 'amethod() advised by " +
  744. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"" +
  745. "' in the Method Detail section", b);
  746. b = AjdocOutputChecker.detailSectionContainsRel(
  747. htmlFile,"=== METHOD DETAIL",
  748. toName("amethod()"),
  749. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  750. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p..");
  751. assertFalse("Should not have the label " +
  752. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.." +
  753. " in the Method Detail section", b);
  754. b = AjdocOutputChecker.summarySectionContainsRel(
  755. htmlFile,"=== METHOD SUMMARY",
  756. toName("amethod()"),
  757. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  758. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"");
  759. assertTrue("Should have 'amethod() advised by " +
  760. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"" +
  761. "' in the Method Summary section", b);
  762. b = AjdocOutputChecker.detailSectionContainsRel(
  763. htmlFile,"=== METHOD SUMMARY",
  764. toName("amethod()"),
  765. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  766. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p..");
  767. assertFalse("Should not have the label " +
  768. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.." +
  769. " in the Method Summary section", b);
  770. }
  771. private void createFiles() {
  772. file0 = new File(getAbsoluteProjectDir() + "/InDefaultPackage.java");
  773. file1 = new File(getAbsoluteProjectDir() + "/foo/ClassA.java");
  774. aspect1 = new File(getAbsoluteProjectDir() + "/foo/UseThisAspectForLinkCheck.aj");
  775. file2 = new File(getAbsoluteProjectDir() + "/foo/InterfaceI.java");
  776. file3 = new File(getAbsoluteProjectDir() + "/foo/PlainJava.java");
  777. file4 = new File(getAbsoluteProjectDir() + "/foo/ModelCoverage.java");
  778. file5 = new File(getAbsoluteProjectDir() + "/fluffy/Fluffy.java");
  779. file6 = new File(getAbsoluteProjectDir() + "/fluffy/bunny/Bunny.java");
  780. file7 = new File(getAbsoluteProjectDir() + "/fluffy/bunny/rocks/Rocks.java");
  781. file8 = new File(getAbsoluteProjectDir() + "/fluffy/bunny/rocks/UseThisAspectForLinkCheckToo.java");
  782. file9 = new File(getAbsoluteProjectDir() + "/foo/PkgVisibleClass.java");
  783. file10 = new File(getAbsoluteProjectDir() + "/foo/NoMembers.java");
  784. }
  785. // public void testPlainJava() {
  786. // String[] args = { "-d",
  787. // getAbsolutePathOutdir(),
  788. // file3.getAbsolutePath() };
  789. // org.aspectj.tools.ajdoc.Main.main(args);
  790. // }
  791. }