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.

AjcSpecXmlReaderTest.java 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.testing.xml;
  14. import java.beans.BeanInfo;
  15. import java.beans.IntrospectionException;
  16. import java.beans.Introspector;
  17. import java.beans.PropertyDescriptor;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.util.ArrayList;
  21. import java.util.Iterator;
  22. import org.aspectj.testing.harness.bridge.AjcSpecTest;
  23. import org.aspectj.testing.harness.bridge.AjcTest;
  24. import org.aspectj.testing.harness.bridge.FlatSuiteReader;
  25. import org.aspectj.util.LangUtil;
  26. //import junit.framework.*;
  27. import junit.framework.TestCase;
  28. /**
  29. *
  30. */
  31. public class AjcSpecXmlReaderTest extends TestCase {
  32. ArrayList<File> tempFiles = new ArrayList<File>();
  33. /**
  34. * Constructor for AjcSpecXmlReaderTest.
  35. * @param name
  36. */
  37. public AjcSpecXmlReaderTest(String name) {
  38. super(name);
  39. }
  40. public void setUp() {
  41. tempFiles.clear();
  42. //System.out.println("XXX test requires compiler and bridgeImpl projects on classpath");
  43. }
  44. public void tearDown() {
  45. if (!LangUtil.isEmpty(tempFiles)) {
  46. for (Iterator<File> iter = tempFiles.iterator(); iter.hasNext();) {
  47. File file = (File) iter.next();
  48. if (file.canRead()) {
  49. file.delete();
  50. }
  51. }
  52. }
  53. }
  54. /** test that all AjcSpecXmlReader.me.expectedProperties() are bean-writable */
  55. public void testBeanInfo() throws IntrospectionException {
  56. // AjcSpecXmlReader me = AjcSpecXmlReader.getReader();
  57. AjcSpecXmlReader.BProps[] expected
  58. = AjcSpecXmlReader.expectedProperties();
  59. PropertyDescriptor[] des;
  60. for (int i = 0; i < expected.length; i++) {
  61. Class<?> clazz = expected[i].cl;
  62. BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
  63. assertTrue(null != beanInfo);
  64. des = beanInfo.getPropertyDescriptors();
  65. for (int j = 0; j < expected[i].props.length; j++) {
  66. String name = expected[i].props[j];
  67. String fqn = clazz.getName() + "." + name;
  68. boolean gotIt = false;
  69. for (int k = 0; k < des.length; k++) {
  70. String desName = des[k].getName();
  71. if (name.equals(desName)) {
  72. assertTrue(fqn, null != des[k].getWriteMethod());
  73. gotIt = true;
  74. }
  75. }
  76. assertTrue("no such property: " + fqn, gotIt);
  77. }
  78. }
  79. }
  80. // public void testAjcTests() throws IOException {
  81. // checkXmlRoundTrip("../tests/ajcTests");
  82. // }
  83. public void testAjcTests10() throws IOException {
  84. checkXmlRoundTrip("../tests/ajcTests10");
  85. }
  86. public void testAjcTestsBroken() throws IOException {
  87. checkXmlRoundTrip("../tests/ajcTestsBroken");
  88. }
  89. public void testAjcTestsAttic() throws IOException {
  90. checkXmlRoundTrip("../tests/ajcTestsAttic");
  91. }
  92. public void testAjcHarnessTests() throws IOException {
  93. checkXmlRoundTrip("../tests/ajcHarnessTests");
  94. }
  95. void checkXmlRoundTrip(String path) throws IOException {
  96. String xmlPath = path + ".xml";
  97. String xml2Path = path + ".tmp.xml";
  98. final File file1 = new File(xmlPath);
  99. final ArrayList<File> toDelete = new ArrayList<File>();
  100. final AjcSpecXmlReader writer = AjcSpecXmlReader.getReader();
  101. assertTrue("" + file1, file1.canRead());
  102. AjcTest.Suite.Spec suite1 = writer.readAjcSuite(file1);
  103. assertNotNull(suite1);
  104. File file2 = new File(xml2Path);
  105. String warning = writer.writeSuiteToXmlFile(file2, suite1);
  106. toDelete.add(file2);
  107. assertTrue(warning, null == warning);
  108. AjcTest.Suite.Spec suite2 = writer.readAjcSuite(file1);
  109. assertNotNull(suite2);
  110. AjcSpecTest.sameAjcSuiteSpec(suite1, suite2, this);
  111. // check clone while we're here
  112. try {
  113. Object clone = (AjcTest.Suite.Spec) suite1.clone();
  114. AjcSpecTest.sameAjcSuiteSpec(suite1, (AjcTest.Suite.Spec) clone, this);
  115. clone = (AjcTest.Suite.Spec) suite2.clone();
  116. AjcSpecTest.sameAjcSuiteSpec(suite2, (AjcTest.Suite.Spec) clone, this);
  117. AjcSpecTest.sameAjcSuiteSpec(suite1, (AjcTest.Suite.Spec) clone, this);
  118. } catch (CloneNotSupportedException e) {
  119. e.printStackTrace(System.err);
  120. assertTrue("CloneNotSupportedException: " + e.getMessage(), false);
  121. }
  122. for (Iterator<File> iter = toDelete.iterator(); iter.hasNext();) {
  123. iter.next().delete();
  124. }
  125. }
  126. void checkRoundTrip(String path) throws IOException, Exception {
  127. // XXX once .txt gone, add bugId and keywords to test
  128. String txtPath = path + ".txt";
  129. String xmlPath = path + ".tmp.xml";
  130. String xml2Path = path + ".tmp2.xml";
  131. // read flat, write the xml variant, read back, and compare
  132. AjcSpecXmlReader writer = AjcSpecXmlReader.getReader();
  133. File file0 = new File(txtPath);
  134. File file1 = new File(xmlPath);
  135. ArrayList<File> toDelete = new ArrayList<File>();
  136. AjcTest.Suite.Spec suite0 = null;
  137. if (file0.canRead()) {
  138. System.out.println("reading " + file0);
  139. suite0 = FlatSuiteReader.ME.readSuite(file0);
  140. String warning = writer.writeSuiteToXmlFile(file1, suite0);
  141. toDelete.add(file1);
  142. assertTrue(warning, null == warning);
  143. } else {
  144. file1 = new File(path + ".xml");
  145. if (file1.canRead()) {
  146. System.out.println("reading " + file1);
  147. suite0 = writer.readAjcSuite(file1);
  148. } else {
  149. System.err.println("Skipping as not in module: " + file0);
  150. return;
  151. }
  152. }
  153. assertNotNull(suite0);
  154. //System.err.println("----------------------- suite0 " + txtPath);
  155. //suite0.printAll(System.err, "");
  156. assertTrue("" + file1, file1.canRead());
  157. System.out.println("reading " + file1);
  158. AjcTest.Suite.Spec suite1 = writer.readAjcSuite(file1);
  159. assertNotNull(suite1);
  160. //System.err.println("----------------------- suite1 " + xmlPath);
  161. //suite0.printAll(System.err, "");
  162. AjcSpecTest.sameAjcSuiteSpec(suite0, suite1, this);
  163. // same for second-generation xml
  164. file1 = new File(xml2Path);
  165. String warning = writer.writeSuiteToXmlFile(file1, suite1);
  166. toDelete.add(file1);
  167. // XXX enable later assertTrue(warning, null == warning);
  168. if (null != warning) {
  169. System.out.println("warning " + file1 + ": " + warning);
  170. }
  171. System.out.println("reading " + file1);
  172. AjcTest.Suite.Spec suite2 = writer.readAjcSuite(file1);
  173. assertNotNull(suite2);
  174. //System.err.println("----------------------- suite2 " + xml2Path);
  175. AjcSpecTest.sameAjcSuiteSpec(suite1, suite2, this);
  176. AjcSpecTest.sameAjcSuiteSpec(suite0, suite2, this);
  177. for (Iterator<File> iter = toDelete.iterator(); iter.hasNext();) {
  178. iter.next().delete();
  179. }
  180. }
  181. }
  182. // ------------------- XXX retry execution round-trips when eclipse working
  183. //AjcSpecTest.sameAjcTestSpec(txtList, xmlSpec, this);
  184. // List xmlList = writer.readAjcTests(xmlFile);
  185. // AjcSpecTest.sameAjcTestLists(txtList, xmlList, this);
  186. // List xml2List = writer.readAjcTests(xmlFile);
  187. // AjcSpecTest.sameAjcTestLists(xmlList, xml2List, this);
  188. // ------------------ now run them both and compare results
  189. // // run the flat and xml variants, then compare
  190. // MessageHandler xmlHandler = new MessageHandler();
  191. // IRunStatus xmlStatus = runFile(xmlPath, xmlHandler);
  192. // MessageHandler txtHandler = new MessageHandler();
  193. // IRunStatus txtStatus = runFile(txtPath, txtHandler);
  194. //
  195. //
  196. // // both should pass or fail..
  197. // IRunValidator v = RunValidator.NORMAL;
  198. // boolean xmlPassed = v.runPassed(xmlStatus);
  199. // boolean txtPassed = v.runPassed(txtStatus);
  200. // boolean passed = (xmlPassed == txtPassed);
  201. // if (!xmlPassed) {
  202. // MessageUtil.print(System.err, xmlStatus);
  203. // }
  204. // if (!txtPassed) {
  205. // MessageUtil.print(System.err, txtStatus);
  206. // }
  207. // if (!passed) { // calculate diffs
  208. // }
  209. // IRunStatus runFile(String path, MessageHandler handler) throws IOException {
  210. // Main runner = new Main(new String[] {path}, handler);
  211. // String id = "AjcSpecXmlReaderTest.runFile(" + path + ")";
  212. // return runner.runMain(id, handler, System.err);
  213. // }