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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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","1.4",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 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","1.4",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","1.4",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","1.4",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. if (LangUtil.is18VMOrGreater()) {
  116. strings = new String[] {
  117. "Aspect ClassA.InnerAspect",
  118. "<pre>static aspect <span class=\"typeNameLabel\">ClassA.InnerAspect</span>",
  119. "Class ClassA.InnerAspect",
  120. "<pre>static class <span class=\"typeNameLabel\">ClassA.InnerAspect</span>"};
  121. }
  122. else {
  123. strings = new String[] {
  124. "Aspect ClassA.InnerAspect",
  125. "<PRE>static aspect <B>ClassA.InnerAspect</B><DT>extends java.lang.Object</DL>",
  126. "Class ClassA.InnerAspect",
  127. "<PRE>static class <B>ClassA.InnerAspect</B><DT>extends java.lang.Object</DL>"};
  128. }
  129. List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
  130. StringBuilder buf = new StringBuilder();
  131. for (String str:missingStrings) {
  132. buf.append(str).append("\n");
  133. }
  134. buf.append("HTMLFILE=\n").append(htmlFile).append("\n");
  135. assertEquals("There should be 2 missing strings:\n"+buf.toString(), 2, missingStrings.size());
  136. assertTrue(htmlFile.getName() + " should not have Class as it's title",
  137. missingStrings.contains("Class ClassA.InnerAspect"));
  138. if (LangUtil.is18VMOrGreater()) {
  139. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  140. missingStrings.contains("<pre>static class <span class=\"typeNameLabel\">ClassA.InnerAspect</span>"));
  141. }
  142. else {
  143. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  144. missingStrings.contains("<PRE>static class <B>ClassA.InnerAspect</B><DT>extends java.lang.Object</DL>"));
  145. }
  146. // get the html file for the enclosing class
  147. File htmlFileClass = new File(getAbsolutePathOutdir() + "/foo/ClassA.html");
  148. if (!htmlFileClass.exists()) {
  149. fail("couldn't find " + htmlFileClass.getAbsolutePath()
  150. + " - were there compilation errors?");
  151. }
  152. // ensure that the file is entitled "Class ClassA" and
  153. // has not been changed to "Aspect ClassA"
  154. String[] classStrings = null;
  155. if (LangUtil.is18VMOrGreater()) {
  156. classStrings = new String[] {
  157. "Class ClassA</h2>",
  158. "public abstract class <span class=\"typeNameLabel\">ClassA</span>",
  159. "Aspect ClassA</H2>",
  160. "public abstract aspect <span class=\"typeNameLabel\">ClassA</span>"};
  161. }
  162. else {
  163. classStrings = new String[] {
  164. "Class ClassA</H2>",
  165. "public abstract class <B>ClassA</B><DT>extends java.lang.Object<DT>",
  166. "Aspect ClassA</H2>",
  167. "public abstract aspect <B>ClassA</B><DT>extends java.lang.Object<DT>"};
  168. }
  169. List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings);
  170. assertEquals("There should be 2 missing strings:\n"+classMissing,2,classMissing.size());
  171. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect ClassA</H2>"));
  172. if (LangUtil.is18VMOrGreater()) {
  173. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  174. classMissing.contains("public abstract aspect <span class=\"typeNameLabel\">ClassA</span>"));
  175. }
  176. else {
  177. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  178. classMissing.contains("public abstract aspect <B>ClassA</B><DT>extends java.lang.Object<DT>"));
  179. }
  180. }
  181. /**
  182. * Test that all the different types of advice appear
  183. * with the named pointcut in it's description
  184. */
  185. public void testAdviceNamingCoverage() throws Exception {
  186. File[] files = {file4};
  187. runAjdoc("private","1.4",files);
  188. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdviceNamingCoverage.html");
  189. if (!htmlFile.exists()) {
  190. fail("couldn't find " + htmlFile.getAbsolutePath()
  191. + " - were there compilation errors?");
  192. }
  193. String[] strings = {
  194. "after(): named..",
  195. "afterReturning(int,int): namedWithArgs..",
  196. "afterThrowing(): named..",
  197. "before(): named..",
  198. "around(int): namedWithOneArg..",
  199. "before(int):",
  200. "before(int): named()..",
  201. "before():"};
  202. List missing = AjdocOutputChecker.getMissingStringsInSection(
  203. htmlFile, strings,"ADVICE DETAIL SUMMARY");
  204. assertTrue(htmlFile.getName() + " should contain all advice in the Advice Detail section",missing.isEmpty());
  205. missing = AjdocOutputChecker.getMissingStringsInSection(
  206. htmlFile,strings,"ADVICE SUMMARY");
  207. assertTrue(htmlFile.getName() + " should contain all advice in the Advice Summary section",missing.isEmpty());
  208. }
  209. /**
  210. * Test that all the advises relationships appear in the
  211. * Advice Detail and Advice Summary sections and that
  212. * the links are correct
  213. */
  214. public void testAdvisesRelationshipCoverage() throws Exception {
  215. File[] files = {file4};
  216. runAjdoc("private","1.4",files);
  217. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html");
  218. if (!htmlFile.exists()) {
  219. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  220. }
  221. String[] strings = {
  222. "before(): methodExecutionP..",
  223. "HREF=\"../foo/Point.html#setX(int)\"",
  224. "before(): constructorExecutionP..",
  225. "HREF=\"../foo/Point.html#Point()\"",
  226. "before(): callMethodP..",
  227. "HREF=\"../foo/Point.html#changeX(int)\"",
  228. "before(): callConstructorP..",
  229. "HREF=\"../foo/Point.html#doIt()\"",
  230. "before(): getP..",
  231. "HREF=\"../foo/Point.html#getX()\"",
  232. "before(): setP..",
  233. "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)\"",
  234. "before(): initializationP..",
  235. "HREF=\"../foo/Point.html#Point()\"",
  236. "before(): staticinitializationP..",
  237. "HREF=\"../foo/Point.html\"",
  238. "before(): handlerP..",
  239. "HREF=\"../foo/Point.html#doIt()\""
  240. };
  241. for (int i = 0; i < strings.length - 1; i = i+2) {
  242. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  243. htmlFile,"ADVICE DETAIL SUMMARY",strings[i],
  244. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  245. strings[i+1]);
  246. assertTrue(strings[i] + " should advise " + strings[i+1] +
  247. " in the Advice Detail section", b);
  248. }
  249. for (int i = 0; i < strings.length - 1; i = i+2) {
  250. boolean b = AjdocOutputChecker.summarySectionContainsRel(
  251. htmlFile,"ADVICE SUMMARY",strings[i],
  252. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  253. strings[i+1]);
  254. assertTrue(strings[i] + " should advise " + strings[i+1] +
  255. " in the Advice Summary section", b);
  256. }
  257. }
  258. /**
  259. * Test that the advised by relationship appears in the ajdoc when the
  260. * advice is associated with a method execution pointcut
  261. */
  262. public void testAdvisedByMethodExecution() throws Exception {
  263. File[] files = {file4};
  264. runAjdoc("private","1.4",files);
  265. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  266. if (!htmlFile.exists()) {
  267. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  268. }
  269. String[] strings = {
  270. toName("setX(int)"),
  271. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): methodExecutionP..\""};
  272. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  273. htmlFile,"=== METHOD DETAIL",
  274. strings[0],
  275. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  276. strings[1]);
  277. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  278. b = AjdocOutputChecker.summarySectionContainsRel(
  279. htmlFile,"=== METHOD SUMMARY",
  280. strings[0],
  281. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  282. strings[1]);
  283. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  284. }
  285. /**
  286. * Test that the advised by relationship appears in the ajdoc when the
  287. * advice is associated with a constructor execution pointcut
  288. */
  289. public void testAdvisedByConstructorExecution() throws Exception {
  290. File[] files = {file4};
  291. runAjdoc("private","1.4",files);
  292. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  293. if (!htmlFile.exists()) {
  294. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  295. }
  296. String[] strings = {
  297. toName("Point()"),
  298. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): constructorExecutionP..\""};
  299. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  300. htmlFile,"=== CONSTRUCTOR DETAIL",
  301. strings[0],
  302. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  303. strings[1]);
  304. assertTrue("the Constructor Detail should have " + strings[0]+" advised by " + strings[1],b);
  305. b = AjdocOutputChecker.summarySectionContainsRel(
  306. htmlFile,"=== CONSTRUCTOR SUMMARY",
  307. strings[0],
  308. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  309. strings[1]);
  310. assertTrue("the Constructor Summary should have " + strings[0]+" advised by " + strings[1],b);
  311. }
  312. /**
  313. * Test that the advised by relationship appears in the ajdoc when the
  314. * advice is associated with a method call pointcut
  315. */
  316. public void testAdvisedByMethodCall() throws Exception {
  317. File[] files = {file4};
  318. runAjdoc("private","1.4",files);
  319. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  320. if (!htmlFile.exists()) {
  321. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  322. }
  323. String[] strings = {
  324. toName("changeX(int)"),
  325. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): callMethodP..\""};
  326. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  327. htmlFile,"=== METHOD DETAIL",
  328. strings[0],
  329. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  330. strings[1]);
  331. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  332. b = AjdocOutputChecker.summarySectionContainsRel(
  333. htmlFile,"=== METHOD SUMMARY",
  334. strings[0],
  335. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  336. strings[1]);
  337. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  338. }
  339. /**
  340. * Test that the advised by relationship appears in the ajdoc when the
  341. * advice is associated with a constructor call pointcut
  342. */
  343. public void testAdvisedByConstructorCall() throws Exception {
  344. File[] files = {file4};
  345. runAjdoc("private","1.4",files);
  346. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  347. if (!htmlFile.exists()) {
  348. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  349. }
  350. String[] strings = {
  351. toName("doIt()"),
  352. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): callConstructorP..\""};
  353. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  354. htmlFile,"=== METHOD DETAIL",
  355. strings[0],
  356. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  357. strings[1]);
  358. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  359. b = AjdocOutputChecker.summarySectionContainsRel(
  360. htmlFile,"=== METHOD SUMMARY",
  361. strings[0],
  362. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  363. strings[1]);
  364. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  365. }
  366. /**
  367. * Test that the advised by relationship appears in the ajdoc when the
  368. * advice is associated with a get pointcut
  369. */
  370. public void testAdvisedByGet() throws Exception {
  371. File[] files = {file4};
  372. runAjdoc("private","1.4",files);
  373. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  374. if (!htmlFile.exists()) {
  375. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  376. }
  377. String[] strings = {
  378. toName("getX()"),
  379. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): getP..\""};
  380. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  381. htmlFile,"=== METHOD DETAIL",
  382. strings[0],
  383. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  384. strings[1]);
  385. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  386. b = AjdocOutputChecker.summarySectionContainsRel(
  387. htmlFile,"=== METHOD SUMMARY",
  388. strings[0],
  389. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  390. strings[1]);
  391. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  392. }
  393. /**
  394. * Test that the advised by relationship appears in the ajdoc when the
  395. * advice is associated with a set pointcut
  396. */
  397. public void testAdvisedBySet() throws Exception {
  398. File[] files = {file4};
  399. runAjdoc("private","1.4",files);
  400. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  401. if (!htmlFile.exists()) {
  402. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  403. }
  404. String href = "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): setP..\"";
  405. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  406. htmlFile,"=== METHOD DETAIL",
  407. toName("setX(int)"),
  408. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  409. href);
  410. assertTrue("the Method Detail should have setX(int) advised by " + href,b);
  411. b = AjdocOutputChecker.summarySectionContainsRel(
  412. htmlFile,"=== METHOD SUMMARY",
  413. toName("setX(int)"),
  414. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  415. href);
  416. assertTrue("the Method Summary should have setX(int) advised by " + href,b);
  417. b = AjdocOutputChecker.detailSectionContainsRel(
  418. htmlFile,"=== CONSTRUCTOR DETAIL",
  419. toName("Point()"),
  420. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  421. href);
  422. assertTrue("the Constructor Detail should have advised by " + href,b);
  423. b = AjdocOutputChecker.summarySectionContainsRel(
  424. htmlFile,"=== CONSTRUCTOR SUMMARY",
  425. toName("Point()"),
  426. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  427. href);
  428. assertTrue("the Constructor Summary should have advised by " + href,b);
  429. 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 an initialization pointcut
  438. */
  439. public void testAdvisedByInitialization() 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. toName("Point()"),
  448. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): initializationP..\""};
  449. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  450. htmlFile,"=== CONSTRUCTOR DETAIL",strings[0],
  451. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  452. strings[1]);
  453. assertTrue("the Method Detail should have 'setX(int) advised by ... before()'",b);
  454. b = AjdocOutputChecker.summarySectionContainsRel(
  455. htmlFile,"=== CONSTRUCTOR SUMMARY",strings[0],
  456. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  457. strings[1]);
  458. assertTrue("the Method Summary should have 'setX(int) advised by ... before()'",b);
  459. }
  460. /**
  461. * Test that the advised by relationship appears in the ajdoc when the
  462. * advice is associated with a staticinitialization pointcut
  463. */
  464. public void testAdvisedByStaticInitialization() throws Exception {
  465. File[] files = {file4};
  466. runAjdoc("private","1.4",files);
  467. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  468. if (!htmlFile.exists()) {
  469. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  470. }
  471. String href = "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): staticinitializationP..\"";
  472. boolean b = AjdocOutputChecker.classDataSectionContainsRel(
  473. htmlFile,
  474. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  475. href);
  476. assertTrue("The class data section should have 'advised by " + href + "'",b);
  477. }
  478. /**
  479. * Test that the advised by relationship appears in the ajdoc when the
  480. * advice is associated with a handler pointcut
  481. */
  482. public void testAdvisedByHandler() throws Exception {
  483. File[] files = {file4};
  484. runAjdoc("private","1.4",files);
  485. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html");
  486. if (!htmlFile.exists()) {
  487. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  488. }
  489. String[] strings = {
  490. toName("doIt()"),
  491. "HREF=\"../foo/AdvisesRelationshipCoverage.html#before(): handlerP..\""};
  492. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  493. htmlFile,"=== METHOD DETAIL",
  494. strings[0],
  495. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  496. strings[1]);
  497. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  498. b = AjdocOutputChecker.summarySectionContainsRel(
  499. htmlFile,"=== METHOD SUMMARY",
  500. strings[0],
  501. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  502. strings[1]);
  503. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  504. }
  505. private String toName(String name) {
  506. if (LangUtil.is18VMOrGreater()) {
  507. name = name.replace('(','-');
  508. name = name.replace(')','-');
  509. }
  510. return name;
  511. }
  512. /**
  513. * Test that if have two before advice blocks from the same
  514. * aspect affect the same method, then both appear in the ajdoc
  515. */
  516. public void testTwoBeforeAdvice() throws Exception {
  517. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/A2.aj")};
  518. runAjdoc("private","1.4",files);
  519. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/C2.html");
  520. if (!htmlFile.exists()) {
  521. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  522. }
  523. String[] strings = {
  524. toName("amethod()"),
  525. "HREF=\"../pkg/A2.html#before(): p..\"",
  526. "HREF=\"../pkg/A2.html#before(): p2..\""};
  527. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  528. htmlFile,"=== METHOD DETAIL",
  529. strings[0],
  530. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  531. strings[1]);
  532. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[1],b);
  533. b = AjdocOutputChecker.summarySectionContainsRel(
  534. htmlFile,"=== METHOD SUMMARY",
  535. strings[0],
  536. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  537. strings[1]);
  538. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[1],b);
  539. b = AjdocOutputChecker.detailSectionContainsRel(
  540. htmlFile,"=== METHOD DETAIL",
  541. strings[0],
  542. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  543. strings[2]);
  544. assertTrue("the Method Detail should have " + strings[0]+" advised by " + strings[2],b);
  545. b = AjdocOutputChecker.summarySectionContainsRel(
  546. htmlFile,"=== METHOD SUMMARY",
  547. strings[0],
  548. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  549. strings[2]);
  550. assertTrue("the Method Summary should have " + strings[0]+" advised by " + strings[2],b);
  551. }
  552. /**
  553. * Test that there are no spurious "advised by" entries
  554. * against the aspect in the ajdoc
  555. */
  556. public void testNoSpuriousAdvisedByRels() throws Exception {
  557. File[] files = {file4};
  558. runAjdoc("private","1.4",files);
  559. File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html");
  560. if (!htmlFile.exists()) {
  561. fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
  562. }
  563. String href = "foo.Point.setX(int)";
  564. boolean b = AjdocOutputChecker.classDataSectionContainsRel(
  565. htmlFile,
  566. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  567. href);
  568. assertFalse("The class data section should not have 'advised by " + href + "'",b);
  569. }
  570. public void testCoverage() {
  571. File[] files = {aspect1,file0,file1,file2,file3,file4,file5,file6,
  572. file7,file8,file9,file10};
  573. runAjdoc("private","1.4",files);
  574. }
  575. /**
  576. * Test that nested aspects appear with "aspect" in their title
  577. * when the ajdoc file is written slightly differently (when it's
  578. * written for this apsect, it's different than for testInnerAspect())
  579. */
  580. public void testNestedAspect() throws Exception {
  581. File[] files = {file9};
  582. runAjdoc("private","1.4",files);
  583. File htmlFile = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.NestedAspect.html");
  584. if (!htmlFile.exists()) {
  585. fail("couldn't find " + htmlFile.getAbsolutePath()
  586. + " - were there compilation errors?");
  587. }
  588. // ensure that the file is entitled "Aspect PkgVisibleClass.NestedAspect" rather
  589. // than "Class PkgVisibleClass.NestedAspect"
  590. String[] strings = null;
  591. if (LangUtil.is18VMOrGreater()) {
  592. strings = new String[] {
  593. "Aspect PkgVisibleClass.NestedAspect",
  594. "<pre>static aspect <span class=\"typeNameLabel\">PkgVisibleClass.NestedAspect</span>",
  595. "Class PkgVisibleClass.NestedAspect",
  596. "<pre>static class <span class=\"typeNameLabel\">PkgVisibleClass.NestedAspect</span>"};
  597. }
  598. else {
  599. strings = new String[] {
  600. "Aspect PkgVisibleClass.NestedAspect",
  601. "<PRE>static aspect <B>PkgVisibleClass.NestedAspect</B><DT>extends java.lang.Object</DL>",
  602. "Class PkgVisibleClass.NestedAspect",
  603. "<PRE>static class <B>PkgVisibleClass.NestedAspect</B><DT>extends java.lang.Object</DL>"};
  604. }
  605. List<String> missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
  606. assertEquals("There should be 2 missing strings",2,missing.size());
  607. assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class PkgVisibleClass.NestedAspect"));
  608. if (LangUtil.is18VMOrGreater()) {
  609. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  610. missing.contains("<pre>static class <span class=\"typeNameLabel\">PkgVisibleClass.NestedAspect</span>"));
  611. }
  612. else {
  613. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  614. missing.contains("<PRE>static class <B>PkgVisibleClass.NestedAspect</B><DT>extends java.lang.Object</DL>"));
  615. }
  616. // get the html file for the enclosing class
  617. File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html");
  618. if (!htmlFileClass.exists()) {
  619. fail("couldn't find " + htmlFileClass.getAbsolutePath()
  620. + " - were there compilation errors?");
  621. }
  622. // ensure that the file is entitled "Class PkgVisibleClass" and
  623. // has not been changed to "Aspect PkgVisibleClass"
  624. String[] classStrings = null;
  625. if (LangUtil.is18VMOrGreater()) {
  626. classStrings = new String[] {
  627. "Class PkgVisibleClass</h2>",
  628. "<pre>class <span class=\"typeNameLabel\">PkgVisibleClass</span>",
  629. "Aspect PkgVisibleClass</h2>",
  630. "<pre>aspect <span class=\"typeNameLabel\">PkgVisibleClass</span>"};
  631. }
  632. else {
  633. classStrings = new String[] {
  634. "Class PkgVisibleClass</H2>",
  635. "class <B>PkgVisibleClass</B><DT>extends java.lang.Object</DL>",
  636. "Aspect PkgVisibleClass</H2>",
  637. "aspect <B>PkgVisibleClass</B><DT>extends java.lang.Object<DT>"};
  638. }
  639. List<String> classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings);
  640. assertEquals("There should be 2 missing strings",2,classMissing.size());
  641. if (LangUtil.is18VMOrGreater()) {
  642. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",
  643. classMissing.contains("Aspect PkgVisibleClass</h2>"));
  644. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  645. classMissing.contains("<pre>aspect <span class=\"typeNameLabel\">PkgVisibleClass</span>"));
  646. }
  647. else {
  648. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect PkgVisibleClass</H2>"));
  649. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("aspect <B>PkgVisibleClass</B><DT>extends java.lang.Object<DT>"));
  650. }
  651. }
  652. /**
  653. * Test that in the case when you have a nested aspect whose
  654. * name is part of the enclosing class, for example a class called
  655. * ClassWithNestedAspect has nested aspect called NestedAspect,
  656. * that the titles for the ajdoc are correct.
  657. */
  658. public void testNestedAspectWithSimilarName() throws Exception {
  659. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")};
  660. runAjdoc("private","1.4",files);
  661. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html");
  662. if (!htmlFile.exists()) {
  663. fail("couldn't find " + htmlFile.getAbsolutePath()
  664. + " - were there compilation errors?");
  665. }
  666. // ensure that the file is entitled "Aspect ClassWithNestedAspect.NestedAspect"
  667. // rather than "Class ClassWithNestedAspect.NestedAspect"
  668. String[] strings = null;
  669. if (LangUtil.is18VMOrGreater()) {
  670. strings = new String [] {
  671. "Aspect ClassWithNestedAspect.NestedAspect",
  672. "<pre>static aspect <span class=\"typeNameLabel\">ClassWithNestedAspect.NestedAspect</span>",
  673. "Class ClassWithNestedAspect.NestedAspect",
  674. "<pre>static class <span class=\"typeNameLabel\">ClassWithNestedAspect.NestedAspect</span>"};
  675. }
  676. else {
  677. strings = new String [] {
  678. "Aspect ClassWithNestedAspect.NestedAspect",
  679. "<PRE>static a;spect <B>ClassWithNestedAspect.NestedAspect</B><DT>extends java.lang.Object</DL>",
  680. "Class ClassWithNestedAspect.NestedAspect",
  681. "<PRE>static class <B>ClassWithNestedAspect.NestedAspect</B><DT>extends java.lang.Object</DL>"};
  682. }
  683. List<String> missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
  684. assertEquals("There should be 2 missing strings",2,missing.size());
  685. assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class ClassWithNestedAspect.NestedAspect"));
  686. if (LangUtil.is18VMOrGreater()) {
  687. assertTrue(htmlFile.getName() + " should not have class in its subtitle",
  688. missing.contains("<pre>static class <span class=\"typeNameLabel\">ClassWithNestedAspect.NestedAspect</span>"));
  689. }
  690. else {
  691. 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>"));
  692. }
  693. // get the html file for the enclosing class
  694. File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html");
  695. if (htmlFileClass == null || !htmlFileClass.exists()) {
  696. fail("couldn't find " + htmlFileClass.getAbsolutePath()
  697. + " - were there compilation errors?");
  698. }
  699. // ensure that the file is entitled "Class ClassWithNestedAspect" and
  700. // has not been changed to "Aspect ClassWithNestedAspect"
  701. String[] classStrings = null;
  702. if (LangUtil.is18VMOrGreater()) {
  703. classStrings = new String[] {
  704. "Class ClassWithNestedAspect</h2>",
  705. "public class <span class=\"typeNameLabel\">ClassWithNestedAspect</span>",
  706. "Aspect ClassWithNestedAspect</h2>",
  707. "public aspect <span class=\"typeNameLabel\">ClassWithNestedAspect</span>"};
  708. }
  709. else {
  710. classStrings = new String[] {
  711. "Class ClassWithNestedAspect</H2>",
  712. "public class <B>ClassWithNestedAspect</B><DT>extends java.lang.Object</DL>",
  713. "Aspect ClassWithNestedAspect</H2>",
  714. "public aspect <B>ClassWithNestedAspect</B><DT>extends java.lang.Object</DL>"};
  715. }
  716. List<String> classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings);
  717. assertEquals("There should be 2 missing strings",2,classMissing.size());
  718. if (LangUtil.is18VMOrGreater()) {
  719. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",
  720. classMissing.contains("Aspect ClassWithNestedAspect</h2>"));
  721. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  722. classMissing.contains("public aspect <span class=\"typeNameLabel\">ClassWithNestedAspect</span>"));
  723. }
  724. else {
  725. assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",
  726. classMissing.contains("Aspect ClassWithNestedAspect</H2>"));
  727. assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
  728. classMissing.contains("public aspect <B>ClassWithNestedAspect</B><DT>extends java.lang.Object</DL>"));
  729. }
  730. }
  731. /**
  732. * Test that everythings being decorated correctly within the ajdoc
  733. * for the aspect when the aspect is a nested aspect
  734. */
  735. public void testAdviceInNestedAspect() throws Exception {
  736. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")};
  737. runAjdoc("private","1.4",files);
  738. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html");
  739. if (!htmlFile.exists()) {
  740. fail("couldn't find " + htmlFile.getAbsolutePath()
  741. + " - were there compilation errors?");
  742. }
  743. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  744. htmlFile,"ADVICE DETAIL SUMMARY",
  745. "before(): p..",
  746. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  747. "HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"");
  748. assertTrue("Should have 'before(): p.. advises HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"" +
  749. "' in the Advice Detail section", b);
  750. b = AjdocOutputChecker.summarySectionContainsRel(
  751. htmlFile,"ADVICE SUMMARY",
  752. "before(): p..",
  753. HtmlDecorator.HtmlRelationshipKind.ADVISES,
  754. "HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"");
  755. assertTrue("Should have 'before(): p.. advises HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"" +
  756. "' in the Advice Summary section", b);
  757. }
  758. /**
  759. * Test that everythings being decorated correctly within the ajdoc
  760. * for the advised class when the aspect is a nested aspect
  761. */
  762. public void testAdvisedByInNestedAspect() throws Exception {
  763. File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")};
  764. runAjdoc("private","1.4",files);
  765. File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html");
  766. if (!htmlFile.exists()) {
  767. fail("couldn't find " + htmlFile.getAbsolutePath()
  768. + " - were there compilation errors?");
  769. }
  770. boolean b = AjdocOutputChecker.containsString(htmlFile,"POINTCUT SUMMARY ");
  771. assertFalse(htmlFile.getName() + " should not contain a pointcut summary section",b);
  772. b = AjdocOutputChecker.containsString(htmlFile,"ADVICE SUMMARY ");
  773. assertFalse(htmlFile.getName() + " should not contain an adivce summary section",b);
  774. b = AjdocOutputChecker.containsString(htmlFile,"POINTCUT DETAIL ");
  775. assertFalse(htmlFile.getName() + " should not contain a pointcut detail section",b);
  776. b = AjdocOutputChecker.containsString(htmlFile,"ADVICE DETAIL ");
  777. assertFalse(htmlFile.getName() + " should not contain an advice detail section",b);
  778. b = AjdocOutputChecker.detailSectionContainsRel(
  779. htmlFile,"=== METHOD DETAIL",
  780. toName("amethod()"),
  781. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  782. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"");
  783. assertTrue("Should have 'amethod() advised by " +
  784. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"" +
  785. "' in the Method Detail section", b);
  786. b = AjdocOutputChecker.detailSectionContainsRel(
  787. htmlFile,"=== METHOD DETAIL",
  788. toName("amethod()"),
  789. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  790. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p..");
  791. assertFalse("Should not have the label " +
  792. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.." +
  793. " in the Method Detail section", b);
  794. b = AjdocOutputChecker.summarySectionContainsRel(
  795. htmlFile,"=== METHOD SUMMARY",
  796. toName("amethod()"),
  797. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  798. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"");
  799. assertTrue("Should have 'amethod() advised by " +
  800. "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"" +
  801. "' in the Method Summary section", b);
  802. b = AjdocOutputChecker.detailSectionContainsRel(
  803. htmlFile,"=== METHOD SUMMARY",
  804. toName("amethod()"),
  805. HtmlDecorator.HtmlRelationshipKind.ADVISED_BY,
  806. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p..");
  807. assertFalse("Should not have the label " +
  808. "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.." +
  809. " in the Method Summary section", b);
  810. }
  811. private void createFiles() {
  812. file0 = new File(getAbsoluteProjectDir() + "/InDefaultPackage.java");
  813. file1 = new File(getAbsoluteProjectDir() + "/foo/ClassA.java");
  814. aspect1 = new File(getAbsoluteProjectDir() + "/foo/UseThisAspectForLinkCheck.aj");
  815. file2 = new File(getAbsoluteProjectDir() + "/foo/InterfaceI.java");
  816. file3 = new File(getAbsoluteProjectDir() + "/foo/PlainJava.java");
  817. file4 = new File(getAbsoluteProjectDir() + "/foo/ModelCoverage.java");
  818. file5 = new File(getAbsoluteProjectDir() + "/fluffy/Fluffy.java");
  819. file6 = new File(getAbsoluteProjectDir() + "/fluffy/bunny/Bunny.java");
  820. file7 = new File(getAbsoluteProjectDir() + "/fluffy/bunny/rocks/Rocks.java");
  821. file8 = new File(getAbsoluteProjectDir() + "/fluffy/bunny/rocks/UseThisAspectForLinkCheckToo.java");
  822. file9 = new File(getAbsoluteProjectDir() + "/foo/PkgVisibleClass.java");
  823. file10 = new File(getAbsoluteProjectDir() + "/foo/NoMembers.java");
  824. }
  825. // public void testPlainJava() {
  826. // String[] args = { "-d",
  827. // getAbsolutePathOutdir(),
  828. // file3.getAbsolutePath() };
  829. // org.aspectj.tools.ajdoc.Main.main(args);
  830. // }
  831. }