-
Notifications
You must be signed in to change notification settings - Fork 8.8k
test: Improve the test case coverage of [sqlparser] module to 70% #6608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f356ad5
test:add unit test for sql-parser-core
traitsisgiorgos 48c1201
add license text for test classes
traitsisgiorgos c1bb34e
registered to 2.x.md
traitsisgiorgos 8fabcdc
fix assert import
traitsisgiorgos 7974c18
only necessary imports added and registerd to zn-cn
traitsisgiorgos e7cf105
was translated to Chinese
traitsisgiorgos c433e1d
Merge branch '2.x' into sqlparser-tests
traitsisgiorgos 47678fc
info added
traitsisgiorgos 956291c
Merge branch '2.x' into sqlparser-tests
traitsisgiorgos 1afa437
Merge branch '2.x' into sqlparser-tests
funky-eyes 22964cc
Merge branch '2.x' of github.com:apache/incubator-seata into sqlparse…
funky-eyes 0a1e3b5
Merge branch '2.x' into sqlparser-tests
funky-eyes 3f91be5
Update changes/en-us/2.x.md
funky-eyes 880b104
Merge branch '2.x' into sqlparser-tests
funky-eyes 472c466
Merge branch '2.x' into sqlparser-tests
funky-eyes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...arser/seata-sqlparser-core/src/test/java/org/apache/seata/sqlparser/EscapeSymbolTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.sqlparser; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class EscapeSymbolTest { | ||
|
||
@Test | ||
public void testGetLeftSymbol() { | ||
char expectedLeftSymbol = '"'; | ||
EscapeSymbol escapeSymbol = new EscapeSymbol(expectedLeftSymbol, '"'); | ||
assertEquals(expectedLeftSymbol, escapeSymbol.getLeftSymbol(), | ||
"The left symbol should be '" + expectedLeftSymbol + "'"); | ||
} | ||
|
||
@Test | ||
public void testGetRightSymbol() { | ||
char expectedRightSymbol = '"'; | ||
EscapeSymbol escapeSymbol = new EscapeSymbol('"', expectedRightSymbol); | ||
assertEquals(expectedRightSymbol, escapeSymbol.getRightSymbol(), | ||
"The right symbol should be '" + expectedRightSymbol + "'"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...eata-sqlparser-core/src/test/java/org/apache/seata/sqlparser/SQLParsingExceptionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.sqlparser; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SQLParsingExceptionTest { | ||
@Test | ||
public void testConstructorWithMessage() { | ||
String message = "Test message"; | ||
SQLParsingException exception = new SQLParsingException(message); | ||
assertEquals(message, exception.getMessage(), "Message should match"); | ||
assertNull(exception.getCause(), "Cause should be null"); | ||
} | ||
|
||
@Test | ||
public void testConstructorWithMessageAndCause() { | ||
String message = "Test message"; | ||
Throwable cause = new IllegalArgumentException("Test cause"); | ||
SQLParsingException exception = new SQLParsingException(message, cause); | ||
assertEquals(message, exception.getMessage(), "Message should match"); | ||
assertEquals(cause, exception.getCause(), "Cause should match"); | ||
} | ||
|
||
@Test | ||
public void testConstructorWithCause() { | ||
Throwable cause = new IllegalArgumentException("Test cause"); | ||
SQLParsingException exception = new SQLParsingException(cause); | ||
assertEquals(cause.toString(), exception.getMessage(), "Message should be cause's toString"); | ||
assertEquals(cause, exception.getCause(), "Cause should match"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
sqlparser/seata-sqlparser-core/src/test/java/org/apache/seata/sqlparser/SQLTypeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.sqlparser; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SQLTypeTest { | ||
|
||
@Test | ||
public void testValue() { | ||
assertEquals(0, SQLType.SELECT.value(), "SELECT value should be 0"); | ||
assertEquals(1, SQLType.INSERT.value(), "INSERT value should be 1"); | ||
// Add more assertions for other enum constants | ||
} | ||
|
||
@Test | ||
public void testValueOf() { | ||
assertEquals(SQLType.SELECT, SQLType.valueOf(0), "Should retrieve SELECT for value 0"); | ||
assertEquals(SQLType.INSERT, SQLType.valueOf(1), "Should retrieve INSERT for value 1"); | ||
// Add more assertions for other integer values | ||
} | ||
|
||
@Test | ||
public void testValueOfInvalid() { | ||
assertThrows(IllegalArgumentException.class, () -> SQLType.valueOf(100), | ||
"Should throw IllegalArgumentException for invalid value"); | ||
} | ||
|
||
} |
188 changes: 188 additions & 0 deletions
188
.../seata-sqlparser-core/src/test/java/org/apache/seata/sqlparser/struct/ColumnMetaTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.sqlparser.struct; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ColumnMetaTest { | ||
|
||
@Test | ||
public void testEqualsAndHashCode() { | ||
// Create two instances with identical properties | ||
ColumnMeta column1 = new ColumnMeta(); | ||
ColumnMeta column2 = new ColumnMeta(); | ||
|
||
// Test equality for two newly created instances | ||
assertTrue(column1.equals(column2)); | ||
assertEquals(column1.hashCode(), column2.hashCode()); | ||
|
||
// Modify some properties of column1 | ||
column1.setTableName("table1"); | ||
column1.setColumnName("column1"); | ||
column1.setDataType(1); | ||
|
||
// Test inequality after modifying properties | ||
assertFalse(column1.equals(column2)); | ||
assertNotEquals(column1.hashCode(), column2.hashCode()); | ||
|
||
// Create a copy of column1 with the same properties | ||
ColumnMeta column3 = new ColumnMeta(); | ||
column3.setTableName("table1"); | ||
column3.setColumnName("column1"); | ||
column3.setDataType(1); | ||
|
||
// Test equality with the copy | ||
assertTrue(column1.equals(column3)); | ||
assertEquals(column1.hashCode(), column3.hashCode()); | ||
|
||
} | ||
|
||
@Test | ||
public void testAutoincrement() { | ||
ColumnMeta column = new ColumnMeta(); | ||
|
||
// Test default value | ||
assertFalse(column.isAutoincrement()); | ||
|
||
// Set autoincrement to YES | ||
column.setIsAutoincrement("YES"); | ||
assertTrue(column.isAutoincrement()); | ||
|
||
// Set autoincrement to NO | ||
column.setIsAutoincrement("NO"); | ||
assertFalse(column.isAutoincrement()); | ||
} | ||
|
||
@Test | ||
public void testGetTableCat() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setTableCat("tableCat"); | ||
assertEquals(columnMeta.getTableCat(), "tableCat".trim()); | ||
} | ||
|
||
@Test | ||
public void testSetGetColumnName() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setColumnName("columnName"); | ||
assertEquals("columnName".trim(), columnMeta.getColumnName()); | ||
} | ||
|
||
@Test | ||
public void testSetGetDataType() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setDataType(2); | ||
assertEquals(2, columnMeta.getDataType()); | ||
} | ||
|
||
@Test | ||
public void testSetGetDataTypeName() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setDataTypeName("dataTypeName"); | ||
assertEquals("dataTypeName".trim(), columnMeta.getDataTypeName()); | ||
} | ||
|
||
@Test | ||
public void testSetGetColumnSize() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setColumnSize(2); | ||
assertEquals(2, columnMeta.getColumnSize()); | ||
} | ||
|
||
@Test | ||
public void testSetGetDemicalDigits() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setDecimalDigits(2); | ||
assertEquals(2, columnMeta.getDecimalDigits()); | ||
} | ||
|
||
@Test | ||
public void testSetGetNumPrecRadix() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setNumPrecRadix(10); | ||
assertEquals(10, columnMeta.getNumPrecRadix()); | ||
} | ||
|
||
@Test | ||
public void testSetGetNullAble() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setNullAble(5); | ||
assertEquals(5, columnMeta.getNullAble()); | ||
} | ||
|
||
@Test | ||
public void testSetGetRemarks() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setRemarks("remarks"); | ||
assertEquals("remarks".trim(), columnMeta.getRemarks()); | ||
} | ||
|
||
@Test | ||
public void testSetGetColumnDef() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setColumnDef("columnDef"); | ||
assertEquals("columnDef", columnMeta.getColumnDef()); | ||
} | ||
|
||
@Test | ||
public void testSetGetSqlDataType() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setSqlDataType(1); | ||
assertEquals(1, columnMeta.getSqlDataType()); | ||
} | ||
|
||
@Test | ||
public void testSetGetSqlDatetimeSub() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setSqlDatetimeSub(2); | ||
assertEquals(2, columnMeta.getSqlDatetimeSub()); | ||
} | ||
|
||
@Test | ||
public void testSetGetCharOctetLength() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
Object charOctetLength = 255; | ||
columnMeta.setCharOctetLength(charOctetLength); | ||
assertEquals(charOctetLength, columnMeta.getCharOctetLength()); | ||
} | ||
|
||
@Test | ||
public void testSetGetOrdinalPosition() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setOrdinalPosition(3); | ||
assertEquals(3, columnMeta.getOrdinalPosition()); | ||
} | ||
|
||
@Test | ||
public void testSetGetIsOnUpdate() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setOnUpdate(true); | ||
assertTrue(columnMeta.isOnUpdate()); | ||
} | ||
|
||
@Test | ||
public void testSetGetIsCaseSensitive() { | ||
ColumnMeta columnMeta = new ColumnMeta(); | ||
columnMeta.setCaseSensitive(true); | ||
assertTrue(columnMeta.isCaseSensitive()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add it to zh-cn/2.x.md