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