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

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