@date 2019年4月30日上午09:58:02 @desc Insert测试类
| 14 | * @desc Insert测试类 |
| 15 | */ |
| 16 | public class InsertTest { |
| 17 | private static final Logger logger = LogManager.getLogger(InsertTest.class); |
| 18 | |
| 19 | private String table; |
| 20 | private String column1; |
| 21 | private String column2; |
| 22 | private String column3; |
| 23 | private String value1; |
| 24 | private String value2; |
| 25 | private String value3; |
| 26 | private String simpleSql; |
| 27 | private String simpleSql2; |
| 28 | private String simpleSql3; |
| 29 | |
| 30 | @Before |
| 31 | public void before() { |
| 32 | // TODO Auto-generated method stub |
| 33 | table = "table1"; |
| 34 | column1 = "column1"; |
| 35 | column2 = "column2"; |
| 36 | column3 = "column3"; |
| 37 | value1 = "1"; |
| 38 | value2 = "'2'"; |
| 39 | value3 = "3"; |
| 40 | simpleSql = "insert into " + table + " values (1)"; |
| 41 | simpleSql2 = "insert into " + table + "(pk) values (1)"; |
| 42 | simpleSql3 = "insert into " + table + " select * from table2"; |
| 43 | } |
| 44 | |
| 45 | @Test |
| 46 | public void testParse() { |
| 47 | try { |
| 48 | Insert insert = Insert.parse(simpleSql); |
| 49 | Assert.assertEquals( |
| 50 | SqlFormatter.format(insert.getSql()), |
| 51 | SqlFormatter.format("INSERT INTO table1 VALUES (1)") |
| 52 | ); |
| 53 | Assert.assertEquals( |
| 54 | SqlFormatter.format(insert.getSql(false)), |
| 55 | SqlFormatter.format("INSERT INTO table1 VALUES (1)") |
| 56 | ); |
| 57 | } catch (Exception e) { |
| 58 | Assert.fail(e.getMessage()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @desc 简单的新增:INSERT INTO table VALUES (1, '2', 3) |
| 64 | */ |
| 65 | @Test |
| 66 | public void testInsertWithValueColumn() { |
| 67 | try { |
| 68 | Insert insert = Insert.parse(simpleSql); |
| 69 | insert.addValueColumn(value1).addValueColumn(value2).addValueColumn(value3); |
| 70 | Assert.assertEquals( |
| 71 | SqlFormatter.format(insert.getSql()), |
| 72 | SqlFormatter.format("INSERT INTO table1 VALUES (1, 1, '2', 3)") |
| 73 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected