Source Code Cross Referenced for FormulaEvalTest.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.layout.CharSepLE;
005:        import jimm.datavision.source.charsep.CharSepSource;
006:        import java.io.*;
007:        import junit.framework.TestCase;
008:        import junit.framework.TestSuite;
009:        import junit.framework.Test;
010:
011:        /**
012:         * Tests formula evals when formulas are hidden or appear multiple
013:         * times.
014:         * <p>
015:         * These tests are tightly coupled with the contents of the files
016:         * <code>eval.xml</code> and <code>eval.csv</code>.
017:         *
018:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
019:         */
020:        public class FormulaEvalTest extends TestCase {
021:
022:            protected static final File EVAL_REPORT = new File(AllTests
023:                    .testDataFile("eval.xml"));
024:            protected static final String EVAL_DATA_FILE = AllTests
025:                    .testDataFile("eval.csv");
026:            protected static final File OUT_FILE = new File(System
027:                    .getProperty("java.io.tmpdir"),
028:                    "datavision_charsep_eval_out.txt");
029:            protected static final File PARAM_INPUT_FILE = new File(AllTests
030:                    .testDataFile("test_parameters.xml"));
031:
032:            protected static final String[] EVAL_RESULTS = { "0", "1\t23.0\t1",
033:                    "1\t44.3\t2", "1\t50.0\t3", "39.1", "0", "2\t33.0\t1",
034:                    "2\t46.0\t2", "39.5" };
035:
036:            protected Report report;
037:            protected CharSepSource dataSource;
038:
039:            public static Test suite() {
040:                return new TestSuite(FormulaEvalTest.class);
041:            }
042:
043:            public FormulaEvalTest(String name) {
044:                super (name);
045:            }
046:
047:            public void setUp() throws Exception {
048:                report = new Report();
049:
050:                OUT_FILE.deleteOnExit();
051:                PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE));
052:                report.setLayoutEngine(new CharSepLE(out, '\t'));
053:
054:                report.read(EVAL_REPORT); // Must come after setting password
055:
056:                dataSource = (CharSepSource) report.getDataSource();
057:                dataSource.setSepChar(',');
058:                dataSource.setInput(EVAL_DATA_FILE);
059:            }
060:
061:            public void tearDown() {
062:                if (OUT_FILE.exists())
063:                    OUT_FILE.delete();
064:            }
065:
066:            public void testEvalAllVisible() throws FileNotFoundException,
067:                    IOException {
068:                runEvalTest(null);
069:            }
070:
071:            public void testEvalDetalInvisible() throws FileNotFoundException,
072:                    IOException {
073:                // Make detail formula field invisible.
074:                report.findField("2").setVisible(false);
075:
076:                runEvalTest(new ExpectedLineModifier() {
077:                    String expected(String str) {
078:                        int pos = str.lastIndexOf("\t");
079:                        return (pos != -1) ? str = str.substring(0, pos) : str;
080:                    }
081:                });
082:            }
083:
084:            public void testEvalHeaderInvisible() throws IOException,
085:                    FileNotFoundException {
086:                // Make detail formula field invisible.
087:                report.findField("1").setVisible(false);
088:
089:                runEvalTest(new ExpectedLineModifier() {
090:                    String expected(String str) {
091:                        return ("0".equals(str)) ? "" : str;
092:                    }
093:                });
094:            }
095:
096:            public void testGroupHeaderInvisible()
097:                    throws FileNotFoundException, IOException {
098:                // Make detail formula field invisible.
099:                Section s = report.findField("1").getSection();
100:                s.getSuppressionProc().setHidden(true);
101:
102:                runEvalTest(new ExpectedLineModifier() {
103:                    String expected(String str) {
104:                        return ("0".equals(str)) ? null : str;
105:                    }
106:                });
107:            }
108:
109:            public void testParamInSuppressionProc()
110:                    throws FileNotFoundException, IOException {
111:                // We only need one parameter. This array of parameters is only
112:                // necessary because the parameter file contains data for parameters
113:                // with ids 1 - 6.
114:                Parameter[] params = new Parameter[6];
115:                for (int i = 0; i < 6; ++i) {
116:                    params[i] = new Parameter(new Long(i + 1), report,
117:                            "string", "str param", "what do YOU want?",
118:                            "single");
119:                    report.addParameter(params[i]);
120:                }
121:
122:                report.setParameterXMLInput(PARAM_INPUT_FILE);
123:
124:                // Find detail section
125:                Section detail = report.findField("100").getSection();
126:                Formula f = detail.getSuppressionProc().getFormula();
127:                f.setExpression("\"{?1}\" == 'never'");
128:
129:                runEvalTest(null);
130:
131:                // Make sure parameter's value has been read in. Thus we prove that the
132:                // report recognized the parameter was used in the detail section's
133:                // suppression proc.
134:                Parameter p = report.findParameter(new Long(1));
135:                assertNotNull(p);
136:                assertEquals("Chicago", p.getValue());
137:            }
138:
139:            void runEvalTest(ExpectedLineModifier elm)
140:                    throws FileNotFoundException, IOException {
141:                // Run report in this thread, not a separate one. Running the
142:                // report closes the output stream.
143:                report.runReport();
144:
145:                // Open the output and look for various things.
146:                BufferedReader out = new BufferedReader(
147:                        new FileReader(OUT_FILE));
148:
149:                // Check output file contents
150:                String outLine;
151:                for (int lineNum = 0; lineNum < EVAL_RESULTS.length
152:                        && (outLine = out.readLine()) != null; ++lineNum) {
153:                    String expected = EVAL_RESULTS[lineNum];
154:                    if (elm == null)
155:                        expected = EVAL_RESULTS[lineNum];
156:                    else
157:                        expected = elm.expected(EVAL_RESULTS[lineNum]);
158:                    while (expected == null) {
159:                        ++lineNum;
160:                        expected = EVAL_RESULTS[lineNum];
161:                        expected = elm.expected(EVAL_RESULTS[lineNum]);
162:                    }
163:                    assertEquals(expected, outLine);
164:                }
165:
166:                // Make sure we are at the end of the file.
167:                assertNull(out.readLine());
168:
169:                out.close();
170:            }
171:
172:            public static void main(String[] args) {
173:                junit.textui.TestRunner.run(suite());
174:                System.exit(0);
175:            }
176:
177:            // ================================================================
178:            /**
179:             * Lets us modify the &quot;standard&quot; expected results to match
180:             * a particular test's output.
181:             */
182:            abstract class ExpectedLineModifier {
183:                /**
184:                 * Given the &quot;standard&quot; expected value, returns the expected
185:                 * text for a particular test. If we return <code>null</code> that means
186:                 * the input line should be skipped.
187:                 */
188:                abstract String expected(String str);
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.