Skip to content

Commit

Permalink
Refactored procedure get_unit_test_info to return more relevant inf…
Browse files Browse the repository at this point in the history
…ormation based on info suite cache.

Suite cache is refreshed when calling procedure (as needed).
  • Loading branch information
jgebal committed Nov 16, 2018
1 parent f7f6811 commit d002d18
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 59 deletions.
15 changes: 3 additions & 12 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,12 @@ create or replace package body ut_runner is
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
end;

function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined is
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 ) return ut_suite_items_info pipelined is
l_cursor sys_refcursor;
l_filter varchar2(100);
l_ut_owner varchar2(250) := ut_utils.ut_owner;
l_results tt_annotations;
l_results ut_suite_items_info;
c_bulk_limit constant integer := 10;
begin
l_filter := case when a_package_name is null then 'is null' else '= o.object_name' end;
open l_cursor for
'select o.object_owner, o.object_name, upper(a.subobject_name),' ||
' a.position, a.name, a.text' ||
' from table('||l_ut_owner||'.ut_annotation_manager.get_annotated_objects(:a_owner, ''PACKAGE'')) o,' ||
' table(o.annotations) a' ||
' where :a_package_name ' || l_filter
using a_owner, a_package_name;
l_cursor := ut_suite_manager.get_suites_info( a_owner, a_package_name );
loop
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
for i in 1 .. l_results.count loop
Expand Down
16 changes: 3 additions & 13 deletions source/api/ut_runner.pks
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,14 @@ create or replace package ut_runner authid current_user is
procedure purge_cache(a_object_owner varchar2 := null, a_object_type varchar2 := null);


type t_annotation_rec is record (
package_owner varchar2(250),
package_name varchar2(250),
procedure_name varchar2(250),
annotation_pos number(5,0),
annotation_name varchar2(1000),
annotation_text varchar2(4000)
);
type tt_annotations is table of t_annotation_rec;

/**
* Returns a pipelined collection containing information about unit tests package/packages for a given owner
* Returns a pipelined collection containing information about unit test suites and the tests contained in them
*
* @param a_owner owner of unit tests to retrieve
* @param a_package_name optional name of unit test package to retrieve, if NULLm all unit test packages are returned
* @return tt_annotations table of records
* @return ut_suite_items_info table of objects
*/
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined;
function get_unit_test_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined;

type t_reporter_rec is record (
reporter_object_name varchar2(250),
Expand Down
27 changes: 27 additions & 0 deletions source/api/ut_suite_item_info.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
create or replace type ut_suite_item_info as object (
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
object_owner varchar2(250),
object_name varchar2(250),
item_name varchar2(250),
item_description varchar2(250),
item_type varchar2(250),
item_line_no integer,
path varchar2(4000),
disabled_flag integer
)
/
19 changes: 19 additions & 0 deletions source/api/ut_suite_items_info.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create or replace type ut_suite_items_info as
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
table of ut_suite_item_info
/
32 changes: 16 additions & 16 deletions source/core/ut_suite_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,14 @@ create or replace package body ut_suite_manager is

end configure_execution_by_path;

function get_suites_info(a_owner_name varchar2) return tt_suite_items pipelined is
l_cursor sys_refcursor;
function get_suites_info(a_owner_name varchar2, a_package_name varchar2) return sys_refcursor is
l_result sys_refcursor;
l_ut_owner varchar2(250) := ut_utils.ut_owner;
c_bulk_limit constant integer := 100;
l_results tt_suite_items;
begin

refresh_cache(a_owner_name);

open l_cursor for
open l_result for
q'[with
suite_items as (
select /*+ cardinality(c 100) */ c.*
Expand All @@ -696,7 +695,12 @@ create or replace package body ut_suite_manager is
and a.owner = c.object_owner
and a.object_type = 'PACKAGE'
)]' end ||q'[
and c.object_owner = ']'||upper(a_owner_name)||q'['
and c.object_owner = ']'||upper(a_owner_name) ||q'['
and ]'
|| case when a_package_name is not null
then 'c.object_name = :a_package_name'
else ':a_package_name is null' end
|| q'[
),
suitepaths as (
select distinct
Expand Down Expand Up @@ -737,17 +741,13 @@ create or replace package body ut_suite_manager is
s.path, 0 as disabled_flag
from logical_suites s
)
select c.*
from items c]';
loop
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
for i in 1 .. l_results.count loop
pipe row (l_results(i));
end loop;
exit when l_cursor%notfound;
end loop;
close l_cursor;
select ]'||l_ut_owner||q'[.ut_suite_item_info(
object_owner, object_name, item_name, item_description,
item_type, item_line_no, path, disabled_flag
)
from items c]' using upper(a_package_name);

