1 package jimm.datavision.test; 2 import jimm.datavision.*; 3 import jimm.datavision.layout.CharSepLE; 4 import jimm.datavision.source.charsep.CharSepSource; 5 import java.io.*; 6 import junit.framework.TestCase; 7 import junit.framework.TestSuite; 8 import junit.framework.Test; 9 import org.xml.sax.SAXException ; 10 11 20 public class GroupFormulaTest extends TestCase { 21 22 protected static final File OUT_FILE = 23 new File(System.getProperty("java.io.tmpdir"), 24 "datavision_grp_form_test_out.txt"); 25 protected static final File GROUP_EVAL_REPORT = 26 new File(AllTests.testDataFile("group_formulas.xml")); 27 protected static final String GROUP_EVAL_DATA_FILE = 28 AllTests.testDataFile("group_formulas_data.csv"); 29 protected static final String GROUP_EVAL_EXPECTED_FILE = 30 AllTests.testDataFile("group_formulas_expected.csv"); 31 32 protected Report report; 33 protected CharSepSource dataSource; 34 35 public static Test suite() { 36 return new TestSuite(GroupFormulaTest.class); 37 } 38 39 public GroupFormulaTest(String name) { 40 super(name); 41 } 42 43 public void setUp() throws Exception { 44 report = new Report(); 45 46 OUT_FILE.deleteOnExit(); 47 PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE)); 48 report.setLayoutEngine(new CharSepLE(out, ',')); 49 50 report.read(GROUP_EVAL_REPORT); 52 dataSource = (CharSepSource)report.getDataSource(); 53 dataSource.setSepChar(','); 54 dataSource.setInput(GROUP_EVAL_DATA_FILE); 55 } 56 57 public void tearDown() { 58 if (OUT_FILE.exists()) 59 OUT_FILE.delete(); 60 } 61 62 public void testGroupHeaderFormula() 63 throws IOException, FileNotFoundException, SAXException 64 { 65 report.runReport(); 68 69 BufferedReader out = new BufferedReader(new FileReader(OUT_FILE)); 71 BufferedReader expected = 72 new BufferedReader(new FileReader(GROUP_EVAL_EXPECTED_FILE)); 73 74 String outLine; 75 while ((outLine = out.readLine()) != null) { 76 String expectedLine = expected.readLine(); 77 if (expectedLine == null) 78 fail("Too much data in output"); 79 assertEquals(expectedLine, outLine); 80 } 81 82 assertNull(expected.readLine()); 84 85 expected.close(); 86 out.close(); 87 } 88 89 public static void main(String [] args) { 90 junit.textui.TestRunner.run(suite()); 91 System.exit(0); 92 } 93 94 } 95 | Popular Tags |