Add DDL Parser tests for strongly-typed ref cursor
diff --git a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/DatabaseTypeBuilderTestSuite.java b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/DatabaseTypeBuilderTestSuite.java
index d2a7918..a7e7d9d 100644
--- a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/DatabaseTypeBuilderTestSuite.java
+++ b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/DatabaseTypeBuilderTestSuite.java
@@ -34,6 +34,7 @@
ConstraintsTableDDLTestSuite.class,
MixedCaseObjectTableTypeTestSuite.class,
IOTTableDDLTestSuite.class,
+ PackagewStronglyTypedCursorDDLTestSuite.class,
ProcedureDDLTestSuite.class,
TableDDLTestSuite.class,
TransformsTestSuite.class,
diff --git a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/PackagewStronglyTypedCursorDDLTestSuite.java b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/PackagewStronglyTypedCursorDDLTestSuite.java
new file mode 100644
index 0000000..f9da069
--- /dev/null
+++ b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/PackagewStronglyTypedCursorDDLTestSuite.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Mike Norman - June 10 2011, created DDL parser package
+ * David McCann - July 2011, visit tests
+ ******************************************************************************/
+package org.eclipse.persistence.tools.oracleddl.test.databasetypebuilder;
+
+//javase imports
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+//JUnit4 imports
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+//DDL imports
+import org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType;
+import org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType;
+import org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCursorType;
+import org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType;
+import org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType;
+import org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType;
+import org.eclipse.persistence.tools.oracleddl.metadata.TableType;
+import org.eclipse.persistence.tools.oracleddl.util.DatabaseTypeBuilder;
+
+//testing imports
+import org.eclipse.persistence.tools.oracleddl.test.AllTests;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DATABASE_DDL_CREATE_KEY;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DATABASE_DDL_DEBUG_KEY;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DATABASE_DDL_DROP_KEY;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DATABASE_USERNAME_KEY;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DEFAULT_DATABASE_DDL_CREATE;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DEFAULT_DATABASE_DDL_DEBUG;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DEFAULT_DATABASE_DDL_DROP;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.DEFAULT_DATABASE_USERNAME;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.buildConnection;
+import static org.eclipse.persistence.tools.oracleddl.test.TestHelper.runDdl;
+
+public class PackagewStronglyTypedCursorDDLTestSuite {
+
+ static final String STRONGLY_TYPED_REF_CURSOR_TABLE = "STRC_TABLE";
+ static final String CREATE_STRONGLY_TYPED_REF_CURSOR_TABLE =
+ "CREATE TABLE " + STRONGLY_TYPED_REF_CURSOR_TABLE + " (" +
+ "\nID NUMBER NOT NULL," +
+ "\nNAME VARCHAR(25)," +
+ "\nSINCE DATE," +
+ "\nPRIMARY KEY (ID)" +
+ "\n)";
+ static final String[] POPULATE_STRONGLY_TYPED_REF_CURSOR_TABLE = new String[] {
+ "INSERT INTO " + STRONGLY_TYPED_REF_CURSOR_TABLE + " (ID, NAME, SINCE) VALUES (1, 'mike', " +
+ "TO_DATE('2001-12-25 00:00:00','YYYY-MM-DD HH24:MI:SS'))",
+ "INSERT INTO " + STRONGLY_TYPED_REF_CURSOR_TABLE + " (ID, NAME, SINCE) VALUES (2, 'blaise', " +
+ "TO_DATE('2002-02-12 00:00:00','YYYY-MM-DD HH24:MI:SS'))",
+ "INSERT INTO " + STRONGLY_TYPED_REF_CURSOR_TABLE + " (ID, NAME, SINCE) VALUES (3, 'rick', " +
+ "TO_DATE('2001-10-30 00:00:00','YYYY-MM-DD HH24:MI:SS'))",
+ "INSERT INTO " + STRONGLY_TYPED_REF_CURSOR_TABLE + " (ID, NAME, SINCE) VALUES (4, 'mikey', " +
+ "TO_DATE('2010-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS'))"
+ };
+ static final String STRONGLY_TYPED_REF_CURSOR_PROC = "GET_EMS";
+ static final String STRONGLY_TYPED_REF_CURSOR = "STRONGLY_TYPED_REF_CURSOR";
+ static final String STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE = STRONGLY_TYPED_REF_CURSOR + "_TEST";
+ static final String CREATE_STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE =
+ "CREATE OR REPLACE PACKAGE " + STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE + " AS" +
+ "\nTYPE " + STRONGLY_TYPED_REF_CURSOR + " IS REF CURSOR RETURN " + STRONGLY_TYPED_REF_CURSOR_TABLE + "%ROWTYPE;" +
+ "\nPROCEDURE " + STRONGLY_TYPED_REF_CURSOR_PROC + "(P_EMS " + STRONGLY_TYPED_REF_CURSOR_TABLE+".NAME%TYPE, P_EMS_SET OUT " +
+ STRONGLY_TYPED_REF_CURSOR + ");" +
+ "\nEND " + STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE + ";";
+ static final String CREATE_STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE_BODY =
+ "CREATE OR REPLACE PACKAGE BODY " + STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE + " AS" +
+ "\nPROCEDURE GET_EMS(P_EMS " + STRONGLY_TYPED_REF_CURSOR_TABLE+".NAME%TYPE, P_EMS_SET OUT " +
+ STRONGLY_TYPED_REF_CURSOR + ") AS" +
+ "\nBEGIN" +
+ "\n OPEN P_EMS_SET FOR" +
+ "\n SELECT ID, NAME, SINCE FROM " + STRONGLY_TYPED_REF_CURSOR_TABLE +
+ " WHERE NAME LIKE P_EMS;" +
+ "\nEND GET_EMS;" +
+ "\nEND " + STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE + ";";
+
+ static final String DROP_STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE =
+ "DROP PACKAGE " + STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE;
+ static final String DROP_STRONGLY_TYPED_REF_CURSOR_TABLE =
+ "DROP TABLE " + STRONGLY_TYPED_REF_CURSOR_TABLE;
+
+ //fixtures
+ static DatabaseTypeBuilder dtBuilder = DatabaseTypeBuilderTestSuite.dtBuilder;
+ static Connection conn = AllTests.conn;
+ static PLSQLPackageType packageType = null;
+ static ProcedureType procType = null;
+ static ArgumentType outCursorArg = null;
+
+ static boolean ddlCreate = false;
+ static boolean ddlDrop = false;
+ static boolean ddlDebug = false;
+
+ @BeforeClass
+ public static void setUp() throws SQLException, ClassNotFoundException {
+ conn = buildConnection();
+ dtBuilder = new DatabaseTypeBuilder();
+ String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
+ if ("true".equalsIgnoreCase(ddlCreateProp)) {
+ ddlCreate = true;
+ }
+ String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
+ if ("true".equalsIgnoreCase(ddlDropProp)) {
+ ddlDrop = true;
+ }
+ String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
+ if ("true".equalsIgnoreCase(ddlDebugProp)) {
+ ddlDebug = true;
+ }
+ if (ddlCreate) {
+ runDdl(conn, CREATE_STRONGLY_TYPED_REF_CURSOR_TABLE, ddlDebug);
+ try {
+ Statement stmt = conn.createStatement();
+ for (int i = 0; i < POPULATE_STRONGLY_TYPED_REF_CURSOR_TABLE.length; i++) {
+ stmt.addBatch(POPULATE_STRONGLY_TYPED_REF_CURSOR_TABLE[i]);
+ }
+ stmt.executeBatch();
+ }
+ catch (SQLException e) {
+ //e.printStackTrace();
+ }
+ runDdl(conn, CREATE_STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE, ddlDebug);
+ runDdl(conn, CREATE_STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE_BODY, ddlDebug);
+ }
+ boolean worked = true;
+ String msg = null;
+ try {
+ String schema = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
+ packageType = dtBuilder.buildPackages(conn, schema, STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE).get(0);
+ }
+ catch (Exception e) {
+ worked = false;
+ msg = e.getMessage();
+ }
+ if (!worked) {
+ fail(msg);
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ if (ddlDrop) {
+ runDdl(conn, DROP_STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE, ddlDebug);
+ runDdl(conn, DROP_STRONGLY_TYPED_REF_CURSOR_TABLE, ddlDebug);
+ }
+ }
+
+ @Test
+ public void testPackageName() {
+ assertEquals("incorrect package name", STRONGLY_TYPED_REF_CURSOR_TEST_PACKAGE,
+ packageType.getPackageName());
+ }
+
+ @Test
+ public void testProcedureName() {
+ List<ProcedureType> procedures = packageType.getProcedures();
+ assertTrue(procedures.size() == 1);
+ procType = procedures.get(0);
+ assertEquals("incorrect procedure name", STRONGLY_TYPED_REF_CURSOR_PROC,
+ procType.getProcedureName());
+ }
+
+ @Test
+ public void testProcedureArgs() {
+ List<ArgumentType> args = procType.getArguments();
+ assertTrue(args.size() == 2);
+ ArgumentType arg1 = args.get(0);
+ assertEquals("incorrect arg1 name", "P_EMS", arg1.getArgumentName());
+ ArgumentType arg2 = args.get(1);
+ assertEquals("incorrect arg2 name", "P_EMS_SET", arg2.getArgumentName());
+ }
+
+ @Test
+ public void testProcedureArgNames() {
+ List<ArgumentType> args = procType.getArguments();
+ assertTrue(args.size() == 2);
+ ArgumentType arg1 = args.get(0);
+ assertEquals("incorrect arg1 name", "P_EMS", arg1.getArgumentName());
+ outCursorArg = args.get(1);
+ assertEquals("incorrect outCursorArg name", "P_EMS_SET", outCursorArg.getArgumentName());
+ }
+
+ @Test
+ public void testOutCursorArg() {
+ DatabaseType enclosedType = outCursorArg.getEnclosedType();
+ assertTrue(enclosedType.isPLSQLCursorType());
+ PLSQLCursorType cursorType = (PLSQLCursorType)enclosedType;
+ assertEquals("incorrect cursor name", STRONGLY_TYPED_REF_CURSOR, cursorType.getCursorName());
+ DatabaseType enclosedType2 = cursorType.getEnclosedType();
+ assertNotNull(enclosedType2);
+ assertTrue(enclosedType2.isROWTYPEType());
+ ROWTYPEType rowType = (ROWTYPEType)enclosedType2;
+ assertEquals("incorrect cursor %ROWTYPE name", "TABLE STRC_TABLE", rowType.getTypeName());
+ DatabaseType enclosedType3 = rowType.getEnclosedType();
+ assertTrue(enclosedType3.isTableType());
+ TableType tableType = (TableType)enclosedType3;
+ assertEquals("incorrect %ROWTYPE table name", "STRC_TABLE", tableType.getTableName());
+ }
+
+}
\ No newline at end of file
diff --git a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/DDLParserTestSuite.java b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/DDLParserTestSuite.java
index b96bd29..1237ea6 100644
--- a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/DDLParserTestSuite.java
+++ b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/DDLParserTestSuite.java
@@ -27,6 +27,7 @@
FunctionDDLTestSuite.class,
ProcedureDDLTestSuite.class,
PackageDDLTestSuite.class,
+ StronglyTypedCursorDDLTestSuite.class,
TableDDLTestSuite.class,
TypeDDLTestSuite.class
})
diff --git a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/StronglyTypedCursorDDLTestSuite.java b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/StronglyTypedCursorDDLTestSuite.java
new file mode 100644
index 0000000..0db5575
--- /dev/null
+++ b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/ddlparser/StronglyTypedCursorDDLTestSuite.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Mike Norman - June 10 2011, created DDL parser package
+ * David McCann - July 2011, visit tests
+ ******************************************************************************/
+package org.eclipse.persistence.tools.oracleddl.test.ddlparser;
+
+//javase imports
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+
+//JUnit4 imports
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+//DDL imports
+import org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType;
+import org.eclipse.persistence.tools.oracleddl.metadata.visit.UnresolvedTypesVisitor;
+import org.eclipse.persistence.tools.oracleddl.parser.DDLParser;
+import org.eclipse.persistence.tools.oracleddl.parser.ParseException;
+import org.eclipse.persistence.tools.oracleddl.util.DatabaseTypesRepository;
+
+public class StronglyTypedCursorDDLTestSuite {
+
+ static final String CREATE_PACKAGE_PREFIX = "CREATE PACKAGE ";
+ static final String CURSOR_PACKAGE = "STRONGLY_TYPED_REF_CURSOR_TEST";
+ static final String CREATE_CURSOR_PACKAGE =
+ CREATE_PACKAGE_PREFIX + CURSOR_PACKAGE + " AS" +
+ "\nTYPE STRONGLY_TYPED_REF_CURSOR IS REF CURSOR RETURN STRC_TABLE%ROWTYPE;" +
+ "\nPROCEDURE GET_EMS(P_EMS STRC_TABLE.NAME%TYPE, P_EMS_SET OUT STRONGLY_TYPED_REF_CURSOR);" +
+ "\nEND " + CURSOR_PACKAGE + ";";
+
+ //JUnit fixture(s)
+ static DDLParser parser = null;
+
+ @BeforeClass
+ static public void setUp() {
+ parser = new DDLParser(new InputStream() {
+ public int read() throws IOException {
+ return 0;
+ }
+ });
+ parser.setTypesRepository(new DatabaseTypesRepository());
+ }
+
+ @Test
+ public void testCursorPackage() {
+ parser.ReInit(new StringReader(CREATE_CURSOR_PACKAGE));
+ boolean worked = true;
+ @SuppressWarnings("unused") PLSQLPackageType packageType = null;
+ try {
+ packageType = parser.parsePLSQLPackage();
+ }
+ catch (ParseException pe) {
+ worked = false;
+ }
+ assertTrue("cursor package should parse", worked);
+ UnresolvedTypesVisitor l = new UnresolvedTypesVisitor();
+ l.visit(packageType);
+ assertTrue("cursor package should contain two unresolved datatypes",
+ l.getUnresolvedTypes().size() == 2);
+ }
+}
\ No newline at end of file