return l_result;
end;

end ut_suite_manager;
Expand Down
20 changes: 7 additions & 13 deletions source/core/ut_suite_manager.pks
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,14 @@ create or replace package ut_suite_manager authid current_user is
a_skip_all_objects boolean := false
) return ut_suite_items;

type t_suite_item_rec is record (
object_owner varchar2(250),
object_name varchar2(250),
item_name varchar2(250),
item_description varchar2(250),
item_type varchar2(250),
item_line_no varchar2(250),
path varchar2(4000),
disabled_flag integer
);

type tt_suite_items is table of t_suite_item_rec;

function get_suites_info(a_owner_name varchar2) return tt_suite_items pipelined;
/**
* Returns a ref cursor containing information about unit test suites and the tests contained in them
*
* @param a_owner owner of unit tests to retrieve
* @return ut_suite_items_info table of objects
*/
function get_suites_info(a_owner_name varchar2, a_package_name varchar2) return sys_refcursor;


end ut_suite_manager;
Expand Down
4 changes: 4 additions & 0 deletions source/create_synonyms_and_grants_for_public.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ grant execute on &&ut3_owner..ut_annotation_cache_manager to public;
grant execute on &&ut3_owner..ut_annotation_parser to public;
grant execute on &&ut3_owner..ut_annotation_objs_cache_info to public;
grant execute on &&ut3_owner..ut_annotation_obj_cache_info to public;
grant execute on &&ut3_owner..ut_suite_items_info to public;
grant execute on &&ut3_owner..ut_suite_item_info to public;
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_blocks to public';
Expand Down Expand Up @@ -152,6 +154,8 @@ create public synonym ut_file_mapper for &&ut3_owner..ut_file_mapper;
create public synonym ut_key_value_pairs for &&ut3_owner..ut_key_value_pairs;
create public synonym ut_key_value_pair for &&ut3_owner..ut_key_value_pair;
create public synonym ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter;
create public synonym ut_suite_items_info for &&ut3_owner..ut_suite_items_info;
create public synonym ut_suite_item_info for &&ut3_owner..ut_suite_item_info;
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
execute immediate 'create public synonym dbmspcc_blocks for &&ut3_owner..dbmspcc_blocks';
Expand Down
2 changes: 2 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'reporters/ut_documentation_reporter.tpb'

--plugin interface API for running utPLSQL
@@install_component.sql 'api/ut_suite_item_info.tps'
@@install_component.sql 'api/ut_suite_items_info.tps'
@@install_component.sql 'api/ut_runner.pks'
@@install_component.sql 'api/ut_runner.pkb'

Expand Down
4 changes: 4 additions & 0 deletions source/uninstall_objects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ drop package ut_teamcity_reporter_helper;

drop package ut_runner;

drop type ut_suite_items_info force;

drop type ut_suite_item_info force;

drop package ut_suite_manager;

drop package ut_suite_builder;
Expand Down
14 changes: 9 additions & 5 deletions test/api/test_ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,16 @@ end;';
begin
--Arrange
open l_expected for
select 'UT3_TESTER' package_owner, 'DUMMY_TEST_PACKAGE' package_name,
to_char(null) procedure_name, 2 annotation_pos, 'suite' annotation_name, 'dummy_test_suite' annotation_text
select
'UT3_TESTER' object_owner, 'DUMMY_TEST_PACKAGE' object_name, 'DUMMY_TEST_PACKAGE' item_name,
'dummy_test_suite' item_description, 'UT_SUITE' item_type, 2 item_line_no,
'dummy_test_package' path, 0 disabled_flag
from dual union all
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', to_char(null), 3, 'rollback', 'manual' from dual union all
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 5, 'test', 'dummy_test' from dual union all
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 6, 'beforetest', 'some_procedure' from dual;
select
'UT3_TESTER' object_owner, 'DUMMY_TEST_PACKAGE' object_name, 'SOME_DUMMY_TEST_PROCEDURE' item_name,
'dummy_test' item_description, 'UT_TEST' item_type, 5 item_line_no,
'dummy_test_package.some_dummy_test_procedure' path, 0 disabled_flag
from dual;
--Act
open l_actual for select * from table(ut3.ut_runner.get_unit_test_info('UT3_TESTER','DUMMY_TEST_PACKAGE'));
--Assert
Expand Down

0 comments on commit d002d18

Please sign in to comment.