1 /*
2 * Replica is published under the terms
3 * of the Apache Software License.
4 */
5 package replica.server.mvc;
6
7 import java.sql.Connection;
8 import java.sql.DriverManager;
9 import java.sql.ResultSet;
10 import java.sql.SQLException;
11 import java.sql.Statement;
12
13 import org.hsqldb.Server;
14
15 import junit.framework.TestCase;
16
17 /***
18 *
19 * @author Pedro Costa
20 * @author Helder Silva
21 * @since 1/Fev/2004
22 */
23 public class TableViewTest extends TestCase {
24
25 Server server;
26 Connection con;
27
28 String testTableName = "test";
29
30 String result = "|ID |NOME |( |\n" +
31 "|-----------+-----+---|\n"+
32 "| 1|pedro| |\n";
33
34 /***
35 * Constructor for TableViewTest.
36 * @param name
37 */
38 public TableViewTest(String name) {
39 super(name);
40 }
41
42 /*
43 * @see TestCase#setUp()
44 */
45 protected void setUp() throws Exception {
46 super.setUp();
47
48 server = new Server();
49 server.putPropertiesFromString("database.0=.");
50 server.setPort(9015);
51 server.start();
52
53 try{ Thread.sleep(500); }catch(InterruptedException e){ }
54
55 Class.forName("org.hsqldb.jdbcDriver").newInstance();
56
57 con = DriverManager.getConnection("jdbc:hsqldb:.://localhost:9015","sa","");
58
59 createTestingData();
60 }
61
62 void createTestingData() throws SQLException{
63
64 Statement st = con.createStatement();
65
66 st.execute("drop table " + testTableName + " if exists;");
67
68 st.execute("create table " + testTableName + " (id integer primary key, nome varchar );");
69
70 st.execute("insert into " + testTableName + " values ( 1, 'pedro' );");
71
72 con.commit();
73
74 st.execute("alter table " + testTableName + " add ( varchar;");
75
76 st.close();
77 }
78
79 /*
80 * @see TestCase#tearDown()
81 */
82 protected void tearDown() throws Exception {
83 super.tearDown();
84
85 try{ con.close(); }catch(Throwable t){}
86 try{ server.stop(); }catch(Throwable t){}
87 }
88
89 public void testRender() throws SQLException{
90
91 ResultSet rs = con.createStatement().executeQuery("select * from " + testTableName +";");
92
93 Object res = new TableView().render(rs);
94
95 assertNotNull( res );
96
97 assertEquals(result, res.toString());
98 }
99
100 }
This page was automatically generated by Maven