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 36KB

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