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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Initial checkin
  • Loading branch information
lwasylow committed Mar 14, 2019
commit 7a4827800e839d1e9f7aef910c1b5f1cb0060c10
7 changes: 6 additions & 1 deletion source/core/ut_expectation_processor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ create or replace package body ut_expectation_processor as
begin
add_expectation_result(ut_expectation_result(ut_utils.gc_failure, null, a_message));
end;


procedure report_failure_no_caller(a_message in varchar2) is
Comment thread
lwasylow marked this conversation as resolved.
Outdated
begin
add_expectation_result(ut_expectation_result(ut_utils.gc_failure, null, a_message,false));
end;

function get_session_parameters return tt_nls_params is
l_session_params tt_nls_params;
begin
Expand Down
2 changes: 2 additions & 0 deletions source/core/ut_expectation_processor.pks
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ create or replace package ut_expectation_processor authid current_user as
procedure add_expectation_result(a_expectation_result ut_expectation_result);

procedure report_failure(a_message in varchar2);

procedure report_failure_no_caller(a_message in varchar2);

procedure set_xml_nls_params;

Expand Down
13 changes: 13 additions & 0 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -719,5 +719,18 @@ create or replace package body ut_utils is
return l_results;
end;

function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2 is
l_caller_stack_line varchar2(4000);
l_ora_search_pattern varchar2(500) := '^ORA'||a_ora_code||': (.*)$';
begin
l_caller_stack_line := regexp_replace(srcstr => a_error_stack
,pattern => l_ora_search_pattern
,replacestr => null
,position => 1
,occurrence => 1
,modifier => 'm');
return l_caller_stack_line;
end;

end ut_utils;
/
12 changes: 11 additions & 1 deletion source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ create or replace package ut_utils authid definer is
gc_dml_for_all constant pls_integer := -20215;
pragma exception_init (ex_dml_for_all, -20215);

ex_xml_processing exception;
gc_xml_processing constant pls_integer := -19202;
pragma exception_init (ex_xml_processing, -19202);

gc_max_storage_varchar2_len constant integer := 4000;
gc_max_output_string_length constant integer := 4000;
gc_max_input_string_length constant integer := gc_max_output_string_length - 2; --we need to remove 2 chars for quotes around string
Expand Down Expand Up @@ -353,6 +357,12 @@ create or replace package ut_utils authid definer is
* Returns list of sub-type reporters for given list of super-type reporters
*/
function get_child_reporters(a_for_reporters ut_reporters_info := null) return ut_reporters_info;


/**
* Remove given ORA error from stack
*/
function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2;


end ut_utils;
/
6 changes: 6 additions & 0 deletions source/expectations/data_values/ut_data_value_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ create or replace type body ut_data_value_refcursor as
exception
when cursor_not_open then
raise_application_error(-20155, 'Cursor is not open');
when ut_utils.ex_xml_processing then
if l_cursor%isopen then
close l_cursor;
end if;
ut_expectation_processor.report_failure_no_caller('Failed to process ref_cursor with error'||chr(10)||
ut_utils.remove_error_from_stack(sqlerrm,-19202));
when others then
if l_cursor%isopen then
close l_cursor;
Expand Down
94 changes: 94 additions & 0 deletions test/core/expectations/test_expectations_cursor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -2465,5 +2465,99 @@ Diff:%
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure xml_error_actual is
c_price CONSTANT NUMBER(20,4):= 1357;
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
open v_actual for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
open v_expected for
select c_price as usd_price_amt, c_user as update_id from dual;

ut3.ut.expect(v_actual).to_equal(v_expected);
--Assert
l_expected_message := q'[%Failed to process ref_cursor with error
%ORA-01722: invalid number
%Actual: refcursor [ count = ] was expected to equal: refcursor [ count = 1 ]
%Diff:
%Columns:
%Column <USD_PRICE_AMT> [data-type: NUMBER] is missing. Expected column position: 1.
%Column <UPDATE_ID> [data-type: VARCHAR2] is missing. Expected column position: 2.
%Rows: [ 1 differences ]
%Row No. 1 - Missing: <USD_PRICE_AMT>1357</USD_PRICE_AMT><UPDATE_ID>TEST_USER</UPDATE_ID>]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure xml_error_expected is
c_price CONSTANT NUMBER(20,4):= 1357;
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
open v_expected for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
open v_actual for
select c_price as usd_price_amt, c_user as update_id from dual;

ut3.ut.expect(v_actual).to_equal(v_expected);
--Assert
l_expected_message := q'[%Failed to process ref_cursor with error
%ORA-01722: invalid number
%Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = ]
%Diff:
%Columns:
%Column <USD_PRICE_AMT> [data-type: NUMBER] is missing. Expected column position: 1.
%Column <UPDATE_ID> [data-type: VARCHAR2] is missing. Expected column position: 2.
%Rows: [ 1 differences ]
%Row No. 1 - Extra: <USD_PRICE_AMT>1357</USD_PRICE_AMT><UPDATE_ID>TEST_USER</UPDATE_ID>]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure xml_error_both is
c_price CONSTANT NUMBER(20,4):= 1357;
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
open v_actual for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
open v_expected for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;

ut3.ut.expect(v_actual).to_equal(v_expected);
--Assert
l_expected_message := q'[%Failed to process ref_cursor with error
%ORA-01722: invalid number
%Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = ]
%Diff:
%Columns:
%Column <USD_PRICE_AMT> [data-type: NUMBER] is missing. Expected column position: 1.
%Column <UPDATE_ID> [data-type: VARCHAR2] is missing. Expected column position: 2.
%Rows: [ 1 differences ]
%Row No. 1 - Extra: <USD_PRICE_AMT>1357</USD_PRICE_AMT><UPDATE_ID>TEST_USER</UPDATE_ID>]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

end;
/
9 changes: 9 additions & 0 deletions test/core/expectations/test_expectations_cursor.pks
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ create or replace package test_expectations_cursor is

--%test(Cursor to contain duplicates fail)
procedure to_contain_duplicates_fail;

--%test(Fail to process a cursor for actual)
procedure xml_error_actual;

--%test(Fail to process a cursor for expected)
procedure xml_error_expected;

--%test(Fail to process a cursor for both)
procedure xml_error_both;

end;
/