|
| 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 | +} |
0 commit comments