forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresNamedFunctionParameterTest.java
More file actions
96 lines (83 loc) · 3.22 KB
/
PostgresNamedFunctionParameterTest.java
File metadata and controls
96 lines (83 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitorAdapter;
import net.sf.jsqlparser.test.TestUtils;
import net.sf.jsqlparser.util.TablesNamesFinder;
import net.sf.jsqlparser.util.validation.ValidationTestAsserts;
import net.sf.jsqlparser.util.validation.feature.DatabaseType;
import net.sf.jsqlparser.util.validation.validator.ExpressionValidator;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class PostgresNamedFunctionParameterTest {
/**
* This test will parse and deparse the statement and assures the functional coverage by
* JSQLParser.
*
* @throws JSQLParserException
*/
@Test
public void testExpression() throws JSQLParserException {
String sqlStr =
"SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World')";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
/**
* This test will trigger the method {@link ExpressionVisitorAdaptor#visit() Visit Method} in
* the ExpressionVisitorAdaptor needed for the Code Coverage.
*
* @throws JSQLParserException
*/
@Test
public void testExpressionVisitorAdaptor() throws JSQLParserException {
String sqlStr =
"SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World')";
CCJSqlParserUtil.parse(sqlStr).accept(new StatementVisitorAdapter());
// alternatively, for the Expression only
CCJSqlParserUtil.parseExpression("a := 'Hello'").accept(new ExpressionVisitorAdapter(),
null);
}
/**
* This test will trigger the method {@link TableNamesFinder#visit() Visit Method} in the
* TableNamesFinder needed for the Code Coverage.
*
* @throws JSQLParserException
*/
@Test
public void testTableNamesFinder() throws JSQLParserException {
String sqlStr =
"SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World') FROM test_table";
Statement statement = CCJSqlParserUtil.parse(sqlStr);
List<String> tables = new TablesNamesFinder<>().getTableList(statement);
assertEquals(1, tables.size());
assertTrue(tables.contains("test_table"));
}
/**
* This test will trigger the method {@link ExpressionValidator#visit() Visit Method} in the
* ExpressionValidator needed for the Code Coverage.
*
* @throws JSQLParserException
*/
@Test
public void testValidator() throws JSQLParserException {
String sqlStr =
"SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World') FROM test_table";
ValidationTestAsserts.validateNoErrors(sqlStr, 1, DatabaseType.POSTGRESQL);
}
}