提交 80bfedba authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved code coverage

上级 fc1cac79
......@@ -201,22 +201,21 @@ public class DbContents {
ArrayList<String> schemaList = New.arrayList();
while (rs.next()) {
String schema = rs.getString(findColumn(rs, "TABLE_SCHEM", 1));
String[] ignoreNames = null;
if (isOracle) {
for (String ignore : new String[] {
"CTXSYS", "DIP", "DBSNMP", "DMSYS", "EXFSYS", "FLOWS_020100", "FLOWS_FILES", "MDDATA", "MDSYS",
"MGMT_VIEW", "OLAPSYS", "ORDSYS", "ORDPLUGINS", "OUTLN", "SI_INFORMTN_SCHEMA", "SYS", "SYSMAN",
"SYSTEM", "TSMSYS", "WMSYS", "XDB"
}) {
if (ignore.equals(schema)) {
schema = null;
break;
}
}
ignoreNames = new String[] { "CTXSYS", "DIP", "DBSNMP",
"DMSYS", "EXFSYS", "FLOWS_020100", "FLOWS_FILES",
"MDDATA", "MDSYS", "MGMT_VIEW", "OLAPSYS", "ORDSYS",
"ORDPLUGINS", "OUTLN", "SI_INFORMTN_SCHEMA", "SYS",
"SYSMAN", "SYSTEM", "TSMSYS", "WMSYS", "XDB" };
} else if (isMSSQLServer) {
for (String ignore : new String[] {
"sys", "db_accessadmin", "db_backupoperator", "db_datareader", "db_datawriter", "db_ddladmin",
"db_denydatareader", "db_denydatawriter", "db_owner", "db_securityadmin"
}) {
ignoreNames = new String[] { "sys", "db_accessadmin",
"db_backupoperator", "db_datareader", "db_datawriter",
"db_ddladmin", "db_denydatareader",
"db_denydatawriter", "db_owner", "db_securityadmin" };
}
if (ignoreNames != null) {
for (String ignore : ignoreNames) {
if (ignore.equals(schema)) {
schema = null;
break;
......
......@@ -50,6 +50,7 @@ public class TestWeb extends TestBase {
testStartWebServerWithConnection();
testServer();
testWebApp();
testIfExists();
}
private static void testWrongParameters() {
......@@ -199,6 +200,31 @@ public class TestWeb extends TestBase {
server.stop();
}
private void testIfExists() throws Exception {
Connection conn = getConnection("jdbc:h2:mem:webExists", getUser(), getPassword());
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-ifExists", "-web", "-webPort", "8182", "-properties", "null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "login.jsp");
result = client.get(url, "test.do?driver=org.h2.Driver&url=jdbc:h2:mem:webExists" +
"&user=" + getUser() + "&password=" + getPassword() + "&name=_test_");
assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "test.do?driver=org.h2.Driver&url=jdbc:h2:mem:web" +
"&user=" + getUser() + "&password=" + getPassword() + "&name=_test_");
assertContains(result, "Exception");
} finally {
server.shutdown();
conn.close();
}
}
private void testWebApp() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
......
......@@ -35,16 +35,22 @@ public class TestBnf extends TestBase {
@Override
public void test() throws Exception {
deleteDb("TestBnf");
Connection conn = getConnection("TestBnf");
deleteDb("bnf");
Connection conn = getConnection("bnf");
try {
testProcedures(conn);
testProcedures(conn, false);
} finally {
conn.close();
}
conn = getConnection("bnf;mode=mysql");
try {
testProcedures(conn, true);
} finally {
conn.close();
}
}
private void testProcedures(Connection conn) throws Exception {
private void testProcedures(Connection conn, boolean isMySQLMode) throws Exception {
// Register a procedure and check if it is present in DbContents
conn.createStatement().execute("DROP ALIAS IF EXISTS CUSTOM_PRINT");
conn.createStatement().execute("CREATE ALIAS CUSTOM_PRINT AS $$ void print(String s) { System.out.println(s); } $$");
......@@ -52,13 +58,42 @@ public class TestBnf extends TestBase {
conn.createStatement().execute("CREATE TABLE TABLE_WITH_STRING_FIELD (STRING_FIELD VARCHAR(50), INT_FIELD integer)");
DbContents dbContents = new DbContents();
dbContents.readContents(conn.getMetaData());
assertTrue(dbContents.isH2());
assertFalse(dbContents.isDerby());
assertFalse(dbContents.isFirebird());
assertEquals(null, dbContents.quoteIdentifier(null));
if (isMySQLMode) {
assertTrue(dbContents.isH2ModeMySQL());
assertEquals("TEST", dbContents.quoteIdentifier("TEST"));
assertEquals("TEST", dbContents.quoteIdentifier("Test"));
assertEquals("TEST", dbContents.quoteIdentifier("test"));
} else {
assertFalse(dbContents.isH2ModeMySQL());
assertEquals("TEST", dbContents.quoteIdentifier("TEST"));
assertEquals("\"Test\"", dbContents.quoteIdentifier("Test"));
assertEquals("\"test\"", dbContents.quoteIdentifier("test"));
}
assertFalse(dbContents.isMSSQLServer());
assertFalse(dbContents.isMySQL());
assertFalse(dbContents.isOracle());
assertFalse(dbContents.isPostgreSQL());
assertFalse(dbContents.isSQLite());
DbSchema defaultSchema = dbContents.getDefaultSchema();
DbProcedure[] procedures = defaultSchema.getProcedures();
Set<String> procedureName = new HashSet<String>(procedures.length);
for (DbProcedure procedure : procedures) {
assertTrue(defaultSchema == procedure.getSchema());
procedureName.add(procedure.getName());
}
if (isMySQLMode) {
assertTrue(procedureName.contains("custom_print"));
} else {
assertTrue(procedureName.contains("CUSTOM_PRINT"));
}
if (isMySQLMode) {
return;
}
// Test completion
Bnf bnf = Bnf.getInstance(null);
......@@ -69,6 +104,7 @@ public class TestBnf extends TestBase {
// Test partial
Map<String, String> tokens = bnf.getNextTokenList("SELECT CUSTOM_PR");
assertTrue(tokens.values().contains("INT"));
// Test parameters
tokens = bnf.getNextTokenList("SELECT CUSTOM_PRINT(");
assertTrue(tokens.values().contains("STRING_FIELD"));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论