Skip to content

Commit f873475

Browse files
test: Improve the test case coverage of [sqlparser] module to 70% (apache#6608)
1 parent 7739e50 commit f873475

File tree

14 files changed

+1085
-0
lines changed

14 files changed

+1085
-0
lines changed

changes/en-us/2.x.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Add changes here for all PR submitted to the 2.x branch.
3434

3535

3636
### test:
37+
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] add unit test for sql-parser-core
3738
- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] improve the test case coverage of saga module to 70%
3839

3940

@@ -48,6 +49,7 @@ Thanks to these contributors for their code commits. Please report an unintended
4849
- [Bughue](https://github.com/Bughue)
4950
- [funky-eyes](https://github.com/funky-eyes)
5051
- [tanyaofei](https://github.com/tanyaofei)
52+
- [traitsisgiorgos](https://github.com/traitsisgiorgos)
5153
- [wanghongzhou](https://github.com/wanghongzhou)
5254
- [ggbocoder](https://github.com/ggbocoder)
5355
- [xjlgod](https://github.com/xjlgod)

changes/zh-cn/2.x.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
### security:
3535

3636
### test:
37+
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] 添加sql-parser-core模块测试用例
3738
- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] 增加saga模块的测试用例覆盖率
3839

3940

@@ -49,6 +50,7 @@
4950
- [Bughue](https://github.com/Bughue)
5051
- [funky-eyes](https://github.com/funky-eyes)
5152
- [tanyaofei](https://github.com/tanyaofei)
53+
- [traitsisgiorgos](https://github.com/traitsisgiorgos)
5254
- [wanghongzhou](https://github.com/wanghongzhou)
5355
- [ggbocoder](https://github.com/ggbocoder)
5456
- [xjlgod](https://github.com/xjlgod)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.sqlparser;
18+
19+
import org.junit.jupiter.api.Test;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
public class EscapeSymbolTest {
23+
24+
@Test
25+
public void testGetLeftSymbol() {
26+
char expectedLeftSymbol = '"';
27+
EscapeSymbol escapeSymbol = new EscapeSymbol(expectedLeftSymbol, '"');
28+
assertEquals(expectedLeftSymbol, escapeSymbol.getLeftSymbol(),
29+
"The left symbol should be '" + expectedLeftSymbol + "'");
30+
}
31+
32+
@Test
33+
public void testGetRightSymbol() {
34+
char expectedRightSymbol = '"';
35+
EscapeSymbol escapeSymbol = new EscapeSymbol('"', expectedRightSymbol);
36+
assertEquals(expectedRightSymbol, escapeSymbol.getRightSymbol(),
37+
"The right symbol should be '" + expectedRightSymbol + "'");
38+
}
39+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.sqlparser;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
public class SQLParsingExceptionTest {
25+
@Test
26+
public void testConstructorWithMessage() {
27+
String message = "Test message";
28+
SQLParsingException exception = new SQLParsingException(message);
29+
assertEquals(message, exception.getMessage(), "Message should match");
30+
assertNull(exception.getCause(), "Cause should be null");
31+
}
32+
33+
@Test
34+
public void testConstructorWithMessageAndCause() {
35+
String message = "Test message";
36+
Throwable cause = new IllegalArgumentException("Test cause");
37+
SQLParsingException exception = new SQLParsingException(message, cause);
38+
assertEquals(message, exception.getMessage(), "Message should match");
39+
assertEquals(cause, exception.getCause(), "Cause should match");
40+
}
41+
42+
@Test
43+
public void testConstructorWithCause() {
44+
Throwable cause = new IllegalArgumentException("Test cause");
45+
SQLParsingException exception = new SQLParsingException(cause);
46+
assertEquals(cause.toString(), exception.getMessage(), "Message should be cause's toString");
47+
assertEquals(cause, exception.getCause(), "Cause should match");
48+
}
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.sqlparser;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
public class SQLTypeTest {
25+
26+
@Test
27+
public void testValue() {
28+
assertEquals(0, SQLType.SELECT.value(), "SELECT value should be 0");
29+
assertEquals(1, SQLType.INSERT.value(), "INSERT value should be 1");
30+
// Add more assertions for other enum constants
31+
}
32+
33+
@Test
34+
public void testValueOf() {
35+
assertEquals(SQLType.SELECT, SQLType.valueOf(0), "Should retrieve SELECT for value 0");
36+
assertEquals(SQLType.INSERT, SQLType.valueOf(1), "Should retrieve INSERT for value 1");
37+
// Add more assertions for other integer values
38+
}
39+
40+
@Test
41+
public void testValueOfInvalid() {
42+
assertThrows(IllegalArgumentException.class, () -> SQLType.valueOf(100),
43+
"Should throw IllegalArgumentException for invalid value");
44+
}
45+
46+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.sqlparser.struct;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
public class ColumnMetaTest {
27+
28+
@Test
29+
public void testEqualsAndHashCode() {
30+
// Create two instances with identical properties
31+
ColumnMeta column1 = new ColumnMeta();
32+
ColumnMeta column2 = new ColumnMeta();
33+
34+
// Test equality for two newly created instances
35+
assertTrue(column1.equals(column2));
36+
assertEquals(column1.hashCode(), column2.hashCode());
37+
38+
// Modify some properties of column1
39+
column1.setTableName("table1");
40+
column1.setColumnName("column1");
41+
column1.setDataType(1);
42+
43+
// Test inequality after modifying properties
44+
assertFalse(column1.equals(column2));
45+
assertNotEquals(column1.hashCode(), column2.hashCode());
46+
47+
// Create a copy of column1 with the same properties
48+
ColumnMeta column3 = new ColumnMeta();
49+
column3.setTableName("table1");
50+
column3.setColumnName("column1");
51+
column3.setDataType(1);
52+
53+
// Test equality with the copy
54+
assertTrue(column1.equals(column3));
55+
assertEquals(column1.hashCode(), column3.hashCode());
56+
57+
}
58+
59+
@Test
60+
public void testAutoincrement() {
61+
ColumnMeta column = new ColumnMeta();
62+
63+
// Test default value
64+
assertFalse(column.isAutoincrement());
65+
66+
// Set autoincrement to YES
67+
column.setIsAutoincrement("YES");
68+
assertTrue(column.isAutoincrement());
69+
70+
// Set autoincrement to NO
71+
column.setIsAutoincrement("NO");
72+
assertFalse(column.isAutoincrement());
73+
}
74+
75+
@Test
76+
public void testGetTableCat() {
77+
ColumnMeta columnMeta = new ColumnMeta();
78+
columnMeta.setTableCat("tableCat");
79+
assertEquals(columnMeta.getTableCat(), "tableCat".trim());
80+
}
81+
82+
@Test
83+
public void testSetGetColumnName() {
84+
ColumnMeta columnMeta = new ColumnMeta();
85+
columnMeta.setColumnName("columnName");
86+
assertEquals("columnName".trim(), columnMeta.getColumnName());
87+
}
88+
89+
@Test
90+
public void testSetGetDataType() {
91+
ColumnMeta columnMeta = new ColumnMeta();
92+
columnMeta.setDataType(2);
93+
assertEquals(2, columnMeta.getDataType());
94+
}
95+
96+
@Test
97+
public void testSetGetDataTypeName() {
98+
ColumnMeta columnMeta = new ColumnMeta();
99+
columnMeta.setDataTypeName("dataTypeName");
100+
assertEquals("dataTypeName".trim(), columnMeta.getDataTypeName());
101+
}
102+
103+
@Test
104+
public void testSetGetColumnSize() {
105+
ColumnMeta columnMeta = new ColumnMeta();
106+
columnMeta.setColumnSize(2);
107+
assertEquals(2, columnMeta.getColumnSize());
108+
}
109+
110+
@Test
111+
public void testSetGetDemicalDigits() {
112+
ColumnMeta columnMeta = new ColumnMeta();
113+
columnMeta.setDecimalDigits(2);
114+
assertEquals(2, columnMeta.getDecimalDigits());
115+
}
116+
117+
@Test
118+
public void testSetGetNumPrecRadix() {
119+
ColumnMeta columnMeta = new ColumnMeta();
120+
columnMeta.setNumPrecRadix(10);
121+
assertEquals(10, columnMeta.getNumPrecRadix());
122+
}
123+
124+
@Test
125+
public void testSetGetNullAble() {
126+
ColumnMeta columnMeta = new ColumnMeta();
127+
columnMeta.setNullAble(5);
128+
assertEquals(5, columnMeta.getNullAble());
129+
}
130+
131+
@Test
132+
public void testSetGetRemarks() {
133+
ColumnMeta columnMeta = new ColumnMeta();
134+
columnMeta.setRemarks("remarks");
135+
assertEquals("remarks".trim(), columnMeta.getRemarks());
136+
}
137+
138+
@Test
139+
public void testSetGetColumnDef() {
140+
ColumnMeta columnMeta = new ColumnMeta();
141+
columnMeta.setColumnDef("columnDef");
142+
assertEquals("columnDef", columnMeta.getColumnDef());
143+
}
144+
145+
@Test
146+
public void testSetGetSqlDataType() {
147+
ColumnMeta columnMeta = new ColumnMeta();
148+
columnMeta.setSqlDataType(1);
149+
assertEquals(1, columnMeta.getSqlDataType());
150+
}
151+
152+
@Test
153+
public void testSetGetSqlDatetimeSub() {
154+
ColumnMeta columnMeta = new ColumnMeta();
155+
columnMeta.setSqlDatetimeSub(2);
156+
assertEquals(2, columnMeta.getSqlDatetimeSub());
157+
}
158+
159+
@Test
160+
public void testSetGetCharOctetLength() {
161+
ColumnMeta columnMeta = new ColumnMeta();
162+
Object charOctetLength = 255;
163+
columnMeta.setCharOctetLength(charOctetLength);
164+
assertEquals(charOctetLength, columnMeta.getCharOctetLength());
165+
}
166+
167+
@Test
168+
public void testSetGetOrdinalPosition() {
169+
ColumnMeta columnMeta = new ColumnMeta();
170+
columnMeta.setOrdinalPosition(3);
171+
assertEquals(3, columnMeta.getOrdinalPosition());
172+
}
173+
174+
@Test
175+
public void testSetGetIsOnUpdate() {
176+
ColumnMeta columnMeta = new ColumnMeta();
177+
columnMeta.setOnUpdate(true);
178+
assertTrue(columnMeta.isOnUpdate());
179+
}
180+
181+
@Test
182+
public void testSetGetIsCaseSensitive() {
183+
ColumnMeta columnMeta = new ColumnMeta();
184+
columnMeta.setCaseSensitive(true);
185+
assertTrue(columnMeta.isCaseSensitive());
186+
}
187+
188+
}

0 commit comments

Comments
 (0)