|
1 | | -package net.sf.jsqlparser.statement.comment; |
2 | | - |
3 | | -import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; |
4 | | -import static org.junit.Assert.assertEquals; |
5 | | - |
6 | | -import java.io.StringReader; |
7 | | - |
8 | | -import net.sf.jsqlparser.JSQLParserException; |
9 | | -import net.sf.jsqlparser.parser.CCJSqlParserManager; |
10 | | -import net.sf.jsqlparser.schema.Column; |
11 | | -import net.sf.jsqlparser.schema.Table; |
12 | | - |
13 | | -import org.junit.Test; |
14 | | - |
15 | | -public class CommentTest { |
16 | | - |
17 | | - private final CCJSqlParserManager parserManager = new CCJSqlParserManager(); |
18 | | - |
19 | | - @Test |
20 | | - public void testCommentTable() throws JSQLParserException { |
21 | | - String statement = "COMMENT ON TABLE table1 IS 'comment1'"; |
22 | | - Comment comment = (Comment) parserManager.parse(new StringReader(statement)); |
23 | | - Table table = comment.getTable(); |
24 | | - assertEquals("table1", table.getName()); |
25 | | - assertEquals("comment1", comment.getComment().getValue()); |
26 | | - assertEquals(statement, "" + comment); |
27 | | - } |
28 | | - |
29 | | - @Test |
30 | | - public void testCommentTable2() throws JSQLParserException { |
31 | | - String statement = "COMMENT ON TABLE schema1.table1 IS 'comment1'"; |
32 | | - Comment comment = (Comment) parserManager.parse(new StringReader(statement)); |
33 | | - Table table = comment.getTable(); |
34 | | - assertEquals("schema1", table.getSchemaName()); |
35 | | - assertEquals("table1", table.getName()); |
36 | | - assertEquals("comment1", comment.getComment().getValue()); |
37 | | - assertEquals(statement, "" + comment); |
38 | | - } |
39 | | - |
40 | | - @Test |
41 | | - public void testCommentTableDeparse() throws JSQLParserException { |
42 | | - String statement = "COMMENT ON TABLE table1 IS 'comment1'"; |
43 | | - assertSqlCanBeParsedAndDeparsed(statement); |
44 | | - } |
45 | | - |
46 | | - @Test |
47 | | - public void testCommentColumn() throws JSQLParserException { |
48 | | - String statement = "COMMENT ON COLUMN table1.column1 IS 'comment1'"; |
49 | | - Comment comment = (Comment) parserManager.parse(new StringReader(statement)); |
50 | | - Column column = comment.getColumn(); |
51 | | - assertEquals("table1", column.getTable().getName()); |
52 | | - assertEquals("column1", column.getColumnName()); |
53 | | - assertEquals("comment1", comment.getComment().getValue()); |
54 | | - assertEquals(statement, "" + comment); |
55 | | - } |
56 | | - |
57 | | - @Test |
58 | | - public void testCommentColumnDeparse() throws JSQLParserException { |
59 | | - String statement = "COMMENT ON COLUMN table1.column1 IS 'comment1'"; |
60 | | - assertSqlCanBeParsedAndDeparsed(statement); |
61 | | - } |
62 | | - |
63 | | - @Test |
64 | | - public void testToString() { |
65 | | - Comment comment = new Comment(); |
66 | | - assertEquals("COMMENT ON IS null", comment.toString()); |
67 | | - } |
68 | | -} |
| 1 | +package net.sf.jsqlparser.statement.comment; |
| 2 | + |
| 3 | +import java.io.StringReader; |
| 4 | +import net.sf.jsqlparser.JSQLParserException; |
| 5 | +import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
| 6 | +import net.sf.jsqlparser.schema.Column; |
| 7 | +import net.sf.jsqlparser.schema.Table; |
| 8 | +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; |
| 9 | +import static org.junit.Assert.assertEquals; |
| 10 | +import org.junit.Test; |
| 11 | + |
| 12 | +public class CommentTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void testCommentTable() throws JSQLParserException { |
| 16 | + String statement = "COMMENT ON TABLE table1 IS 'comment1'"; |
| 17 | + Comment comment = (Comment) CCJSqlParserUtil.parse(new StringReader(statement)); |
| 18 | + Table table = comment.getTable(); |
| 19 | + assertEquals("table1", table.getName()); |
| 20 | + assertEquals("comment1", comment.getComment().getValue()); |
| 21 | + assertEquals(statement, "" + comment); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void testCommentTable2() throws JSQLParserException { |
| 26 | + String statement = "COMMENT ON TABLE schema1.table1 IS 'comment1'"; |
| 27 | + Comment comment = (Comment) CCJSqlParserUtil.parse(new StringReader(statement)); |
| 28 | + Table table = comment.getTable(); |
| 29 | + assertEquals("schema1", table.getSchemaName()); |
| 30 | + assertEquals("table1", table.getName()); |
| 31 | + assertEquals("comment1", comment.getComment().getValue()); |
| 32 | + assertEquals(statement, "" + comment); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testCommentTableDeparse() throws JSQLParserException { |
| 37 | + String statement = "COMMENT ON TABLE table1 IS 'comment1'"; |
| 38 | + assertSqlCanBeParsedAndDeparsed(statement); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testCommentColumn() throws JSQLParserException { |
| 43 | + String statement = "COMMENT ON COLUMN table1.column1 IS 'comment1'"; |
| 44 | + Comment comment = (Comment) CCJSqlParserUtil.parse(new StringReader(statement)); |
| 45 | + Column column = comment.getColumn(); |
| 46 | + assertEquals("table1", column.getTable().getName()); |
| 47 | + assertEquals("column1", column.getColumnName()); |
| 48 | + assertEquals("comment1", comment.getComment().getValue()); |
| 49 | + assertEquals(statement, "" + comment); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testCommentColumnDeparse() throws JSQLParserException { |
| 54 | + assertSqlCanBeParsedAndDeparsed("COMMENT ON COLUMN table1.column1 IS 'comment1'"); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void testToString() { |
| 59 | + Comment comment = new Comment(); |
| 60 | + assertEquals("COMMENT ON IS null", comment.toString()); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testCommentColumnDeparseIssue696() throws JSQLParserException { |
| 65 | + assertSqlCanBeParsedAndDeparsed("COMMENT ON COLUMN hotels.hotelid IS 'Primary key of the table'"); |
| 66 | + } |
| 67 | +} |
0 commit comments