1 package csdl.jblanket.report; 2 3 import csdl.jblanket.methodset.MethodSet; 4 5 import java.io.File ; 6 import java.io.FileInputStream ; 7 import java.io.FileNotFoundException ; 8 import java.io.IOException ; 9 import java.util.ArrayList ; 10 import java.util.Iterator ; 11 12 import junit.framework.TestCase; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 16 import org.apache.tools.ant.util.FileUtils; 17 18 import org.jdom.Document; 19 import org.jdom.Element; 20 import org.jdom.JDOMException; 21 import org.jdom.input.SAXBuilder; 22 23 39 public class TestReport extends TestCase { 40 41 42 private final String reportFormat = "-reportFormat"; 43 44 45 private final String excludeOneLineMethods = "-excludeOneLineMethods"; 46 47 private final String excludeConstructors = "-excludeConstructors"; 48 49 50 private final String totalFile = "-totalFile"; 51 52 private final String testFile = "-testedFile"; 53 54 private final String untestedFile = "-untestedFile"; 55 56 private final String untestableFile = "-untestableFile"; 57 58 private final String oneLineFile = "-oneLineFile"; 59 60 private final String constructorFile = "-constructorFile"; 61 62 63 private final boolean excludeOneLineMethodsValue = true; 64 65 private final boolean excludeConstructorsValue = true; 66 67 68 private final String frames = "frames"; 69 70 71 private final String totalXmlFile = "totalMethods.xml"; 72 73 private final String testXmlFile = "testedMethods.xml"; 74 75 private final String untestedXmlFile = "untestedMethods.xml"; 76 77 private final String untestableXmlFile = "untestableMethods.xml"; 78 79 private final String oneLineXmlFile = "onelineMethods.xml"; 80 81 private final String constructorXmlFile = "constructorMethods.xml"; 82 83 84 private final String coverFile1 = "COVER-csdl.foo.TestBar.xml"; 85 86 private final String coverFile2 = "COVER-csdl.foo.TestBar2.xml"; 87 88 private final String coverFile3 = "COVER-MethodSets.xml"; 89 90 91 private MethodSet methodSetTotal; 92 93 private MethodSet methodSetTest; 94 95 private MethodSet methodSetDiff; 96 97 private MethodSet methodSetOneLine; 98 99 private MethodSet methodSetConstructor; 100 101 102 private File xmlTestdataDir; 103 104 private final String testdataDirName = "testdata"; 105 106 private final String xmlTestdataDirName = "xml"; 107 108 private final String prefix = "test."; 109 110 111 private String jblanketDir; 112 113 118 public TestReport(String name) { 119 120 super(name); 121 } 122 123 129 public void setUp() throws Exception { 130 131 String testdataDir = System.getProperty("jblanket.data.dir"); 132 133 this.xmlTestdataDir = new File (testdataDir, this.xmlTestdataDirName); 134 this.jblanketDir = System.getProperty("jblanket.testdir"); 135 assertNotNull("Checking for presence of jblanket.testdir.", jblanketDir); 136 137 FileUtils util = FileUtils.newFileUtils(); 139 util.copyFile(new File (this.xmlTestdataDir, this.totalXmlFile), 140 new File (this.jblanketDir, this.totalXmlFile)); 141 util.copyFile(new File (this.xmlTestdataDir, this.oneLineXmlFile), 142 new File (this.jblanketDir, this.oneLineXmlFile)); 143 util.copyFile(new File (this.xmlTestdataDir, this.constructorXmlFile), 144 new File (this.jblanketDir, this.constructorXmlFile)); 145 util.copyFile(new File (this.xmlTestdataDir, this.coverFile1), 146 new File (this.jblanketDir, this.coverFile1)); 147 util.copyFile(new File (this.xmlTestdataDir, this.coverFile2), 148 new File (this.jblanketDir, this.coverFile2)); 149 util.copyFile(new File (this.xmlTestdataDir, this.coverFile3), 150 new File (this.jblanketDir, this.prefix + this.coverFile3)); 151 } 152 153 158 public void testReport() throws Exception { 159 160 ArrayList args = new ArrayList (); 162 args.add(this.reportFormat); 163 args.add(this.frames); 164 args.add(this.totalFile); 165 args.add(this.totalXmlFile); 166 args.add(this.testFile); 167 args.add(this.testXmlFile); 168 args.add(this.untestedFile); 169 args.add(this.untestedXmlFile); 170 args.add(this.untestableFile); 171 args.add(this.untestableXmlFile); 172 args.add(this.excludeOneLineMethods); 173 args.add(new Boolean (this.excludeOneLineMethodsValue)); 174 args.add(this.oneLineFile); 175 args.add(this.oneLineXmlFile); 176 args.add(this.excludeConstructors); 177 args.add(new Boolean (this.excludeConstructorsValue)); 178 args.add(this.constructorFile); 179 args.add(this.constructorXmlFile); 180 181 JBlanketReport.main(args); 183 184 verifyFileContents(new File (this.jblanketDir, this.prefix + this.coverFile3), 186 new File (this.jblanketDir, this.coverFile3)); 187 } 188 189 198 private void verifyFileContents(File oldFile, File newFile) 199 throws FileNotFoundException , JDOMException, IOException { 200 201 FileInputStream stream1 = new FileInputStream (oldFile); 203 FileInputStream stream2 = new FileInputStream (newFile); 204 205 SAXBuilder builder1 = new SAXBuilder(); 207 SAXBuilder builder2 = new SAXBuilder(); 208 Document doc1 = builder1.build(stream1); 209 Document doc2 = builder2.build(stream2); 210 211 Element rootElement1 = doc1.getRootElement(); 213 Element rootElement2 = doc2.getRootElement(); 214 215 Iterator j = rootElement2.getChildren().iterator(); 217 218 for (Iterator i = rootElement1.getChildren().iterator(); i.hasNext(); ) { 220 Element element1 = (Element) i.next(); 221 Element element2 = (Element) j.next(); 222 223 String value1, value2; 225 value1 = element1.getAttributeValue("tested"); 226 value2 = element2.getAttributeValue("tested"); 227 assertEquals("Checking tested values", value1, value2); 228 229 value1 = element1.getAttributeValue("untested"); 231 value2 = element2.getAttributeValue("untested"); 232 assertEquals("Checking untested values", value1, value2); 233 234 value1 = element1.getAttributeValue("oneline"); 236 value2 = element2.getAttributeValue("oneline"); 237 assertEquals("Checking oneline values", value1, value2); 238 } 239 } 240 241 246 public static void main(String [] args) { 247 248 System.out.println("JUnit testing csdl.jblanket.report package."); 249 TestRunner.run(new TestSuite(TestReport.class)); 251 } 252 } 253 | Popular Tags |