Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffdc4e3

Browse files
committed
Merge branch 'develop' into feature/cursor_comaprison_enchangements
# Conflicts: # test/install_tests.sql
2 parents 846f373 + b5fd362 commit ffdc4e3

6 files changed

Lines changed: 99 additions & 25 deletions

File tree

docs/userguide/annotations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ The annotation cache is checked for staleness and refreshed automatically on eve
224224

225225
If you are in a situation where your database is controlled via CI/CD server and is refreshed/wiped before each run of your tests, consider building the annotation cache upfront and taking a snapshot of the database after the cache has been refreshed.
226226

227-
To build the annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner, a_object_type)` for every unit test owner for which you want to have the annotation cache prebuilt.
227+
To build the annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner)` for every unit test owner for which you want to have the annotation cache prebuilt.
228228
Example:
229229
```sql
230-
exec ut_runner.rebuild_annotation_cache('HR', 'PACKAGE');
230+
exec ut_runner.rebuild_annotation_cache('HR');
231231
```
232232

233-
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner, a_object_type)`.
233+
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner)`.
234234
Example:
235235
```sql
236236
exec ut_runner.purge_cache('HR', 'PACKAGE');

source/api/ut_runner.pkb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,40 @@ create or replace package body ut_runner is
106106
end if;
107107
end;
108108

109-
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2) is
109+
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2 := null) is
110110
begin
111-
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, a_object_type);
111+
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, coalesce(a_object_type,'PACKAGE'));
112112
end;
113113

114-
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2) is
114+
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2 := null) is
115115
begin
116-
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
116+
ut_annotation_manager.purge_cache(a_object_owner, coalesce(a_object_type,'PACKAGE'));
117+
end;
118+
119+
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined is
120+
l_cursor sys_refcursor;
121+
l_filter varchar2(100);
122+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
123+
l_results tt_annotations;
124+
c_bulk_limit constant integer := 10;
125+
begin
126+
l_filter := case when a_package_name is null then 'is null' else '= o.object_name' end;
127+
open l_cursor for
128+
'select o.object_owner, o.object_name, upper(a.subobject_name),' ||
129+
' a.position, a.name, a.text' ||
130+
' from table('||l_ut_owner||'.ut_annotation_manager.get_annotated_objects(:a_owner, ''PACKAGE'')) o,' ||
131+
' table(o.annotations) a' ||
132+
' where :a_package_name ' || l_filter
133+
using a_owner, a_package_name;
134+
loop
135+
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
136+
for i in 1 .. l_results.count loop
137+
pipe row (l_results(i));
138+
end loop;
139+
exit when l_cursor%notfound;
140+
end loop;
141+
close l_cursor;
142+
return;
117143
end;
118144

119145
end ut_runner;

source/api/ut_runner.pks

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,43 @@ create or replace package ut_runner authid current_user is
6262
);
6363

6464
/**
65-
* Rebuilds annotation cache for a specified schema and object type.
66-
* The procedure is called internally by `get_annotated_objects` function.
67-
* It can be used to speedup initial execution of utPLSQL on a given schema
68-
* if it is executed before any call is made to `ut.run` or `ut_runner.run` procedure.
69-
*
70-
* @param a_object_owner owner of objects to get annotations for
71-
* @param a_object_type type of objects to get annotations for
72-
*/
73-
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2);
65+
* Rebuilds annotation cache for a specified schema and object type.
66+
* It can be used to speedup execution of utPLSQL on a given schema
67+
* if it is executed before initial call made to `ut.run` or `ut_runner.run` procedure.
68+
*
69+
* @param a_object_owner owner of objects to get annotations for
70+
* @param a_object_type optional type of objects to get annotations for (defaults to 'PACKAGE')
71+
*/
72+
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2 := null);
73+
74+
/**
75+
* Removes cached information about annotations for objects of specified type and specified owner
76+
*
77+
* @param a_object_owner owner of objects to purge annotations for
78+
* @param a_object_type optional type of objects to purge annotations for (defaults to 'PACKAGE')
79+
*/
80+
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2 := null);
81+
82+
83+
type t_annotation_rec is record (
84+
package_owner varchar2(250),
85+
package_name varchar2(250),
86+
procedure_name varchar2(250),
87+
annotation_pos number(5,0),
88+
annotation_name varchar2(1000),
89+
annotation_text varchar2(4000)
90+
);
91+
type tt_annotations is table of t_annotation_rec;
7492

7593
/**
76-
* Removes cached information about annotations for objects of specified type and specified owner
77-
*
78-
* @param a_object_owner owner of objects to purge annotations for
79-
* @param a_object_type type of objects to purge annotations for
80-
*/
81-
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2);
94+
* Returns a pipelined collection containing information about unit tests package/packages for a given owner
95+
*
96+
* @param a_owner owner of unit tests to retrieve
97+
* @param a_package_name optional name of unit test package to retrieve, if NULLm all unit test packages are returned
98+
* @return tt_annotations table of records
99+
*/
100+
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined;
101+
82102

83103
end ut_runner;
84104
/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,23 @@ end;';
258258
ut.expect(l_actual).to_equal(0);
259259
end;
260260

261+
procedure test_get_unit_test_info is
262+
l_expected sys_refcursor;
263+
l_actual sys_refcursor;
264+
begin
265+
--Arrange
266+
open l_expected for
267+
select 'UT3_TESTER' package_owner, 'DUMMY_TEST_PACKAGE' package_name,
268+
to_char(null) procedure_name, 1 annotation_pos, 'suite' annotation_name, 'dummy_test_suite' annotation_text
269+
from dual union all
270+
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', to_char(null), 2, 'rollback', 'manual' from dual union all
271+
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 3, 'test', 'dummy_test' from dual union all
272+
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 4, 'beforetest', 'some_procedure' from dual;
273+
--Act
274+
open l_actual for select * from table(ut3.ut_runner.get_unit_test_info('UT3_TESTER','DUMMY_TEST_PACKAGE'));
275+
--Assert
276+
ut.expect(l_actual).to_equal(l_expected);
277+
end;
278+
261279
end;
262280
/
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create or replace package test_ut_runner is
22

33
--%suite(ut_runner)
4-
--%suitepath(utplsql)
4+
--%suitepath(utplsql.api)
55
--%rollback(manual)
66

77
--%test(transaction stays open after the run if it was opened before the run)
@@ -43,5 +43,10 @@ create or replace package test_ut_runner is
4343
--%aftertest(cleanup_cache)
4444
procedure test_rebuild_cache_schema_type;
4545

46+
--%test(get_unit_tests_info returns a cursor containing records for a newly created test)
47+
--%beforetest(setup_cache_objects)
48+
--%aftertest(cleanup_cache)
49+
procedure test_get_unit_test_info;
50+
4651
end;
4752
/

test/install_tests.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ whenever oserror exit failure rollback
3737
@@core/expectations/scalar_data/unary/test_expect_to_be_not_null.pks
3838
@@core/expectations/scalar_data/unary/test_expect_to_be_null.pks
3939
@@core/expectations/scalar_data/unary/test_expect_to_be_true_false.pks
40-
@@test_ut_runner.pks
40+
@@api/test_ut_runner.pks
41+
@@core/expectations/test_expectations_cursor.pks
42+
@@core/expectations/test_expect_not_to_be_null.pks
43+
@@core/expectations/test_expect_to_be_not_null.pks
44+
@@core/expectations/test_expect_to_be_null.pks
45+
@@api/test_ut_runner.pks
4146
@@core/annotations/test_annotation_manager.pks
4247
@@core/test_ut_suite.pks
4348
@@core/test_ut_test.pks
@@ -65,7 +70,7 @@ whenever oserror exit failure rollback
6570
@@core/expectations/scalar_data/unary/test_expect_to_be_not_null.pkb
6671
@@core/expectations/scalar_data/unary/test_expect_to_be_null.pkb
6772
@@core/expectations/scalar_data/unary/test_expect_to_be_true_false.pkb
68-
@@test_ut_runner.pkb
73+
@@api/test_ut_runner.pkb
6974
@@core/annotations/test_annotation_manager.pkb
7075
@@core/test_ut_suite.pkb
7176
@@core/test_ut_test.pkb

0 commit comments

Comments
 (0)