MCPcopy Create free account
hub / github.com/Nemo1870/sql-parse / UpdateTest

Class UpdateTest

src/test/java/com/sql/parse/statement/druid/UpdateTest.java:17–205  ·  view source on GitHub ↗

@date 2019年4月30日上午09:58:02 @desc Update测试类

Source from the content-addressed store, hash-verified

15 * @desc Update测试类
16 */
17public class UpdateTest {
18 private static final Logger logger = LogManager.getLogger(UpdateTest.class);
19
20 private String table;
21 private String column1;
22 private String column2;
23 private String column3;
24 private String value1;
25 private String value2;
26 private String simpleSql;
27
28 @Before
29 public void before() {
30 // TODO Auto-generated method stub
31 table = "table";
32 column1 = "column1";
33 column2 = "column2";
34 column3 = "column3";
35 value1 = "1";
36 value2 = "2";
37 simpleSql = "update " + table + " set pk = 1";
38 }
39
40 @Test
41 public void testParse() {
42 try {
43 Update update = Update.parse(simpleSql);
44 Assert.assertEquals(
45 SqlFormatter.format(update.getSql()),
46 SqlFormatter.format("UPDATE table SET pk = 1 WHERE 1 = 2")
47 );
48 Assert.assertEquals(
49 SqlFormatter.format(update.getSql(false)),
50 SqlFormatter.format("UPDATE table SET pk = 1")
51 );
52 } catch (Exception e) {
53 Assert.fail(e.getMessage());
54 }
55 }
56
57 /**
58 * @desc 最简单的更新
59 */
60 @Test
61 public void testSimpleUpdate() {
62 try {
63 Update update = Update.parse(simpleSql);
64 update.addColumn(new UpdateItem(column1, value1));
65 Assert.assertEquals(
66 SqlFormatter.format(update.getSql()),
67 SqlFormatter.format("UPDATE table SET pk = 1, column1 = 1 WHERE 1 = 2")
68 );
69 Assert.assertEquals(
70 SqlFormatter.format(update.getSql(false)),
71 SqlFormatter.format("UPDATE table SET pk = 1, column1 = 1")
72 );
73 } catch (Exception e) {
74 Assert.fail(e.getMessage());

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected