1 package org.synchronoss.cpo.jdbc.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import static org.testng.Assert.assertTrue;
26 import static org.testng.Assert.fail;
27
28 import java.text.ParseException;
29 import java.util.List;
30 import org.synchronoss.cpo.core.parser.BoundExpressionParser;
31 import org.testng.annotations.Test;
32
33
34 public class BoundExpressionParserTest {
35
36 @Test
37 public void testSelect() {
38 try {
39 String query = "select * from table where a = ? and b = ? and c = ? and d = '0'";
40 BoundExpressionParser parser = new BoundExpressionParser();
41 parser.setExpression(query);
42 List<String> colList = parser.parse();
43
44 assertTrue(colList.size() == 3);
45 assertTrue(colList.get(0).equals("A"));
46 assertTrue(colList.get(1).equals("B"));
47 assertTrue(colList.get(2).equals("C"));
48
49 } catch (ParseException ex) {
50 fail(ex.getMessage());
51 }
52 }
53
54 @Test
55 public void testSelectWithFunction() {
56 try {
57 String query = "select * from table where a = ? and UPPER(b) = ? and c = ? and d = '0'";
58 BoundExpressionParser parser = new BoundExpressionParser();
59 parser.setExpression(query);
60 List<String> colList = parser.parse();
61
62 assertTrue(colList.size() == 3);
63 assertTrue(colList.get(0).equals("A"));
64 assertTrue(colList.get(1).equals("B"));
65 assertTrue(colList.get(2).equals("C"));
66
67 } catch (ParseException ex) {
68 fail(ex.getMessage());
69 }
70 }
71
72 @Test
73 public void testInsert() {
74 try {
75 String query = "insert into table(a, b, c, d) values(?, ?, ?, SYSDATE)";
76 BoundExpressionParser parser = new BoundExpressionParser();
77 parser.setExpression(query);
78 List<String> colList = parser.parse();
79
80 assertTrue(colList.size() == 3);
81 assertTrue(colList.get(0).equals("A"));
82 assertTrue(colList.get(1).equals("B"));
83 assertTrue(colList.get(2).equals("C"));
84
85 } catch (ParseException ex) {
86 fail(ex.getMessage());
87 }
88 }
89 }