01: package jimm.datavision.test;
02:
03: import jimm.datavision.*;
04: import jimm.datavision.source.Column;
05: import jimm.datavision.test.mock.source.MockDataSource;
06: import java.io.File;
07: import junit.framework.TestCase;
08: import junit.framework.TestSuite;
09: import junit.framework.Test;
10:
11: /**
12: * Some tests for BSF {@link Scripting}.
13: *
14: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
15: */
16: public class ScriptingTest extends TestCase {
17:
18: protected static final File EXAMPLE_REPORT = new File(AllTests
19: .testDataFile("test.xml"));
20: protected static final String VALUE_REPORT = AllTests
21: .testDataFile("value.xml");
22:
23: protected Report report;
24:
25: public static Test suite() {
26: return new TestSuite(ScriptingTest.class);
27: }
28:
29: public ScriptingTest(String name) {
30: super (name);
31: }
32:
33: public void setUp() {
34: report = new Report();
35: report.setDataSource(new MockDataSource(report));
36: }
37:
38: public void testReportObject() {
39: report.setTitle("foo");
40: Formula f = new Formula(new Long(0), report,
41: "test report access");
42: f.setEditableExpression("$report.getTitle()");
43: assertEquals("foo", f.eval(null));
44:
45: f.setEditableExpression("$report.title");
46: assertEquals("foo", f.eval(null));
47: }
48:
49: public void testColumnAccess() throws Exception {
50: report.read(EXAMPLE_REPORT);
51:
52: Formula f = report.findFormula("1");
53: f
54: .setEditableExpression("$report.findColumn('jobs.hourly rate')");
55:
56: Object result = f.eval(null);
57: assertNotNull(result);
58: assertEquals("jimm.datavision.source.Column", result.getClass()
59: .getName());
60: assertTrue(result instanceof Column);
61: assertEquals("jobs.hourly rate", ((Column) result).getId()
62: .toString());
63: }
64:
65: public static void main(String[] args) {
66: junit.textui.TestRunner.run(suite());
67: System.exit(0);
68: }
69:
70: }
|