1 package jimm.datavision.test; 2 import jimm.datavision.*; 3 import jimm.datavision.layout.CharSepLE; 4 import jimm.datavision.source.Join; 5 import java.io.*; 6 import java.util.Iterator ; 7 import junit.framework.TestCase; 8 import junit.framework.TestSuite; 9 import junit.framework.Test; 10 11 21 public class SubreportRunTest extends TestCase { 22 23 protected static final File EXAMPLE_REPORT = 24 new File(AllTests.testDataFile("test_sub.xml")); 25 protected static final File OUT_FILE = 26 new File(System.getProperty("java.io.tmpdir"), 27 "datavision_subreport_run_test_out.txt"); 28 protected static final String REPORT_DATE_FORMAT = "yyyy-MM-dd"; 31 protected static final String OFFICES[] = { 34 "Chicago", "New Jersey", "New York" 35 }; 36 protected static final String STRING_PARAM_VALUE = "Chicago"; 39 protected static final String REPORT_TITLE = "Example Report"; 42 43 protected Report report; 44 45 public static Test suite() { 46 return new TestSuite(SubreportRunTest.class); 47 } 48 49 public SubreportRunTest(String name) { 50 super(name); 51 } 52 53 public void setUp() throws Exception { 54 report = new Report(); 55 report.setDatabasePassword(""); 56 report.read(EXAMPLE_REPORT); 58 if (OUT_FILE.exists()) 59 OUT_FILE.delete(); OUT_FILE.deleteOnExit(); 61 PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE)); 62 report.setLayoutEngine(new CharSepLE(out, '\t')); 63 } 64 65 public void tearDown() { 66 if (OUT_FILE.exists()) 67 OUT_FILE.delete(); 68 } 69 70 public void testReportRun() throws IOException, FileNotFoundException { 72 report.runReport(); 75 76 BufferedReader in = new BufferedReader(new FileReader(OUT_FILE)); 77 String line; 78 int cityIndex = -1; 79 String expectedOffice; 80 while ((line = in.readLine()) != null) { 81 int tabPos = line.indexOf("\t"); 82 83 if (tabPos == -1) ++cityIndex; 85 expectedOffice = ReportRunTest.OFFICES[cityIndex]; 86 87 if (tabPos == -1) 88 assertEquals(expectedOffice, line); 89 else { 90 line = line.substring(tabPos + 1); 92 tabPos = line.indexOf("\t"); 93 assertEquals(expectedOffice, line.substring(tabPos + 1)); 94 } 95 } 96 in.close(); 97 } 98 99 public void testMultipleJoins() throws IOException, FileNotFoundException { 100 for (Iterator iter = report.subreports(); iter.hasNext(); ) { 101 Subreport s = (Subreport)iter.next(); 102 s.addJoin(new Join(report.findColumn("office.name"), "=", 103 report.findColumn("office.name"))); 104 } 105 106 report.runReport(); 109 110 BufferedReader in = new BufferedReader(new FileReader(OUT_FILE)); 111 String line; 112 int cityIndex = -1; 113 String expectedOffice; 114 while ((line = in.readLine()) != null) { 115 int tabPos = line.indexOf("\t"); 116 117 if (tabPos == -1) ++cityIndex; 119 expectedOffice = ReportRunTest.OFFICES[cityIndex]; 120 121 if (tabPos == -1) 122 assertEquals(expectedOffice, line); 123 else { 124 line = line.substring(tabPos + 1); 126 tabPos = line.indexOf("\t"); 127 assertEquals(expectedOffice, line.substring(tabPos + 1)); 128 } 129 } 130 in.close(); 131 } 132 133 public static void main(String [] args) { 134 junit.textui.TestRunner.run(suite()); 135 System.exit(0); 136 } 137 138 } 139 | Popular Tags |