Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengguanLi committed Nov 26, 2024
1 parent 4e11e91 commit ff52956
Showing 1 changed file with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,60 @@ public void test_0() throws Exception {
System.out.println("orderBy : " + visitor.getOrderByColumns());

Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getConditions().size());
Assert.assertEquals(0, visitor.getRelationships().size());

Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dept_temp")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("dept_temp", "department_id")));
}

public void test_1() throws Exception {
String sql = "CREATE OR REPLACE PROCEDURE p (" +
" dept_no NUMBER" +
") AS " +
"BEGIN" +
" DELETE FROM dept_temp" +
" WHERE department_id = dept_no;" +
" " +
" IF SQL%NOTFOUND THEN" +
" DBMS_OUTPUT.PUT_LINE (" +
" 'No department number');" +
" ELSE" +
" DBMS_OUTPUT.PUT_LINE ('Delete succeeded for department number');" +
" END IF;" +
"END;" +
"/" +
"BEGIN" +
" p(270);" +
" p(400);" +
"END;"; //

OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
print(statementList);

Assert.assertEquals(3, statementList.size());

OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
for (SQLStatement statement : statementList) {
statement.accept(visitor);
}

System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());

Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getConditions().size());
Assert.assertEquals(0, visitor.getRelationships().size());

// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("employees", "salary")));
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dept_temp")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("dept_temp", "department_id")));
}
}

0 comments on commit ff52956

Please sign in to comment.