2017-05-27 23:54:22 -04:00
|
|
|
package com.moparisthebest.jdbc.codegen;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mopar on 5/30/17.
|
|
|
|
*/
|
2017-05-28 22:14:30 -04:00
|
|
|
public class SimpleSQLParserTest {
|
2017-05-27 23:54:22 -04:00
|
|
|
|
|
|
|
private final SQLParser factory = new SimpleSQLParser();
|
|
|
|
|
2017-05-28 22:14:30 -04:00
|
|
|
public SQLParser getFactory() {
|
|
|
|
return factory;
|
|
|
|
}
|
|
|
|
|
2017-05-27 23:54:22 -04:00
|
|
|
@Test
|
|
|
|
public void testSingleSelect() {
|
2017-05-28 22:14:30 -04:00
|
|
|
final SQLParser ret = getFactory().parse("select bob from tom");
|
2017-05-27 23:54:22 -04:00
|
|
|
assertTrue(ret.isSelect());
|
|
|
|
assertArrayEquals(new String[]{null, "BOB"}, ret.columnNames());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMultiSelect() {
|
|
|
|
final String[] expected = new String[]{null, "BOB", "TOM"};
|
|
|
|
for (final String sql : new String[]{
|
|
|
|
"select bob, tom from tom"
|
|
|
|
, "select some_bob bob, some_tom as tom from tom"
|
|
|
|
, "select tom.bob, some_tom as tom from tom"
|
|
|
|
}) {
|
2017-05-28 22:14:30 -04:00
|
|
|
final SQLParser ret = getFactory().parse(sql);
|
2017-05-27 23:54:22 -04:00
|
|
|
assertTrue(ret.isSelect());
|
|
|
|
assertArrayEquals(expected, ret.columnNames());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNotSelect() {
|
|
|
|
for (final String sql : new String[]{
|
|
|
|
"UPDATE bob SET bob = 'bob' WHERE bob_no = 1"
|
|
|
|
, "INSERT INTO bob (bob_no, bob) VALUES (1, 'bob')"
|
|
|
|
, "MERGE INTO bob bla bla bla"
|
|
|
|
}) {
|
2017-05-28 22:14:30 -04:00
|
|
|
final SQLParser ret = getFactory().parse(sql);
|
2017-05-27 23:54:22 -04:00
|
|
|
assertFalse(ret.isSelect());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|