-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test for wrong table #48
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,35 @@ void testSimpleSchemaProvider() throws JSQLParserException, SQLException { | |
.isEqualTo(new String[] {res.getTableName(6), res.getColumnName(6)}); | ||
} | ||
|
||
@Test | ||
void testWithWrongTable() { | ||
JdbcMetaData metaData = new JdbcMetaData("", "") | ||
.addTable("a", new JdbcColumn("col1"), new JdbcColumn("col2"), new JdbcColumn("col3")) | ||
.addTable("b", new JdbcColumn("col1"), new JdbcColumn("col2"), new JdbcColumn("col3")); | ||
|
||
//should be exception because bb table is not exist | ||
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select * from a where a.col1 in (select bb.col1 from bb)", metaData)); | ||
} | ||
|
||
@Test | ||
void testWithWrongTable1() { | ||
JdbcMetaData metaData = new JdbcMetaData("", "") | ||
.addTable("foo", new JdbcColumn("id"), new JdbcColumn("name")); | ||
|
||
//should be exception because foo1 table is not exist | ||
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select sum(foo1.id) from foo group by foo.name", metaData)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please:
|
||
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select avg(foo1.id) from foo group by foo.name", metaData)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Literally the same tests. |
||
} | ||
|
||
@Test | ||
void testWithWrongColumn() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not throw any exception because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we throw exception if we use "wrong" name of column. But why "wrong" table name should have other behavior |
||
JdbcMetaData metaData = new JdbcMetaData("", "") | ||
.addTable("foo", new JdbcColumn("id"), new JdbcColumn("name")); | ||
|
||
//should be exception because name1 column is not exist | ||
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select count(foo.id) from foo group by foo.name having foo.name1 = 'test'", metaData)); | ||
} | ||
|
||
@Test | ||
void testSimplerSchemaProvider() throws JSQLParserException, SQLException { | ||
JdbcMetaData metaData = new JdbcMetaData().addTable("a", "col1", "col2", "col3").addTable("b", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSQLParserException
is very generic and can mean anything.If you want to make this test meaniningful then please check if Table
bb
is pointed out and blamed correctly.