2
0
Fork 0
imxmi/vasc-backend/vasc-backend-metamodel/src/test/java/BravoTest.java
2012-11-21 20:45:08 +01:00

70 lines
2.2 KiB
Java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import junit.framework.TestCase;
import org.eobjects.metamodel.data.DataSet;
import org.eobjects.metamodel.jdbc.JdbcDataContext;
import org.eobjects.metamodel.schema.Table;
public class BravoTest extends TestCase {
private Connection conn;
@Override
protected void setUp() throws Exception {
super.setUp();
//Class.forName("org.postgresql.Driver");
//conn = DriverManager.getConnection("jdbc:postgresql://localhost/openbravo","postgres","postgresql");
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
//conn.close();
}
public void testDataTypeBoolean() throws Exception {
/*
Statement s = conn.createStatement();
s.executeUpdate("DROP TABLE test_type_bool IF EXISTS;");
s.executeUpdate("CREATE TABLE test_type_bool (id IDENTITY not null primary key,name varchar not null,active boolean not null);");
s.executeUpdate("INSERT INTO test_type_bool VALUES(1,\'name\',true);");
// Test working data first
JdbcDataContext dc = new JdbcDataContext(conn);
Table table = dc.getDefaultSchema().getTableByName("TEST_TYPE_BOOL");
assertNotNull(table);
DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
assertTrue(ds.next());
ds = dc.query().from(table).selectCount().execute();
assertTrue(ds.next());
// Now let it fail
s.executeUpdate("DROP TABLE test_type_bool IF EXISTS;");
s.executeUpdate("CREATE TABLE test_type_bool (id IDENTITY not null primary key,name varchar not null,active boolean not null);");
s.executeUpdate("INSERT INTO test_type_bool VALUES(1,\'\',true);");
// Make sure it works from jdbc driver
Boolean active = null;
s.execute("SELECT * FROM TEST_TYPE_BOOL");
ResultSet rs = s.getResultSet();
while (rs.next()) {
active = rs.getBoolean(3); // this should be same method as exception
}
assertTrue(active);
*/
// Fails on execute.
/*
long startTime = System.currentTimeMillis();
JdbcDataContext dc = new JdbcDataContext(conn);
long stopTime = System.currentTimeMillis();
System.out.println("DC init took: "+(stopTime-startTime)+" ms. for total tables: "+dc.getDefaultSchema().getTableCount());
*/
}
}