add unit test

This commit is contained in:
XudongXie 2024-09-20 09:57:33 +08:00
parent 97091da1d1
commit db2701ae44
3 changed files with 75 additions and 8 deletions

View File

@ -4,9 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="d8d12963-4777-48e3-9669-309cf5e41d60" name="更改" comment="revise">
<change afterPath="$PROJECT_DIR$/src/test/java/testAlterTable.java" afterDir="false" />
<list default="true" id="d8d12963-4777-48e3-9669-309cf5e41d60" name="更改" comment="add unit test">
<change afterPath="$PROJECT_DIR$/src/test/java/testCommitRollbackExec.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/testAlterTable.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/testAlterTable.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -43,18 +44,19 @@
"keyToString": {
"Application.Main.executor": "Run",
"JUnit.testAlterTable.testAlterTable.executor": "Run",
"JUnit.testCommitRollbackExec.test.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "F:/oracle2opengauss/examples/sqlTranslate",
"project.structure.last.edited": "模块",
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0",
"settings.editor.selected.configurable": "preferences.pluginManager"
}
}]]></component>
<component name="RunManager" selected="JUnit.testAlterTable.testAlterTable">
<component name="RunManager" selected="JUnit.testCommitRollbackExec.test">
<configuration name="App" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.App" />
<module name="sqlTranslate" />
@ -101,14 +103,26 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="testCommitRollbackExec.test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="sqlTranslate" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="testCommitRollbackExec" />
<option name="METHOD_NAME" value="test" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.App" />
<item itemvalue="Application.Main" />
<item itemvalue="JUnit.testAlterTable.testAlterTable" />
<item itemvalue="JUnit.testCommitRollbackExec.test" />
<item itemvalue="JUnit.AppTest.shouldAnswerWithTrue" />
</list>
<recent_temporary>
<list>
<item itemvalue="JUnit.testCommitRollbackExec.test" />
<item itemvalue="JUnit.testAlterTable.testAlterTable" />
<item itemvalue="Application.Main" />
<item itemvalue="JUnit.AppTest.shouldAnswerWithTrue" />
@ -468,7 +482,7 @@
<option name="project" value="LOCAL" />
<updated>1726633703475</updated>
</task>
<option name="localTasksCounter" value="96" />
<option name="localTasksCounter" value="97" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -483,7 +497,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="add view generate method" />
<MESSAGE value="add if elseif else endif document" />
<MESSAGE value="add if elseif else endif ast classes" />
<MESSAGE value="add IF ELSIF" />
@ -508,7 +521,8 @@
<MESSAGE value="add PL ast classes" />
<MESSAGE value="add pl/sql" />
<MESSAGE value="revise" />
<option name="LAST_COMMIT_MESSAGE" value="revise" />
<MESSAGE value="add unit test" />
<option name="LAST_COMMIT_MESSAGE" value="add unit test" />
</component>
<component name="XDebuggerManager">
<watches-manager>

View File

@ -30,7 +30,7 @@ public class testAlterTable {
}
@Test
public void testAlterTable()
public void test()
{
int num = 1;
for (String sql : testSQL) {

View File

@ -0,0 +1,53 @@
import config.CommonConfig;
import generator.OpenGaussGenerator;
import lexer.OracleLexer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import parser.OracleParser;
import parser.ast.ASTNode;
import java.util.ArrayList;
import java.util.List;
public class testCommitRollbackExec {
List<String> testSQL = new ArrayList<>();
@BeforeEach
public void loadData()
{
testSQL.add("BEGIN\n" +
" INSERT INTO my_table (id, value) VALUES (1, 'test');\n" +
" ROLLBACK;\n" +
"END;");
testSQL.add("BEGIN\n" +
" INSERT INTO my_table (id, value) VALUES (1, 'test');\n" +
" COMMIT;\n" +
"END;");
System.out.println("===== test of the alter table =====");
System.out.println("The source DBMS is: " + CommonConfig.getSourceDB());
System.out.println("The target DBMS is: " + CommonConfig.getTargetDB());
System.out.println();
}
@Test
public void test()
{
int num = 1;
for (String sql : testSQL) {
System.out.println("===== test of the SQL" + num++ + " =====");
System.out.println("Input SQL: " + sql);
OracleLexer lexer = new OracleLexer(sql);
lexer.printTokens();
OracleParser parser = new OracleParser(lexer);
ASTNode root = parser.parse();
System.out.println("The AST of the input SQL: ");
System.out.println(root.getASTString());
System.out.println("The query String of the AST parsed from the input SQL: ");
System.out.println(root.toQueryString());
OpenGaussGenerator generator = new OpenGaussGenerator(root);
System.out.println("The converted query String: ");
System.out.println(generator.generate());
System.out.println();
}
}
}