From 7a4827800e839d1e9f7aef910c1b5f1cb0060c10 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Thu, 14 Mar 2019 16:25:27 +0000 Subject: [PATCH 01/16] Initial checkin --- source/core/ut_expectation_processor.pkb | 7 +- source/core/ut_expectation_processor.pks | 2 + source/core/ut_utils.pkb | 13 +++ source/core/ut_utils.pks | 12 ++- .../data_values/ut_data_value_refcursor.tpb | 6 ++ .../expectations/test_expectations_cursor.pkb | 94 +++++++++++++++++++ .../expectations/test_expectations_cursor.pks | 9 ++ 7 files changed, 141 insertions(+), 2 deletions(-) diff --git a/source/core/ut_expectation_processor.pkb b/source/core/ut_expectation_processor.pkb index 170846125..f0b0a72a7 100644 --- a/source/core/ut_expectation_processor.pkb +++ b/source/core/ut_expectation_processor.pkb @@ -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 + 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 diff --git a/source/core/ut_expectation_processor.pks b/source/core/ut_expectation_processor.pks index f58de2441..017b6aaba 100644 --- a/source/core/ut_expectation_processor.pks +++ b/source/core/ut_expectation_processor.pks @@ -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; diff --git a/source/core/ut_utils.pkb b/source/core/ut_utils.pkb index 79d2df10f..11602ae1f 100644 --- a/source/core/ut_utils.pkb +++ b/source/core/ut_utils.pkb @@ -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; / diff --git a/source/core/ut_utils.pks b/source/core/ut_utils.pks index e4f0641d2..0c779fd09 100644 --- a/source/core/ut_utils.pks +++ b/source/core/ut_utils.pks @@ -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 @@ -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; / diff --git a/source/expectations/data_values/ut_data_value_refcursor.tpb b/source/expectations/data_values/ut_data_value_refcursor.tpb index 53c881693..24febc46c 100644 --- a/source/expectations/data_values/ut_data_value_refcursor.tpb +++ b/source/expectations/data_values/ut_data_value_refcursor.tpb @@ -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; diff --git a/test/core/expectations/test_expectations_cursor.pkb b/test/core/expectations/test_expectations_cursor.pkb index 599745de7..e212bf076 100644 --- a/test/core/expectations/test_expectations_cursor.pkb +++ b/test/core/expectations/test_expectations_cursor.pkb @@ -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 [data-type: NUMBER] is missing. Expected column position: 1. +%Column [data-type: VARCHAR2] is missing. Expected column position: 2. +%Rows: [ 1 differences ] +%Row No. 1 - Missing: 1357TEST_USER]'; + + 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 [data-type: NUMBER] is missing. Expected column position: 1. +%Column [data-type: VARCHAR2] is missing. Expected column position: 2. +%Rows: [ 1 differences ] +%Row No. 1 - Extra: 1357TEST_USER]'; + + 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 [data-type: NUMBER] is missing. Expected column position: 1. +%Column [data-type: VARCHAR2] is missing. Expected column position: 2. +%Rows: [ 1 differences ] +%Row No. 1 - Extra: 1357TEST_USER]'; + + 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; / diff --git a/test/core/expectations/test_expectations_cursor.pks b/test/core/expectations/test_expectations_cursor.pks index c0195393e..26605addd 100644 --- a/test/core/expectations/test_expectations_cursor.pks +++ b/test/core/expectations/test_expectations_cursor.pks @@ -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; / From ad3ce1074ac0eb35516e581f4a44f3335fb69bfe Mon Sep 17 00:00:00 2001 From: lwasylow Date: Sat, 16 Mar 2019 11:45:17 +0000 Subject: [PATCH 02/16] Adding handling of xml error --- .../data_values/ut_data_value_refcursor.tpb | 8 +-- .../expectations/test_expectations_cursor.pkb | 53 +++++++------------ 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/source/expectations/data_values/ut_data_value_refcursor.tpb b/source/expectations/data_values/ut_data_value_refcursor.tpb index a470b4f61..26a820fb7 100644 --- a/source/expectations/data_values/ut_data_value_refcursor.tpb +++ b/source/expectations/data_values/ut_data_value_refcursor.tpb @@ -100,8 +100,8 @@ create or replace type body ut_data_value_refcursor as 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)); + ut_expectation_processor.report_failure_no_caller('SQL exception thrown when fetching data from cursor: '|| + ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||'Check the query and data for errors.'); when others then if l_cursor%isopen then close l_cursor; @@ -117,7 +117,9 @@ create or replace type body ut_data_value_refcursor as dbms_lob.createtemporary(l_result, true); ut_utils.append_to_clob(l_result, 'Data-types:'||chr(10)); - ut_utils.append_to_clob( l_result, self.cursor_details.get_xml_children().getclobval() ); + if self.cursor_details.cursor_columns_info.count > 0 then + ut_utils.append_to_clob( l_result, self.cursor_details.get_xml_children().getclobval() ); + end if; ut_utils.append_to_clob(l_result,chr(10)||(self as ut_compound_data_value).to_string()); l_result_string := ut_utils.to_string(l_result,null); dbms_lob.freetemporary(l_result); diff --git a/test/core/expectations/test_expectations_cursor.pkb b/test/core/expectations/test_expectations_cursor.pkb index e904d8419..ed7dd5479 100644 --- a/test/core/expectations/test_expectations_cursor.pkb +++ b/test/core/expectations/test_expectations_cursor.pkb @@ -972,18 +972,21 @@ Rows: [ 4 differences ] procedure reports_on_exception_in_cursor as l_actual sys_refcursor; - l_error_code integer := -19202; --Error occurred in XML processing + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); begin --Act open l_actual for select 1/0 as error_column from dual connect by level < 10; - begin ut3.ut.expect(l_actual).to_be_empty(); --Assert - ut.fail('Expected '||l_error_code||' but nothing was raised'); - exception - when others then - ut.expect(sqlcode).to_equal(l_error_code); - end; + --Assert + l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% +%ORA-01476: divisor is equal to zero% +%Check the query and data for errors.]'; + + 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 exception_when_closed_cursor @@ -2481,15 +2484,9 @@ Diff:% 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 [data-type: NUMBER] is missing. Expected column position: 1. -%Column [data-type: VARCHAR2] is missing. Expected column position: 2. -%Rows: [ 1 differences ] -%Row No. 1 - Missing: 1357TEST_USER]'; + l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% +%ORA-01722: invalid number% +%Check the query and data for errors.]'; l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; --Assert @@ -2512,15 +2509,9 @@ Diff:% 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 [data-type: NUMBER] is missing. Expected column position: 1. -%Column [data-type: VARCHAR2] is missing. Expected column position: 2. -%Rows: [ 1 differences ] -%Row No. 1 - Extra: 1357TEST_USER]'; + l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% +%ORA-01722: invalid number% +%Check the query and data for errors.]'; l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; --Assert @@ -2544,15 +2535,9 @@ Diff:% 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 [data-type: NUMBER] is missing. Expected column position: 1. -%Column [data-type: VARCHAR2] is missing. Expected column position: 2. -%Rows: [ 1 differences ] -%Row No. 1 - Extra: 1357TEST_USER]'; + l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% +%ORA-01722: invalid number% +%Check the query and data for errors.]'; l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; --Assert From 90eb8c9109e471a6cf4ade7da30b511d2472537d Mon Sep 17 00:00:00 2001 From: lwasylow Date: Thu, 4 Apr 2019 08:37:06 +0100 Subject: [PATCH 03/16] Cursor error handling --- source/core/ut_utils.pkb | 8 ++++ source/core/ut_utils.pks | 5 +++ .../data_values/ut_data_value_refcursor.tpb | 3 +- .../expectations/test_expectations_cursor.pkb | 43 +++---------------- .../expectations/test_expectations_cursor.pks | 5 +-- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/source/core/ut_utils.pkb b/source/core/ut_utils.pkb index 830369349..dce71a1cb 100644 --- a/source/core/ut_utils.pkb +++ b/source/core/ut_utils.pkb @@ -750,5 +750,13 @@ create or replace package body ut_utils is return l_caller_stack_line; end; + function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is + begin + return 'SQL exception thrown when fetching data from cursor: '|| + remove_error_from_stack(sqlerrm,-19202)||chr(10)|| + ut_expectation_processor.who_called_expectation(a_error_stack)||chr(10)|| + 'Check the query and data for errors.'; + end; + end ut_utils; / diff --git a/source/core/ut_utils.pks b/source/core/ut_utils.pks index 45b49e965..f47fdcca1 100644 --- a/source/core/ut_utils.pks +++ b/source/core/ut_utils.pks @@ -113,6 +113,10 @@ create or replace package ut_utils authid definer is gc_xml_processing constant pls_integer := -19202; pragma exception_init (ex_xml_processing, -19202); + ex_failed_open_cur exception; + gc_failed_open_cur constant pls_integer := -20218; + pragma exception_init (ex_failed_open_cur, -20218); + gc_max_storage_varchar2_len constant integer := 4000; gc_max_output_string_length constant integer := 4000; gc_more_data_string constant varchar2(5) := '[...]'; @@ -378,6 +382,7 @@ create or replace package ut_utils authid definer is */ function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2; + function create_err_cursor_msg(a_error_stack varchar2) return varchar2; end ut_utils; / diff --git a/source/expectations/data_values/ut_data_value_refcursor.tpb b/source/expectations/data_values/ut_data_value_refcursor.tpb index 26a820fb7..5c40e49d5 100644 --- a/source/expectations/data_values/ut_data_value_refcursor.tpb +++ b/source/expectations/data_values/ut_data_value_refcursor.tpb @@ -100,8 +100,7 @@ create or replace type body ut_data_value_refcursor as if l_cursor%isopen then close l_cursor; end if; - ut_expectation_processor.report_failure_no_caller('SQL exception thrown when fetching data from cursor: '|| - ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||'Check the query and data for errors.'); + raise_application_error(ut_utils.gc_failed_open_cur,ut_utils.create_err_cursor_msg(dbms_utility.format_call_stack())); when others then if l_cursor%isopen then close l_cursor; diff --git a/test/core/expectations/test_expectations_cursor.pkb b/test/core/expectations/test_expectations_cursor.pkb index ed7dd5479..bd3fbe78e 100644 --- a/test/core/expectations/test_expectations_cursor.pkb +++ b/test/core/expectations/test_expectations_cursor.pkb @@ -2484,9 +2484,9 @@ Diff:% ut3.ut.expect(v_actual).to_equal(v_expected); --Assert - l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% + l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor: %ORA-01722: invalid number% -%Check the query and data for errors.]'; +at%ut.expect(v_actual).to_equal(v_expected)%]'; l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; --Assert @@ -2494,50 +2494,21 @@ Diff:% 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'[%SQL exception thrown when fetching data from cursor:% -%ORA-01722: invalid number% -%Check the query and data for errors.]'; - - 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 + select 1/0 as test from dual; 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; + select 1 as test from dual; ut3.ut.expect(v_actual).to_equal(v_expected); --Assert - l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% -%ORA-01722: invalid number% -%Check the query and data for errors.]'; + l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor: +%ORA-01476: divisor is equal to zero% +%at % ut.expect(v_actual).to_equal(v_expected)%]'; l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; --Assert diff --git a/test/core/expectations/test_expectations_cursor.pks b/test/core/expectations/test_expectations_cursor.pks index 26605addd..b6f1345a8 100644 --- a/test/core/expectations/test_expectations_cursor.pks +++ b/test/core/expectations/test_expectations_cursor.pks @@ -396,9 +396,6 @@ create or replace package test_expectations_cursor is --%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; / From b56b8efd81a2ee731822cec13f0ad882f5f8b550 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Thu, 4 Apr 2019 13:37:19 +0100 Subject: [PATCH 04/16] Update tests for handling usr friendly error --- source/core/ut_utils.pkb | 8 +--- source/core/ut_utils.pks | 4 +- .../data_values/ut_compound_data_helper.pkb | 8 ++++ .../data_values/ut_compound_data_helper.pks | 2 + .../data_values/ut_data_value_refcursor.tpb | 3 +- .../expectations/test_expectations_cursor.pkb | 43 +++++++------------ 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/source/core/ut_utils.pkb b/source/core/ut_utils.pkb index dce71a1cb..25ef3fb3f 100644 --- a/source/core/ut_utils.pkb +++ b/source/core/ut_utils.pkb @@ -750,13 +750,7 @@ create or replace package body ut_utils is return l_caller_stack_line; end; - function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is - begin - return 'SQL exception thrown when fetching data from cursor: '|| - remove_error_from_stack(sqlerrm,-19202)||chr(10)|| - ut_expectation_processor.who_called_expectation(a_error_stack)||chr(10)|| - 'Check the query and data for errors.'; - end; + end ut_utils; / diff --git a/source/core/ut_utils.pks b/source/core/ut_utils.pks index 8fb232a1b..a7a5718ed 100644 --- a/source/core/ut_utils.pks +++ b/source/core/ut_utils.pks @@ -381,8 +381,6 @@ create or replace package ut_utils authid definer is * Remove given ORA error from stack */ function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2; - - function create_err_cursor_msg(a_error_stack varchar2) return varchar2; - + end ut_utils; / diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index 5ac8a4546..859213722 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -595,6 +595,14 @@ create or replace package body ut_compound_data_helper is open l_diff_cursor for a_diff_cursor_text using a_self_id, a_other_id; return l_diff_cursor; end; + + function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is + begin + return 'SQL exception thrown when fetching data from cursor: '|| + ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)|| + ut_expectation_processor.who_called_expectation(a_error_stack)|| + 'Check the query and data for errors.'; + end; begin g_anytype_name_map(dbms_types.typecode_date) := 'DATE'; diff --git a/source/expectations/data_values/ut_compound_data_helper.pks b/source/expectations/data_values/ut_compound_data_helper.pks index bf3182500..62d5c8a27 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pks +++ b/source/expectations/data_values/ut_compound_data_helper.pks @@ -92,5 +92,7 @@ create or replace package ut_compound_data_helper authid definer is function get_compare_cursor(a_diff_cursor_text in clob,a_self_id raw, a_other_id raw) return sys_refcursor; + function create_err_cursor_msg(a_error_stack varchar2) return varchar2; + end; / diff --git a/source/expectations/data_values/ut_data_value_refcursor.tpb b/source/expectations/data_values/ut_data_value_refcursor.tpb index 7f157b5ad..23dca3dcf 100644 --- a/source/expectations/data_values/ut_data_value_refcursor.tpb +++ b/source/expectations/data_values/ut_data_value_refcursor.tpb @@ -100,7 +100,8 @@ create or replace type body ut_data_value_refcursor as if l_cursor%isopen then close l_cursor; end if; - raise_application_error(ut_utils.gc_failed_open_cur,ut_utils.create_err_cursor_msg(dbms_utility.format_call_stack())); + raise_application_error(ut_utils.gc_failed_open_cur, + ut_compound_data_helper.create_err_cursor_msg(dbms_utility.format_call_stack())); when others then if l_cursor%isopen then close l_cursor; diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 29d9b7819..0cf37e63a 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -972,21 +972,16 @@ Rows: [ 4 differences ] procedure reports_on_exception_in_cursor as l_actual sys_refcursor; - l_expected_message varchar2(32767); - l_actual_message varchar2(32767); begin --Act open l_actual for select 1/0 as error_column from dual connect by level < 10; ut3.ut.expect(l_actual).to_be_empty(); - --Assert - --Assert - l_expected_message := q'[%SQL exception thrown when fetching data from cursor:% -%ORA-01476: divisor is equal to zero% -%Check the query and data for errors.]'; - l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); + ut.fail('Expected exception on cursor fetch'); + exception + when others then + ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:% +%ORA-01476: divisor is equal to zero%Check the query and data for errors%'); end; procedure exception_when_closed_cursor @@ -2531,8 +2526,6 @@ Diff:% 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 @@ -2541,21 +2534,17 @@ Diff:% 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'[%ORA-20218: SQL exception thrown when fetching data from cursor: -%ORA-01722: invalid number% -at%ut.expect(v_actual).to_equal(v_expected)%]'; - l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1); - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); + ut.fail('Expected exception on cursor fetch'); + exception + when others then + ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:% +%ORA-01722: invalid number%%Check the query and data for errors%'); end; procedure xml_error_expected is v_actual sys_refcursor; v_expected sys_refcursor; - l_expected_message varchar2(32767); - l_actual_message varchar2(32767); begin open v_expected for select 1/0 as test from dual; @@ -2563,14 +2552,12 @@ at%ut.expect(v_actual).to_equal(v_expected)%]'; select 1 as test from dual; ut3.ut.expect(v_actual).to_equal(v_expected); - --Assert - l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor: -%ORA-01476: divisor is equal to zero% -%at % ut.expect(v_actual).to_equal(v_expected)%]'; - l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1); - --Assert - ut.expect(l_actual_message).to_be_like(l_expected_message); + ut.fail('Expected exception on cursor fetch'); + exception + when others then + ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:% +%ORA-01476: divisor is equal to zero%Check the query and data for errors%'); end; end; From 8c64d78153e01920942c9e565b499e85f9b46b43 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Fri, 5 Apr 2019 09:13:40 +0100 Subject: [PATCH 05/16] Applying fixes as per PR review. Removal of unused procedure from expactation_processor Switch to use constant in error message creation Update tests to match full message. --- source/core/ut_expectation_processor.pkb | 5 --- source/core/ut_expectation_processor.pks | 2 - .../data_values/ut_compound_data_helper.pkb | 2 +- .../expectations/test_expectations_cursor.pkb | 42 ++++++++++++------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/source/core/ut_expectation_processor.pkb b/source/core/ut_expectation_processor.pkb index 22dc9000f..e961ca908 100644 --- a/source/core/ut_expectation_processor.pkb +++ b/source/core/ut_expectation_processor.pkb @@ -89,11 +89,6 @@ create or replace package body ut_expectation_processor as add_expectation_result(ut_expectation_result(ut_utils.gc_failure, null, a_message)); end; - procedure report_failure_no_caller(a_message in varchar2) is - 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 diff --git a/source/core/ut_expectation_processor.pks b/source/core/ut_expectation_processor.pks index 017b6aaba..ab3b70f76 100644 --- a/source/core/ut_expectation_processor.pks +++ b/source/core/ut_expectation_processor.pks @@ -36,8 +36,6 @@ create or replace package ut_expectation_processor authid current_user as procedure report_failure(a_message in varchar2); - procedure report_failure_no_caller(a_message in varchar2); - procedure set_xml_nls_params; procedure reset_nls_params; diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index 859213722..d69cb0c3d 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -599,7 +599,7 @@ create or replace package body ut_compound_data_helper is function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is begin return 'SQL exception thrown when fetching data from cursor: '|| - ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)|| + ut_utils.remove_error_from_stack(sqlerrm,ut_utils.gc_xml_processing)||chr(10)|| ut_expectation_processor.who_called_expectation(a_error_stack)|| 'Check the query and data for errors.'; end; diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 0cf37e63a..099a694cf 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2522,42 +2522,54 @@ Diff:% end; procedure xml_error_actual is - c_price CONSTANT NUMBER(20,4):= 1357; + c_price CONSTANT NUMBER(20,4):= 1357; c_user CONSTANT varchar2(30):= 'TEST_USER'; - v_actual sys_refcursor; - v_expected sys_refcursor; + l_actual sys_refcursor; + l_expected sys_refcursor; + l_exp_message varchar2(32000); begin - open v_actual for + l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: +ORA-01722: invalid number +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_ACTUAL", line 2542 ut3.ut.expect(l_actual).to_equal(l_expected); +Check the query and data for errors.'; + + open l_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 + open l_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); + ut3.ut.expect(l_actual).to_equal(l_expected); + --Line that error relates to in expected messag ut.fail('Expected exception on cursor fetch'); exception when others then - ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:% -%ORA-01722: invalid number%%Check the query and data for errors%'); + ut.expect(sqlerrm).to_equal(l_exp_message); end; procedure xml_error_expected is - v_actual sys_refcursor; - v_expected sys_refcursor; + l_actual sys_refcursor; + l_expected sys_refcursor; + l_exp_message varchar2(32000); begin - open v_expected for + + l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: +ORA-01476: divisor is equal to zero +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_EXPECTED", line 2567 ut3.ut.expect(l_actual).to_equal(l_expected); +Check the query and data for errors.'; + + open l_expected for select 1/0 as test from dual; - open v_actual for + open l_actual for select 1 as test from dual; - ut3.ut.expect(v_actual).to_equal(v_expected); + ut3.ut.expect(l_actual).to_equal(l_expected); ut.fail('Expected exception on cursor fetch'); exception when others then - ut.expect(sqlerrm).to_be_like('%ORA-20218: SQL exception thrown when fetching data from cursor:% -%ORA-01476: divisor is equal to zero%Check the query and data for errors%'); + ut.expect(sqlerrm).to_equal(l_exp_message); end; end; From 05efc5e1e71648830791c2c3d4e5e07e256e9b38 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Fri, 5 Apr 2019 09:32:48 +0100 Subject: [PATCH 06/16] Cleanup whitespaces --- source/expectations/data_values/ut_compound_data_helper.pkb | 6 +++--- test/ut3_user/expectations/test_expectations_cursor.pkb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index d69cb0c3d..6a9489274 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -598,9 +598,9 @@ create or replace package body ut_compound_data_helper is function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is begin - return 'SQL exception thrown when fetching data from cursor: '|| - ut_utils.remove_error_from_stack(sqlerrm,ut_utils.gc_xml_processing)||chr(10)|| - ut_expectation_processor.who_called_expectation(a_error_stack)|| + return 'SQL exception thrown when fetching data from cursor:'|| + trim(ut_utils.remove_error_from_stack(sqlerrm,ut_utils.gc_xml_processing))||chr(10)|| + trim(ut_expectation_processor.who_called_expectation(a_error_stack))|| 'Check the query and data for errors.'; end; diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 099a694cf..757c3dd26 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2528,9 +2528,9 @@ Diff:% l_expected sys_refcursor; l_exp_message varchar2(32000); begin - l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: + l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01722: invalid number -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_ACTUAL", line 2542 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_ACTUAL", line 2542 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_actual for @@ -2554,7 +2554,7 @@ Check the query and data for errors.'; l_exp_message varchar2(32000); begin - l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: + l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_EXPECTED", line 2567 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; From 45d6e7a8c84be6f0fe1bab3ac86420a11cb8c6cc Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 15:19:35 +0100 Subject: [PATCH 07/16] Call stack differs based on version --- test/ut3_user/expectations/test_expectations_cursor.pkb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 757c3dd26..98e0ad5c7 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2530,7 +2530,7 @@ Diff:% begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01722: invalid number -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_ACTUAL", line 2542 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2542 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_actual for @@ -2539,7 +2539,7 @@ Check the query and data for errors.'; open l_expected for select c_price as usd_price_amt, c_user as update_id from dual; - ut3.ut.expect(l_actual).to_equal(l_expected); + ut3.ut.expect(l_actual).to_be_like(l_expected); --Line that error relates to in expected messag ut.fail('Expected exception on cursor fetch'); @@ -2556,7 +2556,7 @@ Check the query and data for errors.'; l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR.XML_ERROR_EXPECTED", line 2567 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2567 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_expected for @@ -2564,7 +2564,7 @@ Check the query and data for errors.'; open l_actual for select 1 as test from dual; - ut3.ut.expect(l_actual).to_equal(l_expected); + ut3.ut.expect(l_actual).to_be_like(l_expected); ut.fail('Expected exception on cursor fetch'); exception From 0025dd9327c060a63e733c6d719ec88f5b48f4af Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 15:31:22 +0100 Subject: [PATCH 08/16] Fix typo --- test/ut3_user/expectations/test_expectations_cursor.pkb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 901beafc6..d5bf100f5 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2561,13 +2561,13 @@ Check the query and data for errors.'; open l_expected for select c_price as usd_price_amt, c_user as update_id from dual; - ut3.ut.expect(l_actual).to_be_like(l_expected); + ut3.ut.expect(l_actual).to_equal(l_expected); --Line that error relates to in expected messag ut.fail('Expected exception on cursor fetch'); exception when others then - ut.expect(sqlerrm).to_equal(l_exp_message); + ut.expect(sqlerrm).to_be_like(l_exp_message); end; procedure xml_error_expected is @@ -2586,12 +2586,12 @@ Check the query and data for errors.'; open l_actual for select 1 as test from dual; - ut3.ut.expect(l_actual).to_be_like(l_expected); + ut3.ut.expect(l_actual).to_equal(l_expected); ut.fail('Expected exception on cursor fetch'); exception when others then - ut.expect(sqlerrm).to_equal(l_exp_message); + ut.expect(sqlerrm).to_be_like(l_exp_message); end; end; From 3428fa8b1f9c1811e8038569d103e4284cbcef6e Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 15:41:47 +0100 Subject: [PATCH 09/16] Update error lines --- test/ut3_user/expectations/test_expectations_cursor.pkb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index d5bf100f5..5d59c75d9 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2552,7 +2552,7 @@ Diff:% begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01722: invalid number -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2542 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2564 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_actual for @@ -2578,7 +2578,7 @@ Check the query and data for errors.'; l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2567 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2589 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_expected for From 80a46d0a903b453c64afae73f51de7ecc26f3a3e Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 16:01:14 +0100 Subject: [PATCH 10/16] Adding ROWID to list of types that do not provide a length. --- .../data_values/ut_compound_data_helper.pkb | 15 +++++++++++++-- .../data_values/ut_compound_data_helper.pks | 5 +++++ .../expectations/test_expectations_cursor.pkb | 12 ++++++++++++ .../expectations/test_expectations_cursor.pks | 3 +++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index f68ee2a6f..a9ded7932 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -231,8 +231,7 @@ create or replace package body ut_compound_data_helper is elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('DATE','TIMESTAMP','TIMESTAMP WITH TIME ZONE', 'TIMESTAMP WITH LOCAL TIME ZONE') then l_col_type := 'VARCHAR2(50)'; - elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('INTERVAL DAY TO SECOND', - 'INTERVAL YEAR TO MONTH', 'BINARY_FLOAT', 'BINARY_DOUBLE') then + elsif a_data_info.is_sql_diffable = 1 and type_no_length(a_data_info.column_type) then l_col_type := a_data_info.column_type; else l_col_type := a_data_info.column_type @@ -570,6 +569,8 @@ create or replace package body ut_compound_data_helper is --clob/blob/xmltype/object/nestedcursor/nestedtable if a_type_name IN (g_type_name_map(dbms_sql.blob_type), g_type_name_map(dbms_sql.clob_type), + g_type_name_map(dbms_sql.long_type), + g_type_name_map(dbms_sql.long_raw_type), g_type_name_map(dbms_sql.bfile_type), g_anytype_name_map(dbms_types.typecode_namedcollection)) then @@ -605,6 +606,16 @@ create or replace package body ut_compound_data_helper is 'Check the query and data for errors.'; end; + function type_no_length ( a_type_name varchar2) return boolean is + begin + return case + when a_type_name in ('INTERVAL DAY TO SECOND','INTERVAL YEAR TO MONTH', 'BINARY_FLOAT', 'BINARY_DOUBLE','ROWID') then + true + else + false + end; + end; + begin g_anytype_name_map(dbms_types.typecode_date) := 'DATE'; g_anytype_name_map(dbms_types.typecode_number) := 'NUMBER'; diff --git a/source/expectations/data_values/ut_compound_data_helper.pks b/source/expectations/data_values/ut_compound_data_helper.pks index 62d5c8a27..1c00d2263 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pks +++ b/source/expectations/data_values/ut_compound_data_helper.pks @@ -94,5 +94,10 @@ create or replace package ut_compound_data_helper authid definer is function create_err_cursor_msg(a_error_stack varchar2) return varchar2; + /* + * Function to return true or false if the type dont have an length + */ + function type_no_length ( a_type_name varchar2) return boolean; + end; / diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 5d59c75d9..4713d14e0 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2594,5 +2594,17 @@ Check the query and data for errors.'; ut.expect(sqlerrm).to_be_like(l_exp_message); end; + procedure rowid_refcursor is + l_actual sys_refcursor; + l_expected sys_refcursor; + begin + open l_expected for + select rowid as test from dual; + open l_actual for + select rowid as test from dual; + + ut3.ut.expect(l_actual).to_equal(l_expected); + ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0); + end; end; / diff --git a/test/ut3_user/expectations/test_expectations_cursor.pks b/test/ut3_user/expectations/test_expectations_cursor.pks index b41ff005e..a2a74aeb2 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pks +++ b/test/ut3_user/expectations/test_expectations_cursor.pks @@ -405,6 +405,9 @@ create or replace package test_expectations_cursor is --%test(Fail to process a cursor for expected) procedure xml_error_expected; + + --%test(Check that cursor correctly handles ROWID dataype) + procedure rowid_refcursor; end; / From 296102aedcdfbe05c5d31051f5dcd2d74332da65 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 16:19:49 +0100 Subject: [PATCH 11/16] cleaning up tests --- test/ut3_user/expectations/test_expectations_cursor.pkb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 4713d14e0..09ad973bd 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2544,22 +2544,19 @@ Diff:% end; procedure xml_error_actual is - c_price CONSTANT NUMBER(20,4):= 1357; - c_user CONSTANT varchar2(30):= 'TEST_USER'; l_actual sys_refcursor; l_expected sys_refcursor; l_exp_message varchar2(32000); begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01722: invalid number -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2564 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_actual for - select cast(null as number(10)) as usd_price_amt, c_user as update_id - from dual where dummy = 1; + select cast(null as number(10)) as usd_price_amt from dual where dummy = 1; open l_expected for - select c_price as usd_price_amt, c_user as update_id from dual; + select 1357 as usd_price_amt from dual; ut3.ut.expect(l_actual).to_equal(l_expected); --Line that error relates to in expected messag From b399115f248252baad62c63c47a92072c176d2fd Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 16:28:38 +0100 Subject: [PATCH 12/16] Update tests --- test/ut3_user/expectations/test_expectations_cursor.pkb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 09ad973bd..016c0c3db 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2549,14 +2549,14 @@ Diff:% l_exp_message varchar2(32000); begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: -ORA-01722: invalid number +ORA-01476: divisor is equal to zero at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_actual for - select cast(null as number(10)) as usd_price_amt from dual where dummy = 1; + select 1 as test from dual; open l_expected for - select 1357 as usd_price_amt from dual; + select 1/0 as test from dual; ut3.ut.expect(l_actual).to_equal(l_expected); --Line that error relates to in expected messag @@ -2575,7 +2575,7 @@ Check the query and data for errors.'; l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2589 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_expected for From b051324c64fb0d4944265f005ae986bca57fbd31 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Mon, 8 Apr 2019 17:34:26 +0100 Subject: [PATCH 13/16] testing wildcard, there is some unexpected white space that is not appearing on local tests or other similar for expected. --- test/ut3_user/expectations/test_expectations_cursor.pkb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 016c0c3db..21ea9a697 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2550,7 +2550,7 @@ Diff:% begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected);% Check the query and data for errors.'; open l_actual for @@ -2575,7 +2575,7 @@ Check the query and data for errors.'; l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected);% Check the query and data for errors.'; open l_expected for From 10e651f247ec4279a4c64ddb102b74e579f6a0fd Mon Sep 17 00:00:00 2001 From: lwasylow Date: Tue, 9 Apr 2019 08:57:51 +0100 Subject: [PATCH 14/16] Fix : No length datatypes mapping. This is to address issue when Oracle dont expect a length value against data type but cursor description return a max_len not being null. --- .../data_values/ut_compound_data_helper.pkb | 15 +++++++++-- .../expectations/test_expectations_cursor.pkb | 25 +++++++++++++++---- .../expectations/test_expectations_cursor.pks | 4 +-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index a9ded7932..3c1a743cb 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -18,8 +18,10 @@ create or replace package body ut_compound_data_helper is g_diff_count integer; type t_type_name_map is table of varchar2(128) index by binary_integer; + type t_types_no_length is table of varchar2(128) index by varchar2(128); g_type_name_map t_type_name_map; g_anytype_name_map t_type_name_map; + g_type_no_length_map t_types_no_length; g_compare_sql_template varchar2(4000) := q'[ @@ -609,7 +611,7 @@ create or replace package body ut_compound_data_helper is function type_no_length ( a_type_name varchar2) return boolean is begin return case - when a_type_name in ('INTERVAL DAY TO SECOND','INTERVAL YEAR TO MONTH', 'BINARY_FLOAT', 'BINARY_DOUBLE','ROWID') then + when g_type_no_length_map.exists(a_type_name) then true else false @@ -661,6 +663,15 @@ begin g_type_name_map( dbms_sql.urowid_type ) := 'UROWID'; g_type_name_map( dbms_sql.user_defined_type ) := 'USER_DEFINED_TYPE'; g_type_name_map( dbms_sql.ref_type ) := 'REF_TYPE'; - + + + /** + * List of types that have no length but can produce a max_len from desc_cursor function. + */ + g_type_no_length_map('ROWID') := 'ROWID'; + g_type_no_length_map('INTERVAL DAY TO SECOND') := 'INTERVAL DAY TO SECOND'; + g_type_no_length_map('INTERVAL YEAR TO MONTH') := 'INTERVAL YEAR TO MONTH'; + g_type_no_length_map('BINARY_DOUBLE') := 'BINARY_DOUBLE'; + g_type_no_length_map('BINARY_FLOAT') := 'BINARY_FLOAT'; end; / diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 21ea9a697..9b41a259c 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2591,17 +2591,32 @@ Check the query and data for errors.'; ut.expect(sqlerrm).to_be_like(l_exp_message); end; - procedure rowid_refcursor is + procedure no_length_datatypes is l_actual sys_refcursor; l_expected sys_refcursor; begin + ut3.ut.set_nls; open l_expected for - select rowid as test from dual; + select cast(3.14 as binary_double) as pi_double, + cast(3.14 as binary_float) as pi_float, + rowid as row_rowid, + numtodsinterval(1.12345678912, 'day') row_ds_interval, + numtoyminterval(1.1, 'year') row_ym_interval + from dual; + open l_actual for - select rowid as test from dual; - - ut3.ut.expect(l_actual).to_equal(l_expected); + select cast(3.14 as binary_double) as pi_double, + cast(3.14 as binary_float) as pi_float, + rowid as row_rowid, + numtodsinterval(1.12345678912, 'day') row_ds_interval, + numtoyminterval(1.1, 'year') row_ym_interval + from dual; + --Act + ut3.ut.expect( l_actual ).to_equal( l_expected ); + --Assert ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0); + ut3.ut.reset_nls; + end; end; / diff --git a/test/ut3_user/expectations/test_expectations_cursor.pks b/test/ut3_user/expectations/test_expectations_cursor.pks index a2a74aeb2..b662ba61b 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pks +++ b/test/ut3_user/expectations/test_expectations_cursor.pks @@ -406,8 +406,8 @@ create or replace package test_expectations_cursor is --%test(Fail to process a cursor for expected) procedure xml_error_expected; - --%test(Check that cursor correctly handles ROWID dataype) - procedure rowid_refcursor; + --%test(Check that cursor correctly handles no length dataypes) + procedure no_length_datatypes; end; / From a4a33fb0e9e22fd624747d10627ee5a8a2242505 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Wed, 10 Apr 2019 09:13:38 +0100 Subject: [PATCH 15/16] Update test --- source/expectations/data_values/ut_compound_data_helper.pkb | 4 ++-- test/ut3_user/expectations/test_expectations_cursor.pkb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index 3c1a743cb..dd55036bb 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -603,8 +603,8 @@ create or replace package body ut_compound_data_helper is function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is begin return 'SQL exception thrown when fetching data from cursor:'|| - trim(ut_utils.remove_error_from_stack(sqlerrm,ut_utils.gc_xml_processing))||chr(10)|| - trim(ut_expectation_processor.who_called_expectation(a_error_stack))|| + ut_utils.remove_error_from_stack(sqlerrm,ut_utils.gc_xml_processing)||chr(10)|| + ut_expectation_processor.who_called_expectation(a_error_stack)|| 'Check the query and data for errors.'; end; diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 9b41a259c..8e7bb24c3 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2550,7 +2550,7 @@ Diff:% begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected);% +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_actual for @@ -2575,7 +2575,7 @@ Check the query and data for errors.'; l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected);% +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected); Check the query and data for errors.'; open l_expected for From f5331aca8cacc1745a4c7b308c053bd75c373474 Mon Sep 17 00:00:00 2001 From: lwasylow Date: Fri, 12 Apr 2019 08:16:27 +0100 Subject: [PATCH 16/16] Mysterious whitespace appears from time to time. TODO --- test/ut3_user/expectations/test_expectations_cursor.pkb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ut3_user/expectations/test_expectations_cursor.pkb b/test/ut3_user/expectations/test_expectations_cursor.pkb index 8e7bb24c3..9b41a259c 100644 --- a/test/ut3_user/expectations/test_expectations_cursor.pkb +++ b/test/ut3_user/expectations/test_expectations_cursor.pkb @@ -2550,7 +2550,7 @@ Diff:% begin l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2561 ut3.ut.expect(l_actual).to_equal(l_expected);% Check the query and data for errors.'; open l_actual for @@ -2575,7 +2575,7 @@ Check the query and data for errors.'; l_exp_message :='ORA-20218: SQL exception thrown when fetching data from cursor: ORA-01476: divisor is equal to zero -at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected); +at "UT3$USER#.TEST_EXPECTATIONS_CURSOR%", line 2586 ut3.ut.expect(l_actual).to_equal(l_expected);% Check the query and data for errors.'; open l_expected for