01: package com.mockrunner.test.jdbc;
02:
03: import java.io.File;
04:
05: import junit.framework.TestCase;
06:
07: import com.mockrunner.jdbc.XMLResultSetFactory;
08: import com.mockrunner.mock.jdbc.MockResultSet;
09:
10: public class XMLResultSetFactoryTest extends TestCase {
11: /**
12: * Test for the Sybase Dialect of the XMLResultSetFactory
13: */
14: public void testSybaseCreate() {
15: XMLResultSetFactory goodSybaseXMLRSF = new XMLResultSetFactory(
16: "src/com/mockrunner/test/jdbc/xmltestresult.xml");
17: MockResultSet goodMRS = goodSybaseXMLRSF
18: .create("Good-ResultSet-ID");
19: assertNotNull(goodSybaseXMLRSF.getXMLFile());
20: doTestGoodResultSet(goodSybaseXMLRSF, goodMRS);
21:
22: goodSybaseXMLRSF = new XMLResultSetFactory(
23: "/com/mockrunner/test/jdbc/xmltestresult.xml");
24: goodMRS = goodSybaseXMLRSF.create("Good-ResultSet-ID");
25: assertNotNull(goodSybaseXMLRSF.getXMLFile());
26: doTestGoodResultSet(goodSybaseXMLRSF, goodMRS);
27:
28: goodSybaseXMLRSF = new XMLResultSetFactory(new File(
29: "src/com/mockrunner/test/jdbc/xmltestresult.xml"));
30: goodMRS = goodSybaseXMLRSF.create("Good-ResultSet-ID");
31: assertNotNull(goodSybaseXMLRSF.getXMLFile());
32: doTestGoodResultSet(goodSybaseXMLRSF, goodMRS);
33: }
34:
35: private void doTestGoodResultSet(
36: XMLResultSetFactory goodSybaseXMLRSF, MockResultSet goodMRS) {
37: assertEquals("Dialects should be equal!",
38: XMLResultSetFactory.SYBASE_DIALECT, goodSybaseXMLRSF
39: .getDialect());
40: assertEquals("There should be 2 columns!", 2, goodMRS
41: .getColumnCount());
42: assertEquals("There should be 3 rows!", 3, goodMRS
43: .getRowCount());
44: }
45:
46: /**
47: * Test for a bad create where there is no actual file
48: * passed to the XMLResultSetFactory
49: */
50: public void testBadCreate() {
51: try {
52: XMLResultSetFactory badXMLRSF = new XMLResultSetFactory(
53: "src/com/mockrunner/test/jdbc/nonexisting.xml");
54: assertNull(badXMLRSF.getXMLFile());
55: badXMLRSF.create("Bad-ResultSet-ID");
56: fail();
57: } catch (RuntimeException exc) {
58: //should throw exception
59: }
60: try {
61: XMLResultSetFactory badXMLRSF = new XMLResultSetFactory(
62: new File(
63: "src/com/mockrunner/test/jdbc/nonexisting.xml"));
64: assertNull(badXMLRSF.getXMLFile());
65: badXMLRSF.create("Bad-ResultSet-ID");
66: fail();
67: } catch (RuntimeException exc) {
68: //should throw exception
69: }
70: }
71:
72: public void testGetXMLFile() {
73: XMLResultSetFactory factory = new XMLResultSetFactory(
74: "src/com/mockrunner/test/jdbc/xmltestresult.xml");
75: assertEquals(new File(
76: "src/com/mockrunner/test/jdbc/xmltestresult.xml"),
77: factory.getXMLFile());
78: factory = new XMLResultSetFactory(new File(
79: "src/com/mockrunner/test/jdbc/xmltestresult.xml"));
80: assertEquals(new File(
81: "src/com/mockrunner/test/jdbc/xmltestresult.xml"),
82: factory.getXMLFile());
83: factory = new XMLResultSetFactory("badfile");
84: try {
85: factory.getXMLFile();
86: fail();
87: } catch (RuntimeException exc) {
88: //should throw exception
89: }
90: factory = new XMLResultSetFactory(new File("badfile"));
91: try {
92: factory.getXMLFile();
93: fail();
94: } catch (RuntimeException exc) {
95: //should throw exception
96: }
97: }
98: }
|