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

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