Skip to content

Commit 1afc556

Browse files
committed
Migration to GitHub Actions
1 parent bd74fed commit 1afc556

File tree

16 files changed

+605
-136
lines changed

16 files changed

+605
-136
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
UTPLSQL_DOWNLOAD_URL=$(curl --silent https://api.github.com/repos/utPLSQL/utPLSQL/releases/latest | awk '/browser_download_url/ { print $2 }' | grep ".zip\"" | sed 's/"//g')
2+
3+
curl -Lk "${UTPLSQL_DOWNLOAD_URL}" -o utPLSQL.zip
4+
5+
unzip -q utPLSQL.zip
6+
7+
cd utPLSQL/source
8+
9+
sqlplus sys/oracle@//localhost/XE as sysdba @install_headless.sql UT3 UT3 users
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
define UTPLSQL_USER = 'UT3';
2+
define APP_USER = 'APP';
3+
define CODE_OWNER = 'CODE_OWNER';
4+
define TESTS_OWNER = 'TESTS_OWNER';
5+
define DB_PASS = 'pass';
6+
7+
grant execute any procedure to &UTPLSQL_USER;
8+
grant create any procedure to &UTPLSQL_USER;
9+
grant execute on dbms_lob to &UTPLSQL_USER;
10+
grant execute on dbms_sql to &UTPLSQL_USER;
11+
grant execute on dbms_xmlgen to &UTPLSQL_USER;
12+
grant execute on dbms_lock to &UTPLSQL_USER;
13+
14+
create user &APP_USER identified by &DB_PASS quota unlimited on USERS default tablespace USERS;
15+
grant create session, create procedure, create type, create table, create sequence, create view to &APP_USER;
16+
grant select any dictionary to &APP_USER;
17+
18+
create user &CODE_OWNER identified by &DB_PASS quota unlimited on USERS default tablespace USERS;
19+
grant create session, create procedure, create type, create table, create sequence, create view to &CODE_OWNER;
20+
21+
create user &TESTS_OWNER identified by &DB_PASS quota unlimited on USERS default tablespace USERS;
22+
grant create session, create procedure, create type, create table, create sequence, create view, create synonym to &TESTS_OWNER;
23+
grant select any dictionary to &TESTS_OWNER;
24+
grant select any table, delete any table, drop any table to &TESTS_OWNER;
25+
grant execute any procedure to &TESTS_OWNER;
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
ALTER SESSION SET CURRENT_SCHEMA = APP;
2+
3+
--
4+
-- This is a table used to demonstrate the UNIT test framework.
5+
--
6+
CREATE TABLE TO_TEST_ME
7+
(
8+
SNAME VARCHAR2(10)
9+
);
10+
/
11+
12+
--
13+
-- This package is used TO demonstrate the utPL/SQL possibilities
14+
--
15+
CREATE OR REPLACE PACKAGE PKG_TEST_ME AS
16+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER;
17+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2);
18+
END PKG_TEST_ME;
19+
/
20+
21+
CREATE OR REPLACE PACKAGE BODY PKG_TEST_ME IS
22+
--
23+
-- This
24+
--
25+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS
26+
BEGIN
27+
IF PPARAM1 IS NULL THEN
28+
RETURN NULL;
29+
ELSIF PPARAM1 = '1' THEN
30+
RETURN 1;
31+
ELSE
32+
RETURN 0;
33+
END IF;
34+
END FC_TEST_ME;
35+
36+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS
37+
BEGIN
38+
IF PSNAME IS NULL THEN
39+
NULL;
40+
ELSE
41+
INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME);
42+
COMMIT;
43+
END IF;
44+
END PR_TEST_ME;
45+
46+
END PKG_TEST_ME;
47+
/
48+
49+
CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS
50+
-- %suite(TEST_PKG_TEST_ME)
51+
-- %suitepath(plsql.examples)
52+
--
53+
-- This package shows all the possibilities to unit test
54+
-- your PL/SQL package. NOTE that it is not limited to
55+
-- testing your package. You can do that on all your
56+
-- procedure/functions...
57+
--
58+
59+
/**
60+
* This two parameters are used by the test framework in
61+
* order to identify the test suite to run
62+
*/
63+
64+
/*
65+
* This method is invoked once before any other method.
66+
* It should contain all the setup code that is relevant
67+
* for all your test. It might be inserting a register,
68+
* creating a type, etc...
69+
*/
70+
-- %beforeall
71+
PROCEDURE SETUP_GLOBAL;
72+
73+
/*
74+
* This method is invoked once after all other method.
75+
* It can be used to clean up all the resources that
76+
* you created in your script
77+
*/
78+
-- %afterall
79+
PROCEDURE TEARDOWN_GLOBAL;
80+
81+
/*
82+
* This method is called once before each test.
83+
*/
84+
-- %beforeeach
85+
PROCEDURE SETUP_TEST;
86+
87+
/*
88+
* This method is called once after each test.
89+
*/
90+
-- %aftereach
91+
PROCEDURE TEARDOWN_TEST;
92+
93+
/**
94+
* This is a real test. The main test can declare a setup
95+
* and teardown method in order to setup and cleanup things
96+
* for that specific test.
97+
*/
98+
-- %test
99+
-- %displayname(Checking if function ('1') returns 1)
100+
-- %beforetest(SETUP_TEST_FC_INPUT_1)
101+
-- %aftertest(TEARDOWN_TEST_FC_INPUT_1)
102+
PROCEDURE TEST_FC_INPUT_1;
103+
PROCEDURE SETUP_TEST_FC_INPUT_1;
104+
PROCEDURE TEARDOWN_TEST_FC_INPUT_1;
105+
106+
-- %test
107+
-- %displayname(Checking if function ('0') returns 0)
108+
PROCEDURE TEST_FC_INPUT_0;
109+
110+
-- %test
111+
-- %displayname(Checking if function (NULL) returns NULL)
112+
PROCEDURE TEST_FC_INPUT_NULL;
113+
114+
-- %test
115+
-- %displayname(Checking if procedure (NULL) insert)
116+
PROCEDURE TEST_PR_TEST_ME_NULL;
117+
118+
-- %test
119+
-- %displayname(Checking if procedure (NOT NULL) insert)
120+
-- %rollback(manual)
121+
PROCEDURE TEST_PR_TEST_ME_NOT_NULL;
122+
123+
-- %test
124+
-- %displayname(Checking if procedure (NOT NULL) insert while existing)
125+
-- %rollback(manual)
126+
-- %tags(exists)
127+
PROCEDURE TEST_PR_TEST_ME_EXISTS;
128+
129+
-- %test
130+
-- %displayname(Demonstrating the use of cursor)
131+
-- %rollback(manual)
132+
-- %tags(cursor)
133+
PROCEDURE TEST_PR_TEST_ME_CURSOR;
134+
135+
END;
136+
/
137+
138+
CREATE OR REPLACE PACKAGE BODY TEST_PKG_TEST_ME AS
139+
140+
---------------------------------------------------------------------------
141+
PROCEDURE SETUP_GLOBAL IS
142+
BEGIN
143+
-- Put here the code which is valid for all tests and that should be
144+
-- executed once.
145+
NULL;
146+
END SETUP_GLOBAL;
147+
148+
---------------------------------------------------------------------------
149+
PROCEDURE TEARDOWN_GLOBAL IS
150+
BEGIN
151+
-- Put here the code that should be called only once after all the test
152+
-- have executed
153+
NULL;
154+
END TEARDOWN_GLOBAL;
155+
156+
---------------------------------------------------------------------------
157+
PROCEDURE SETUP_TEST IS
158+
BEGIN
159+
-- Nothing to clean up globally
160+
NULL;
161+
END SETUP_TEST;
162+
163+
PROCEDURE TEARDOWN_TEST IS
164+
BEGIN
165+
-- Nothing to clean up globally
166+
NULL;
167+
END TEARDOWN_TEST;
168+
169+
PROCEDURE TEST_FC_INPUT_1 IS
170+
BEGIN
171+
-- Ok this is a real test where I check that the function return 1
172+
-- when called with a '1' parameter
173+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1);
174+
END;
175+
176+
PROCEDURE SETUP_TEST_FC_INPUT_1 IS
177+
BEGIN
178+
-- Nothing to be done really
179+
NULL;
180+
END;
181+
182+
PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS
183+
BEGIN
184+
-- Nothing to be done really
185+
NULL;
186+
END;
187+
188+
PROCEDURE TEST_FC_INPUT_0 IS
189+
BEGIN
190+
-- Ok this is a real test where I check that the function return 0
191+
-- when called with a '0' parameter
192+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0);
193+
END;
194+
195+
PROCEDURE TEST_FC_INPUT_NULL IS
196+
BEGIN
197+
-- Ok I check that the function return NULL
198+
-- when called with a NULL parameter
199+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL;
200+
END TEST_FC_INPUT_NULL;
201+
202+
PROCEDURE TEST_PR_TEST_ME_NULL IS
203+
VNCOUNT1 PLS_INTEGER;
204+
VNCOUNT2 PLS_INTEGER;
205+
BEGIN
206+
-- In this example I check that the procedure does
207+
-- not insert anything when passing it a NULL parameter
208+
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
209+
PKG_TEST_ME.PR_TEST_ME(NULL);
210+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
211+
UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2);
212+
END;
213+
214+
PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS
215+
VNCOUNT1 PLS_INTEGER;
216+
VNCOUNT2 PLS_INTEGER;
217+
VSNAME TO_TEST_ME.SNAME%TYPE;
218+
BEGIN
219+
-- In this test I will check that I do insert a value
220+
-- when the parameter is not null. I futher check that
221+
-- the procedure has inserted the value I specified.
222+
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
223+
VSNAME := TO_CHAR(VNCOUNT1);
224+
PKG_TEST_ME.PR_TEST_ME(VSNAME);
225+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
226+
227+
-- Check that I have inserted the value
228+
UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2);
229+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
230+
231+
-- Check that I inserted the one I said I would insert
232+
UT.EXPECT(VNCOUNT2).TO_EQUAL(1);
233+
DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
234+
COMMIT;
235+
END;
236+
237+
PROCEDURE TEST_PR_TEST_ME_EXISTS IS
238+
BEGIN
239+
-- In case the value exists the procedure should fail with an exception.
240+
BEGIN
241+
PKG_TEST_ME.PR_TEST_ME('EXISTS');
242+
PKG_TEST_ME.PR_TEST_ME('EXISTS');
243+
EXCEPTION
244+
WHEN OTHERS THEN
245+
UT.FAIL('Unexpected exception raised');
246+
END;
247+
END;
248+
249+
PROCEDURE TEST_PR_TEST_ME_CURSOR IS
250+
TYPE REF_CURSOR IS REF CURSOR;
251+
VEXPECTED REF_CURSOR;
252+
VACTUAL REF_CURSOR;
253+
BEGIN
254+
EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME';
255+
OPEN VEXPECTED FOR
256+
SELECT T.SNAME FROM TO_TEST_ME T;
257+
OPEN VACTUAL FOR
258+
SELECT T.SNAME FROM TO_TEST_ME T;
259+
UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL));
260+
END;
261+
262+
END;
263+
/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
ALTER SESSION SET CURRENT_SCHEMA = CODE_OWNER;
2+
3+
--
4+
-- This is a table used to demonstrate the UNIT test framework.
5+
--
6+
CREATE TABLE TO_TEST_ME
7+
(
8+
SNAME VARCHAR2(10)
9+
);
10+
/
11+
12+
--
13+
-- This package is used TO demonstrate the utPL/SQL possibilities
14+
--
15+
CREATE OR REPLACE PACKAGE CODE_OWNER.PKG_TEST_ME AS
16+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER;
17+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2);
18+
END PKG_TEST_ME;
19+
/
20+
21+
CREATE OR REPLACE PACKAGE BODY PKG_TEST_ME IS
22+
--
23+
-- This
24+
--
25+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS
26+
BEGIN
27+
IF PPARAM1 IS NULL THEN
28+
RETURN NULL;
29+
ELSIF PPARAM1 = '1' THEN
30+
RETURN 1;
31+
ELSE
32+
RETURN 0;
33+
END IF;
34+
END FC_TEST_ME;
35+
36+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS
37+
BEGIN
38+
IF PSNAME IS NULL THEN
39+
NULL;
40+
ELSE
41+
INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME);
42+
COMMIT;
43+
END IF;
44+
END PR_TEST_ME;
45+
46+
END PKG_TEST_ME;
47+
/

0 commit comments

Comments
 (0)