add unit test

This commit is contained in:
XudongXie 2024-09-20 09:46:27 +08:00
parent 8deb614144
commit 97091da1d1
2 changed files with 86 additions and 15 deletions

View File

@ -4,7 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="d8d12963-4777-48e3-9669-309cf5e41d60" name="更改" comment="revise" />
<list default="true" id="d8d12963-4777-48e3-9669-309cf5e41d60" name="更改" comment="revise">
<change afterPath="$PROJECT_DIR$/src/test/java/testAlterTable.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -36,20 +39,22 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;F:/oracle2opengauss/examples/sqlTranslate&quot;,
&quot;project.structure.last.edited&quot;: &quot;模块&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Application.Main.executor": "Run",
"JUnit.testAlterTable.testAlterTable.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.proportion": "0.0",
"project.structure.side.proportion": "0.0",
"settings.editor.selected.configurable": "preferences.pluginManager"
}
}</component>
<component name="RunManager" selected="Application.Main">
}]]></component>
<component name="RunManager" selected="JUnit.testAlterTable.testAlterTable">
<configuration name="App" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.App" />
<module name="sqlTranslate" />
@ -86,13 +91,25 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="testAlterTable.testAlterTable" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="sqlTranslate" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="testAlterTable" />
<option name="METHOD_NAME" value="testAlterTable" />
<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.AppTest.shouldAnswerWithTrue" />
</list>
<recent_temporary>
<list>
<item itemvalue="JUnit.testAlterTable.testAlterTable" />
<item itemvalue="Application.Main" />
<item itemvalue="JUnit.AppTest.shouldAnswerWithTrue" />
<item itemvalue="Application.App" />
@ -451,7 +468,7 @@
<option name="project" value="LOCAL" />
<updated>1726633703475</updated>
</task>
<option name="localTasksCounter" value="95" />
<option name="localTasksCounter" value="96" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">

View File

@ -0,0 +1,54 @@
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 testAlterTable {
List<String> testSQL = new ArrayList<>();
@BeforeEach
public void loadData()
{
testSQL.add("ALTER TABLE employees ADD email VARCHAR2(100);");
testSQL.add("ALTER TABLE employees ADD email LONG RAW;");
testSQL.add("ALTER TABLE employees DROP COLUMN middle_name;");
testSQL.add("ALTER TABLE employees MODIFY salary NUMBER(10,2);");
testSQL.add("ALTER TABLE employees MODIFY salary ROWID;");
testSQL.add("ALTER TABLE employees RENAME COLUMN first_name TO given_name;");
testSQL.add("ALTER TABLE employees ADD CONSTRAINT emp_pk PRIMARY KEY (employee_id);");
testSQL.add("ALTER TABLE employees DROP CONSTRAINT emp_pk;");
testSQL.add("ALTER TABLE employees RENAME TO staff;");
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 testAlterTable()
{
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();
}
}
}