01: /*
02: * OraclePackageParserTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.oracle;
13:
14: import junit.framework.TestCase;
15:
16: /**
17: * @author support@sql-workbench.net
18: */
19: public class OraclePackageParserTest extends TestCase {
20: String decl = "CREATE OR REPLACE PACKAGE emp_actions AS -- spec \n"
21: + " TYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL); \n"
22: + " CURSOR desc_salary RETURN EmpRecTyp \n"
23: + " PROCEDURE hire_employee ( \n"
24: + " ename VARCHAR2, \n"
25: + " job VARCHAR2, \n"
26: + " mgr NUMBER, \n"
27: + " sal NUMBER, \n"
28: + " comm NUMBER, \n"
29: + " deptno NUMBER) \n"
30: + " PROCEDURE fire_employee (emp_id NUMBER); \n"
31: + "END emp_actions;";
32:
33: String body = "CREATE \nOR\t REPLACE PACKAGE BODY emp_actions AS -- body \n"
34: + " CURSOR desc_salary RETURN EmpRecTyp IS \n"
35: + " SELECT empno, sal FROM emp ORDER BY sal DESC; \n"
36: + " /** Procedure hire_employee **/ \n"
37: + " PROCEDURE hire_employee( \n"
38: + " ename VARCHAR2, \n"
39: + " job VARCHAR2, \n"
40: + " mgr NUMBER, \n"
41: + " sal NUMBER, \n"
42: + " comm NUMBER, \n"
43: + " deptno NUMBER) IS \n"
44: + " BEGIN \n"
45: + " INSERT INTO emp VALUES (empno_seq.NEXTVAL, ename, job, \n"
46: + " mgr, SYSDATE, sal, comm, deptno) \n"
47: + " END hire_employee; \n"
48: + " \n"
49: + " /** Procedure fire_employee **/ \n"
50: + " PROCEDURE fire_employee (emp_id NUMBER) IS \n"
51: + " BEGIN \n"
52: + " DELETE FROM emp WHERE empno = emp_id; \n"
53: + " END fire_employee; \n" + "END emp_actions;";
54:
55: public OraclePackageParserTest(String testName) {
56: super (testName);
57: }
58:
59: public void testParser() {
60: String script = decl + "\n/\n/" + body;
61: OraclePackageParser parser = new OraclePackageParser(script);
62: String parsedBody = parser.getPackageBody();
63: String parsedDecl = parser.getPackageDeclaration();
64: assertEquals(body, parsedBody);
65: assertEquals(decl, parsedDecl);
66: }
67:
68: public void testFindProc() {
69: String script = decl + "\n/\n/" + body;
70: int pos = script.indexOf(" PROCEDURE hire_employee(") + 3;
71: int procPos = OraclePackageParser.findProcedurePosition(script,
72: "hire_employee");
73: assertEquals(pos, procPos);
74: }
75: }
|