1 package net.jaekl.cfb.db;
3 import static org.junit.Assert.*;
5 import java.io.ByteArrayInputStream;
6 import java.io.FileNotFoundException;
7 import java.io.IOException;
8 import java.sql.SQLException;
11 import net.jaekl.cfb.analyze.MessageMap;
12 import net.jaekl.cfb.db.driver.ConnectionMock;
13 import net.jaekl.cfb.db.driver.DbDriverMock;
14 import net.jaekl.cfb.xml.MessagesXmlData;
16 import org.junit.Test;
17 import org.xml.sax.InputSource;
18 import org.xml.sax.SAXException;
20 public class CfbSchemaTest {
22 public void testEnsureDbInitialized() throws SQLException, FileNotFoundException, IOException, SAXException {
24 DbDriverMock dbDriver;
26 con = new ConnectionMock();
27 dbDriver = new DbDriverMock();
28 schema = new CfbSchema(dbDriver);
30 MessageMap msgMap = new MessageMap();
31 msgMap.parse(new InputSource(new ByteArrayInputStream(MessagesXmlData.XML.getBytes("UTF-8"))));
33 schema.setMessageMap(msgMap);
34 schema.ensureDbInitialized(con);
36 for (Table table : CfbSchema.TABLES) {
37 assertTablePresent(con, dbDriver, table);
41 private void assertTablePresent(ConnectionMock con, DbDriverMock dbDriver, Table table)
44 Column[] columns = new Column[table.getNumColumns()];
45 Table[] tables = new Table[] { table };
47 for (int i = 0; i < table.getNumColumns(); ++i) {
48 columns[i] = table.getColumn(i);
50 List<Row> result = dbDriver.select(con, columns, tables, null);
51 assertNotNull(result);