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

Skip to content

Commit 3dea567

Browse files
committed
Fixed an issue with CAHR/VARCHAR2 data-type comparison on cursors.
1 parent a3a36e1 commit 3dea567

2 files changed

Lines changed: 59 additions & 41 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,26 @@ create or replace package body ut_compound_data_helper is
9595
expected_cols as ( select :a_expected as item_data from dual ),
9696
actual_cols as ( select :a_actual as item_data from dual ),
9797
expected_cols_info as (
98-
select rownum expected_pos,
99-
r.column_value.getrootelement() expected_name,
100-
extractvalue(r.column_value,'/*') expected_type
101-
from ( select ]'||l_column_filter||q'[ from expected_cols ucd ) s,
102-
table( xmlsequence(extract(s.item_data,'/*/*')) ) r
98+
select e.*,
99+
replace(expected_type,'VARCHAR2','CHAR') expected_type_compare
100+
from (
101+
select rownum expected_pos,
102+
r.column_value.getrootelement() expected_name,
103+
extractvalue(r.column_value,'/*') expected_type
104+
from ( select ]'||l_column_filter||q'[ from expected_cols ucd ) s,
105+
table( xmlsequence(extract(s.item_data,'/*/*')) ) r
106+
) e
103107
),
104108
actual_cols_info as (
105-
select rownum actual_pos,
106-
r.column_value.getrootelement() actual_name,
107-
extractvalue(r.column_value,'/*') actual_type
108-
from ( select ]'||l_column_filter||q'[ from actual_cols ucd ) s,
109-
table( xmlsequence(extract(s.item_data,'/*/*')) ) r
109+
select a.*,
110+
replace(actual_type,'VARCHAR2','CHAR') actual_type_compare
111+
from (
112+
select rownum actual_pos,
113+
r.column_value.getrootelement() actual_name,
114+
extractvalue(r.column_value,'/*') actual_type
115+
from ( select ]'||l_column_filter||q'[ from actual_cols ucd ) s,
116+
table( xmlsequence(extract(s.item_data,'/*/*')) ) r
117+
) a
110118
),
111119
joined_cols as (
112120
select e.*, a.*,
@@ -118,13 +126,18 @@ create or replace package body ut_compound_data_helper is
118126
select case
119127
when expected_pos is null and actual_pos is not null then '+'
120128
when expected_pos is not null and actual_pos is null then '-'
121-
when actual_type != expected_type then 't'
129+
when expected_type_compare != actual_type_compare then 't'
122130
else 'p'
123131
end as diff_type,
124132
expected_name, expected_type, expected_pos,
125133
actual_name, actual_type, actual_pos
126134
from joined_cols
127-
where actual_pos is null or expected_pos is null or actual_type != expected_type or a_pos_nn != e_pos_nn
135+
--column is unexpected (extra) or missing
136+
where actual_pos is null or expected_pos is null
137+
--column type is not matching (except CHAR/VARCHAR2)
138+
or actual_type_compare != expected_type_compare
139+
--column position is not matching (both when excluded extra/missing columns as well as when they are included)
140+
or (a_pos_nn != e_pos_nn and expected_pos != actual_pos)
128141
order by expected_pos, actual_pos]';
129142
execute immediate l_sql
130143
bulk collect into l_results

test/core/expectations/compound_data/test_expectations_cursor.pkb

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,25 @@ Rows: [ 2 differences ]
579579
end;
580580

581581
procedure char_and_varchar2_col_is_equal is
582-
l_expected sys_refcursor;
583-
l_actual sys_refcursor;
582+
l_expected sys_refcursor;
583+
l_actual sys_refcursor;
584+
l_actual_message varchar2(32767);
585+
l_expected_message varchar2(32767);
584586
begin
585587
--Arrange
586-
open l_actual for select cast('a' as char(1)) a_column from dual;
587-
open l_expected for select cast('a' as varchar2(10)) a_column from dual;
588+
open l_actual for select cast('a' as char(1)) a_column, 1 as id from dual;
589+
open l_expected for select cast('a' as varchar2(10)) a_column from dual;
588590
--Act
589591
ut3.ut.expect(l_actual).to_equal(l_expected);
592+
l_expected_message := q'[Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ]
593+
Diff:
594+
Columns:
595+
Column <ID> [position: 2, data-type: NUMBER] is not expected in results.
596+
Rows: [ 1 differences ]
597+
All rows are different as the columns are not matching.]';
598+
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
590599
--Assert
591-
ut.expect(expectations.failed_expectations_data()).to_be_empty();
600+
ut.expect(l_actual_message).to_be_like(l_expected_message);
592601
end;
593602

