Skip to content

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 15 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Add changes here for all PR submitted to the 2.x branch.


### test:
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] add unit test for sql-parser-core
Copy link
Contributor

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

- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] improve the test case coverage of saga module to 70%


Expand All @@ -43,9 +44,10 @@ Thanks to these contributors for their code commits. Please report an unintended
- [Bughue](https://github.com/Bughue)
- [funky-eyes](https://github.com/funky-eyes)
- [tanyaofei](https://github.com/tanyaofei)
- [traitsisgiorgos](https://github.com/traitsisgiorgos)
- [wanghongzhou](https://github.com/wanghongzhou)
- [ggbocoder](https://github.com/ggbocoder)
- [xjlgod](https://github.com/xjlgod)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
### security:

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


Expand All @@ -44,6 +45,7 @@
- [Bughue](https://github.com/Bughue)
- [funky-eyes](https://github.com/funky-eyes)
- [tanyaofei](https://github.com/tanyaofei)
- [traitsisgiorgos](https://github.com/traitsisgiorgos)
- [wanghongzhou](https://github.com/wanghongzhou)
- [ggbocoder](https://github.com/ggbocoder)
- [xjlgod](https://github.com/xjlgod)
Expand Down
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 + "'");
}
}
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");
}
}
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");
}

}
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());
}

}
Loading
Loading