Source Code Cross Referenced for AggregateTest.java in  » Report » datavision-1.1.0 » jimm » datavision » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » datavision 1.1.0 » jimm.datavision.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.test;
002:
003:        import jimm.datavision.*;
004:        import jimm.datavision.field.AggregateField;
005:        import jimm.datavision.layout.CharSepLE;
006:        import jimm.datavision.test.mock.source.MockAggregateDataSource;
007:        import java.io.*;
008:        import java.util.*;
009:        import junit.framework.TestCase;
010:        import junit.framework.TestSuite;
011:        import junit.framework.Test;
012:
013:        /**
014:         * Tests the aggregate functions by reading a report from an XML file, running
015:         * it, and verifying the output.
016:         * <p>
017:         * These tests are tightly coupled with the contents of the file
018:         * <code>aggregate_test.xml</code> and the contents of the data generated by
019:         * a {@link MockAggregateDataSource}.
020:         *
021:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
022:         */
023:        public class AggregateTest extends TestCase {
024:
025:            protected static final File EXAMPLE_REPORT = new File(AllTests
026:                    .testDataFile("aggregate_test.xml"));
027:            protected static final File OUT_FILE = new File(System
028:                    .getProperty("java.io.tmpdir"),
029:                    "datavision_aggregate_test_out.txt");
030:
031:            protected Report report;
032:            protected Collection aggrFields;
033:
034:            public static Test suite() {
035:                return new TestSuite(AggregateTest.class);
036:            }
037:
038:            public AggregateTest(String name) {
039:                super (name);
040:            }
041:
042:            public void setUp() throws Exception {
043:                report = new Report();
044:                report.setDataSource(new MockAggregateDataSource(report));
045:
046:                OUT_FILE.deleteOnExit();
047:                PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE));
048:                report.setLayoutEngine(new CharSepLE(out, '\t'));
049:
050:                report.read(EXAMPLE_REPORT); // Must come after setting password
051:                aggrFields = new ArrayList();
052:                aggrFields.add(report.findField(new Long(23)));
053:                aggrFields.add(report.findField(new Long(24)));
054:                aggrFields.add(report.findField(new Long(25)));
055:                aggrFields.add(report.findField(new Long(27)));
056:            }
057:
058:            public void tearDown() {
059:                if (OUT_FILE.exists())
060:                    OUT_FILE.delete();
061:            }
062:
063:            public void testSum() throws IOException, FileNotFoundException {
064:                String[] expected = { "A", "B", "D", // group headers
065:                        "2", "24", "3", // row values
066:                        "29", "29", // D, B group footers
067:                        "C", "D", // group headers
068:                        "12", "42", // row values
069:                        "54", "54", "83", // D, C, A group footers
070:                        "83" }; // report footer
071:                runTest("sum", expected);
072:            }
073:
074:            public void testMin() throws IOException, FileNotFoundException {
075:                String[] expected = { "A", "B", "D", "2", "24", "3", "2", "2",
076:                        "C", "D", "12", "42", "12", "12", "2", "2" };
077:                runTest("min", expected);
078:            }
079:
080:            public void testMax() throws IOException, FileNotFoundException {
081:                String[] expected = { "A", "B", "D", "2", "24", "3", "24",
082:                        "24", "C", "D", "12", "42", "42", "42", "42", "42" };
083:
084:                runTest("max", expected);
085:            }
086:
087:            public void testCount() throws IOException, FileNotFoundException {
088:                String[] expected = { "A", "B", "D", "2", "24", "3", "3", "3",
089:                        "C", "D", "12", "42", "2", "2", "5", "5" };
090:                runTest("count", expected);
091:            }
092:
093:            public void testAverage() throws IOException, FileNotFoundException {
094:                String[] expected = { "A", "B", "D", "2", "24", "3", "9.67",
095:                        "9.67", "C", "D", "12", "42", "27", "27", "16.6",
096:                        "16.6" };
097:                runTest("average", expected);
098:            }
099:
100:            public void testStddev() throws IOException, FileNotFoundException {
101:                String[] expected = { "A", "B", "D", "2", "24", "3", "12.42",
102:                        "12.42", "C", "D", "12", "42", "21.21", "21.21",
103:                        "16.73", "16.73" };
104:                runTest("stddev", expected);
105:            }
106:
107:            public void runTest(String funcName, String[] expected)
108:                    throws IOException, FileNotFoundException {
109:                setAggregateFieldFunction(funcName);
110:
111:                // Running the report closes the output stream.
112:                report.runReport();
113:                BufferedReader in = new BufferedReader(new FileReader(OUT_FILE));
114:
115:                for (int i = 0; i < expected.length; ++i)
116:                    expect(i, expected[i], in);
117:
118:                String noMoreData = in.readLine();
119:                assertNull("extra data in output, starting at line "
120:                        + expected.length + ": " + noMoreData, noMoreData);
121:                in.close();
122:            }
123:
124:            protected void setAggregateFieldFunction(String function) {
125:                for (Iterator iter = aggrFields.iterator(); iter.hasNext();) {
126:                    AggregateField aggr = (AggregateField) iter.next();
127:                    aggr.setFunction(function);
128:                }
129:            }
130:
131:            protected void expect(int lineNum, String value, BufferedReader in)
132:                    throws IOException {
133:                String line = in.readLine();
134:                assertNotNull("Output is too short; stops after line "
135:                        + lineNum, line);
136:                assertEquals("Line " + (lineNum + 1), value, line);
137:            }
138:
139:            public void testHasParameterFields() {
140:                assertEquals(false, report.hasParameterFields());
141:            }
142:
143:            public static void main(String[] args) {
144:                junit.textui.TestRunner.run(suite());
145:                System.exit(0);
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.