594603
procedure column_diff_on_data_type_diff is
@@ -730,35 +739,31 @@ Rows: [ 60 differences, showing first 20 ]
730739
l_expected_message varchar2(32767);
731740
begin
732741
--Arrange
733-
ut3.ut.set_nls();
734-
open l_actual for
735-
select 10 id, 'Norris' last_name, 'Chuck' first_name, systimestamp as create_tmstmp, user as created_by from dual union all
736-
select 20 id, 'Skywalker' last_name, 'Luke' first_name, systimestamp as create_tmstmp, user as created_by from dual union all
737-
select 30 id, 'Bear' last_name, 'Teddy' first_name, systimestamp as create_tmstmp, user as created_by from dual union all
738-
select 40 id, 'Lee' last_name, 'Bruce' first_name, systimestamp as create_tmstmp, user as created_by from dual;
739742
open l_expected for
740-
select 10 id, 'Chuck' first_name, 'Norris' last_name, sysdate as birth_date from dual union all
741-
select 20 id, 'Luke' first_name, 'Skywalker' last_name, sysdate as birth_date from dual union all
742-
select 31 id, 'Teddy' first_name, 'Bear' last_name, sysdate as birth_date from dual union all
743-
select 40 id, 'Brandon' first_name, 'Lee' last_name, sysdate as birth_date from dual union all
744-
select 50 id, 'Mona' first_name, 'Lisa' last_name, date '1550-01-01' as birth_date from dual;
745-
ut3.ut.reset_nls();
743+
select 1 as ID, 'JACK' as FIRST_NAME, 'SPARROW' AS LAST_NAME, 10000 AS SALARY from dual union all
744+
select 2 as ID, 'LUKE' as FIRST_NAME, 'SKYWALKER' AS LAST_NAME, 1000 AS SALARY from dual union all
745+
select 3 as ID, 'TONY' as FIRST_NAME, 'STARK' AS LAST_NAME, 100000 AS SALARY from dual;
746+
open l_actual for
747+
select 'M' AS GENDER, 'JACK' as FIRST_NAME, 'SPARROW' AS LAST_NAME, 1 as ID, '25000' AS SALARY from dual union all
748+
select 'M' AS GENDER, 'TONY' as FIRST_NAME, 'STARK' AS LAST_NAME, 3 as ID, '100000' AS SALARY from dual union all
749+
select 'F' AS GENDER, 'JESSICA' as FIRST_NAME, 'JONES' AS LAST_NAME, 4 as ID, '2345' AS SALARY from dual union all
750+
select 'M' AS GENDER, 'LUKE' as FIRST_NAME, 'SKYWALKER' AS LAST_NAME, 2 as ID, '1000' AS SALARY from dual;
746751
--Act
747752
ut3.ut.expect(l_actual).to_equal(l_expected);
748-
l_expected_message := q'[%Actual: refcursor [ count = 4 ] was expected to equal: refcursor [ count = 5 ]
753+
l_expected_message := q'[Actual: refcursor [ count = 4 ] was expected to equal: refcursor [ count = 3 ]
749754
Diff:
750755
Columns:
751-
Column <FIRST_NAME> is misplaced. Expected position: 2, actual position: 3.
752-
Column <LAST_NAME> is misplaced. Expected position: 3, actual position: 2.
753-
Column <BIRTH_DATE> [data-type: DATE] is missing. Expected column position: 4.
754-
Column <CREATE_TMSTMP> [position: 4, data-type: TIMESTAMP WITH TIME ZONE] is not expected in results.
755-
Column <CREATED_BY> [position: 5, data-type: VARCHAR2] is not expected in results.
756-
Rows: [ 5 differences ]
757-
Row No. 3 - Actual: <ID>30</ID>
758-
Row No. 3 - Expected: <ID>31</ID>
759-
Row No. 4 - Actual: <FIRST_NAME>Bruce</FIRST_NAME>
760-
Row No. 4 - Expected: <FIRST_NAME>Brandon</FIRST_NAME>
761-
Row No. 5 - Missing: <ID>50</ID><FIRST_NAME>Mona</FIRST_NAME><LAST_NAME>Lisa</LAST_NAME><BIRTH_DATE>1550-01-01%</BIRTH_DATE>]';
756+
Column <ID> is misplaced. Expected position: 1, actual position: 4.
757+
Column <SALARY> data-type is invalid. Expected: NUMBER, actual: VARCHAR2.
758+
Column <GENDER> [position: 1, data-type: CHAR] is not expected in results.
759+
Rows: [ 4 differences ]
760+
Row No. 1 - Actual: <SALARY>25000</SALARY>
761+
Row No. 1 - Expected: <SALARY>10000</SALARY>
762+
Row No. 2 - Actual: <FIRST_NAME>TONY</FIRST_NAME><LAST_NAME>STARK</LAST_NAME><ID>3</ID><SALARY>100000</SALARY>
763+
Row No. 2 - Expected: <ID>2</ID><FIRST_NAME>LUKE</FIRST_NAME><LAST_NAME>SKYWALKER</LAST_NAME><SALARY>1000</SALARY>
764+
Row No. 3 - Actual: <FIRST_NAME>JESSICA</FIRST_NAME><LAST_NAME>JONES</LAST_NAME><ID>4</ID><SALARY>2345</SALARY>
765+
Row No. 3 - Expected: <ID>3</ID><FIRST_NAME>TONY</FIRST_NAME><LAST_NAME>STARK</LAST_NAME><SALARY>100000</SALARY>
766+
Row No. 4 - Extra: <GENDER>M</GENDER><FIRST_NAME>LUKE</FIRST_NAME><LAST_NAME>SKYWALKER</LAST_NAME><ID>2</ID><SALARY>1000</SALARY>]';
762767
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
763768
--Assert
764769
ut.expect(l_actual_message).to_be_like(l_expected_message);

0 commit comments

Comments
 (0)