MCPcopy Create free account
hub / github.com/Nemo1870/sql-parse / SelectTest

Class SelectTest

src/test/java/com/sql/parse/statement/druid/SelectTest.java:20–606  ·  view source on GitHub ↗

@date 2019年4月29日上午11:20:58·· @desc Select语法单元测试类

Source from the content-addressed store, hash-verified

18 * @desc Select语法单元测试类
19 */
20public class SelectTest {
21 private static final Logger logger = LogManager.getLogger(SelectTest.class);
22
23 private String table1;
24 private String table2;
25 private String column1;
26 private String column2;
27 private String column3;
28 private String simpleSql;
29 private String simpleSql2;
30
31 @Before
32 public void before() {
33 // TODO Auto-generated method stub
34 table1 = "table1";
35 table2 = "table2";
36 column1 = "column1";
37 column2 = "column2";
38 column3 = "column3";
39 simpleSql = "select " + column1 +" from " + table1;
40 simpleSql2 = "select t." + column1 + " from " + table1 + " t";
41 }
42
43 @Test
44 public void testParse() {
45 try {
46 Select select = Select.parse(simpleSql);
47 Assert.assertEquals(
48 SqlFormatter.format(select.getSql()),
49 SqlFormatter.format("SELECT column1 FROM table1 LIMIT 500")
50 );
51 Assert.assertEquals(
52 SqlFormatter.format(select.getSql(false)),
53 SqlFormatter.format("SELECT column1 FROM table1")
54 );
55 } catch (Exception e) {
56 Assert.fail(e.getMessage());
57 }
58 }
59
60 /**
61 * @desc 新增查询列
62 */
63 @Test
64 public void testSelectWithAddColumns() {
65 try {
66 Select select = Select.parse(simpleSql);
67 Assert.assertEquals(
68 SqlFormatter.format(select.getSql()),
69 SqlFormatter.format("SELECT column1 FROM table1 LIMIT 500")
70 );
71 Assert.assertEquals(
72 SqlFormatter.format(select.getSql(false)),
73 SqlFormatter.format("SELECT column1 FROM table1")
74 );
75 select.addColumn(column2).addColumn(column3);
76 Assert.assertEquals(
77 SqlFormatter.format(select.getSql()),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected