Skip to content

Commit d002d18

Browse files
committed
Refactored procedure get_unit_test_info to return more relevant information based on info suite cache.
Suite cache is refreshed when calling procedure (as needed).
1 parent f7f6811 commit d002d18

10 files changed

Lines changed: 94 additions & 59 deletions

source/api/ut_runner.pkb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,12 @@ create or replace package body ut_runner is
165165
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
166166
end;
167167

168-
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined is
168+
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 ) return ut_suite_items_info pipelined is
169169
l_cursor sys_refcursor;
170-
l_filter varchar2(100);
171-
l_ut_owner varchar2(250) := ut_utils.ut_owner;
172-
l_results tt_annotations;
170+
l_results ut_suite_items_info;
173171
c_bulk_limit constant integer := 10;
174172
begin
175-
l_filter := case when a_package_name is null then 'is null' else '= o.object_name' end;
176-
open l_cursor for
177-
'select o.object_owner, o.object_name, upper(a.subobject_name),' ||
178-
' a.position, a.name, a.text' ||
179-
' from table('||l_ut_owner||'.ut_annotation_manager.get_annotated_objects(:a_owner, ''PACKAGE'')) o,' ||
180-
' table(o.annotations) a' ||
181-
' where :a_package_name ' || l_filter
182-
using a_owner, a_package_name;
173+
l_cursor := ut_suite_manager.get_suites_info( a_owner, a_package_name );
183174
loop
184175
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
185176
for i in 1 .. l_results.count loop

source/api/ut_runner.pks

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,14 @@ create or replace package ut_runner authid current_user is
8787
procedure purge_cache(a_object_owner varchar2 := null, a_object_type varchar2 := null);
8888

8989

90-
type t_annotation_rec is record (
91-
package_owner varchar2(250),
92-
package_name varchar2(250),
93-
procedure_name varchar2(250),
94-
annotation_pos number(5,0),
95-
annotation_name varchar2(1000),
96-
annotation_text varchar2(4000)
97-
);
98-
type tt_annotations is table of t_annotation_rec;
99-
10090
/**
101-
* Returns a pipelined collection containing information about unit tests package/packages for a given owner
91+
* Returns a pipelined collection containing information about unit test suites and the tests contained in them
10292
*
10393
* @param a_owner owner of unit tests to retrieve
10494
* @param a_package_name optional name of unit test package to retrieve, if NULLm all unit test packages are returned
105-
* @return tt_annotations table of records
95+
* @return ut_suite_items_info table of objects
10696
*/
107-
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined;
97+
function get_unit_test_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined;
10898

10999
type t_reporter_rec is record (
110100
reporter_object_name varchar2(250),

source/api/ut_suite_item_info.tps

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
create or replace type ut_suite_item_info as object (
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2018 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
object_owner varchar2(250),
19+
object_name varchar2(250),
20+
item_name varchar2(250),
21+
item_description varchar2(250),
22+
item_type varchar2(250),
23+
item_line_no integer,
24+
path varchar2(4000),
25+
disabled_flag integer
26+
)
27+
/

source/api/ut_suite_items_info.tps

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
create or replace type ut_suite_items_info as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2018 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
table of ut_suite_item_info
19+
/

source/core/ut_suite_manager.pkb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -674,15 +674,14 @@ create or replace package body ut_suite_manager is
674674

675675
end configure_execution_by_path;
676676

677-
function get_suites_info(a_owner_name varchar2) return tt_suite_items pipelined is
678-
l_cursor sys_refcursor;
677+
function get_suites_info(a_owner_name varchar2, a_package_name varchar2) return sys_refcursor is
678+
l_result sys_refcursor;
679679
l_ut_owner varchar2(250) := ut_utils.ut_owner;
680-
c_bulk_limit constant integer := 100;
681-
l_results tt_suite_items;
682680
begin
681+
683682
refresh_cache(a_owner_name);
684683

685-
open l_cursor for
684+
open l_result for
686685
q'[with
687686
suite_items as (
688687
select /*+ cardinality(c 100) */ c.*
@@ -696,7 +695,12 @@ create or replace package body ut_suite_manager is
696695
and a.owner = c.object_owner
697696
and a.object_type = 'PACKAGE'
698697
)]' end ||q'[
699-
and c.object_owner = ']'||upper(a_owner_name)||q'['
698+
and c.object_owner = ']'||upper(a_owner_name) ||q'['
699+
and ]'
700+
|| case when a_package_name is not null
701+
then 'c.object_name = :a_package_name'
702+
else ':a_package_name is null' end
703+
|| q'[
700704
),
701705
suitepaths as (
702706
select distinct
@@ -737,17 +741,13 @@ create or replace package body ut_suite_manager is
737741
s.path, 0 as disabled_flag
738742
from logical_suites s
739743
)
740-
select c.*
741-
from items c]';
742-
loop
743-
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
744-
for i in 1 .. l_results.count loop
745-
pipe row (l_results(i));
746-
end loop;
747-
exit when l_cursor%notfound;
748-
end loop;
749-
close l_cursor;
744+
select ]'||l_ut_owner||q'[.ut_suite_item_info(
745+
object_owner, object_name, item_name, item_description,
746+
item_type, item_line_no, path, disabled_flag
747+
)
748+
from items c]' using upper(a_package_name);
750749

750+
return l_result;
751751
end;
752752

753753
end ut_suite_manager;

source/core/ut_suite_manager.pks

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,14 @@ create or replace package ut_suite_manager authid current_user is
6868
a_skip_all_objects boolean := false
6969
) return ut_suite_items;
7070

71-
type t_suite_item_rec is record (
72-
object_owner varchar2(250),
73-
object_name varchar2(250),
74-
item_name varchar2(250),
75-
item_description varchar2(250),
76-
item_type varchar2(250),
77-
item_line_no varchar2(250),
78-
path varchar2(4000),
79-
disabled_flag integer
80-
);
8171

82-
type tt_suite_items is table of t_suite_item_rec;
83-
84-
function get_suites_info(a_owner_name varchar2) return tt_suite_items pipelined;
72+
/**
73+
* Returns a ref cursor containing information about unit test suites and the tests contained in them
74+
*
75+
* @param a_owner owner of unit tests to retrieve
76+
* @return ut_suite_items_info table of objects
77+
*/
78+
function get_suites_info(a_owner_name varchar2, a_package_name varchar2) return sys_refcursor;
8579

8680

8781
end ut_suite_manager;

source/create_synonyms_and_grants_for_public.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ grant execute on &&ut3_owner..ut_annotation_cache_manager to public;
9595
grant execute on &&ut3_owner..ut_annotation_parser to public;
9696
grant execute on &&ut3_owner..ut_annotation_objs_cache_info to public;
9797
grant execute on &&ut3_owner..ut_annotation_obj_cache_info to public;
98+
grant execute on &&ut3_owner..ut_suite_items_info to public;
99+
grant execute on &&ut3_owner..ut_suite_item_info to public;
98100
begin
99101
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
100102
execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_blocks to public';
@@ -152,6 +154,8 @@ create public synonym ut_file_mapper for &&ut3_owner..ut_file_mapper;
152154
create public synonym ut_key_value_pairs for &&ut3_owner..ut_key_value_pairs;
153155
create public synonym ut_key_value_pair for &&ut3_owner..ut_key_value_pair;
154156
create public synonym ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter;
157+
create public synonym ut_suite_items_info for &&ut3_owner..ut_suite_items_info;
158+
create public synonym ut_suite_item_info for &&ut3_owner..ut_suite_item_info;
155159
begin
156160
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
157161
execute immediate 'create public synonym dbmspcc_blocks for &&ut3_owner..dbmspcc_blocks';

source/install.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
259259
@@install_component.sql 'reporters/ut_documentation_reporter.tpb'
260260

261261
--plugin interface API for running utPLSQL
262+
@@install_component.sql 'api/ut_suite_item_info.tps'
263+
@@install_component.sql 'api/ut_suite_items_info.tps'
262264
@@install_component.sql 'api/ut_runner.pks'
263265
@@install_component.sql 'api/ut_runner.pkb'
264266

source/uninstall_objects.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ drop package ut_teamcity_reporter_helper;
5151

5252
drop package ut_runner;
5353

54+
drop type ut_suite_items_info force;
55+
56+
drop type ut_suite_item_info force;
57+
5458
drop package ut_suite_manager;
5559

5660
drop package ut_suite_builder;

test/api/test_ut_runner.pkb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,16 @@ end;';
273273
begin
274274
--Arrange
275275
open l_expected for
276-
select 'UT3_TESTER' package_owner, 'DUMMY_TEST_PACKAGE' package_name,
277-
to_char(null) procedure_name, 2 annotation_pos, 'suite' annotation_name, 'dummy_test_suite' annotation_text
276+
select
277+
'UT3_TESTER' object_owner, 'DUMMY_TEST_PACKAGE' object_name, 'DUMMY_TEST_PACKAGE' item_name,
278+
'dummy_test_suite' item_description, 'UT_SUITE' item_type, 2 item_line_no,
279+
'dummy_test_package' path, 0 disabled_flag
278280
from dual union all
279-
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', to_char(null), 3, 'rollback', 'manual' from dual union all
280-
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 5, 'test', 'dummy_test' from dual union all
281-
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 6, 'beforetest', 'some_procedure' from dual;
281+
select
282+
'UT3_TESTER' object_owner, 'DUMMY_TEST_PACKAGE' object_name, 'SOME_DUMMY_TEST_PROCEDURE' item_name,
283+
'dummy_test' item_description, 'UT_TEST' item_type, 5 item_line_no,
284+
'dummy_test_package.some_dummy_test_procedure' path, 0 disabled_flag
285+
from dual;
282286
--Act
283287
open l_actual for select * from table(ut3.ut_runner.get_unit_test_info('UT3_TESTER','DUMMY_TEST_PACKAGE'));
284288
--Assert

0 commit comments

Comments
 (0)