KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > test > GroupFormulaTest


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 JavaDoc;
10
11 /**
12  * Tests formula evals when formulas are hidden or appear multiple
13  * times.
14  * <p>
15  * These tests are tightly coupled with the contents of the
16  * <code>group_formulas_*</code> files.
17  *
18  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
19  */

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 JavaDoc GROUP_EVAL_DATA_FILE =
28     AllTests.testDataFile("group_formulas_data.csv");
29 protected static final String JavaDoc 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 JavaDoc name) {
40     super(name);
41 }
42
43 public void setUp() throws Exception JavaDoc {
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); // Must come after setting password
51

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 JavaDoc
64 {
65     // Run report in this thread, not a separate one. Running the
66
// report closes the output stream.
67
report.runReport();
68
69     // Open the output and the expected output and compare them.
70
BufferedReader out = new BufferedReader(new FileReader(OUT_FILE));
71     BufferedReader expected =
72     new BufferedReader(new FileReader(GROUP_EVAL_EXPECTED_FILE));
73
74     String JavaDoc outLine;
75     while ((outLine = out.readLine()) != null) {
76     String JavaDoc expectedLine = expected.readLine();
77     if (expectedLine == null)
78         fail("Too much data in output");
79     assertEquals(expectedLine, outLine);
80     }
81
82     // Make sure we are at the end of the expected file
83
assertNull(expected.readLine());
84
85     expected.close();
86     out.close();
87 }
88
89 public static void main(String JavaDoc[] args) {
90     junit.textui.TestRunner.run(suite());
91     System.exit(0);
92 }
93
94 }
95
Popular Tags