33import java .io .StringReader ;
44import static junit .framework .Assert .assertEquals ;
55
6- import junit .framework .TestCase ;
76import net .sf .jsqlparser .JSQLParserException ;
87import net .sf .jsqlparser .expression .DoubleValue ;
98import net .sf .jsqlparser .expression .JdbcParameter ;
1716import net .sf .jsqlparser .statement .select .PlainSelect ;
1817import net .sf .jsqlparser .statement .select .SubSelect ;
1918import static net .sf .jsqlparser .test .TestUtils .*;
19+ import static org .junit .Assert .assertTrue ;
20+ import static org .junit .Assert .fail ;
21+ import org .junit .Test ;
2022
21- public class InsertTest extends TestCase {
23+ public class InsertTest {
2224
2325 CCJSqlParserManager parserManager = new CCJSqlParserManager ();
2426
25- public InsertTest (String arg0 ) {
26- super (arg0 );
27- }
28-
27+ @ Test
2928 public void testRegularInsert () throws JSQLParserException {
3029 String statement = "INSERT INTO mytable (col1, col2, col3) VALUES (?, 'sadfsd', 234)" ;
3130 Insert insert = (Insert ) parserManager .parse (new StringReader (statement ));
@@ -52,6 +51,7 @@ public void testRegularInsert() throws JSQLParserException {
5251
5352 }
5453
54+ @ Test
5555 public void testInsertWithKeywordValue () throws JSQLParserException {
5656 String statement = "INSERT INTO mytable (col1) VALUE ('val1')" ;
5757 Insert insert = (Insert ) parserManager .parse (new StringReader (statement ));
@@ -63,6 +63,7 @@ public void testInsertWithKeywordValue() throws JSQLParserException {
6363 assertEquals ("INSERT INTO mytable (col1) VALUES ('val1')" , insert .toString ());
6464 }
6565
66+ @ Test
6667 public void testInsertFromSelect () throws JSQLParserException {
6768 String statement = "INSERT INTO mytable (col1, col2, col3) SELECT * FROM mytable2" ;
6869 Insert insert = (Insert ) parserManager .parse (new StringReader (statement ));
@@ -80,10 +81,12 @@ public void testInsertFromSelect() throws JSQLParserException {
8081 assertEquals (statementToString , "" + insert );
8182 }
8283
84+ @ Test
8385 public void testInsertMultiRowValue () throws JSQLParserException {
8486 assertSqlCanBeParsedAndDeparsed ("INSERT INTO mytable (col1, col2) VALUES (a, b), (d, e)" );
8587 }
8688
89+ @ Test
8790 public void testInsertMultiRowValueDifferent () throws JSQLParserException {
8891 try {
8992 assertSqlCanBeParsedAndDeparsed ("INSERT INTO mytable (col1, col2) VALUES (a, b), (d, e, c)" );
@@ -94,7 +97,23 @@ public void testInsertMultiRowValueDifferent() throws JSQLParserException {
9497 fail ("should not work" );
9598 }
9699
100+ @ Test
97101 public void testSimpleInsert () throws JSQLParserException {
98102 assertSqlCanBeParsedAndDeparsed ("INSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234')" );
99103 }
104+
105+ @ Test
106+ public void testInsertWithReturning () throws JSQLParserException {
107+ assertSqlCanBeParsedAndDeparsed ("INSERT INTO mytable (mycolumn) VALUES ('1') RETURNING id" );
108+ }
109+
110+ @ Test
111+ public void testInsertWithReturning2 () throws JSQLParserException {
112+ assertSqlCanBeParsedAndDeparsed ("INSERT INTO mytable (mycolumn) VALUES ('1') RETURNING *" );
113+ }
114+
115+ @ Test
116+ public void testInsertWithReturning3 () throws JSQLParserException {
117+ assertSqlCanBeParsedAndDeparsed ("INSERT INTO mytable (mycolumn) VALUES ('1') RETURNING id AS a1, id2 AS a2" );
118+ }
100119}
0 commit comments