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

Skip to content

Commit c633ff5

Browse files
committed
Update code with bug fixes
1 parent af8b49a commit c633ff5

11 files changed

Lines changed: 186 additions & 158 deletions

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 80 additions & 105 deletions
Large diffs are not rendered by default.

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ create or replace package ut_compound_data_helper authid definer is
7171

7272
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob;
7373

74+
--TODO : Can this be done better ??
7475
function get_rows_diff(
7576
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
7677
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
77-
a_join_by_xpath varchar2,a_unordered boolean
78+
a_join_by_xpath varchar2,a_refcursor boolean
7879
) return tt_row_diffs;
7980

8081
subtype t_hash is raw(128);
@@ -99,7 +100,7 @@ create or replace package ut_compound_data_helper authid definer is
99100

100101
procedure cleanup_diff;
101102

102-
function get_rows_diff return integer;
103+
function get_rows_diff_count return integer;
103104

104105
end;
105106
/

source/expectations/data_values/ut_compound_data_tmp.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ create global temporary table ut_compound_data_tmp(
1919
pk_hash raw(128),
2020
duplicate_no integer,
2121
constraint ut_cmp_data_tmp_hash_pk unique (data_id, item_no, duplicate_no)
22-
) on commit preserve rows;
22+
) on commit preserve rows xmltype column item_data store as binary xml;

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ create or replace type body ut_compound_data_value as
5353
--return first c_max_rows rows
5454
execute immediate '
5555
select xmlserialize( content ucd.item_data no indent)
56-
from '|| ut_utils.ut_owner ||'.ut_compound_data_tmp ucd
57-
where ucd.data_id = :data_id
58-
and ucd.item_no <= :max_rows'
59-
bulk collect into l_results using self.data_id, c_max_rows;
56+
from '|| ut_utils.ut_owner ||q'[.ut_compound_data_tmp tmp
57+
,xmltable ( '/ROWSET' passing tmp.item_data
58+
columns item_data xmltype PATH '*'
59+
) ucd
60+
where tmp.data_id = :data_id
61+
and rownum <= :max_rows]'
62+
bulk collect into l_results using self.data_id, ut_utils.gc_diff_max_rows;
6063

6164
ut_utils.append_to_clob(l_result,l_results);
6265

@@ -113,18 +116,15 @@ create or replace type body ut_compound_data_value as
113116

114117
dbms_lob.createtemporary(l_result,true);
115118

116-
--diff rows and row elements
117119
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id);
118-
120+
119121
-- First tell how many rows are different
120-
121-
--TODO: that is a bit mess ?? Can we use global variable for all matchers.
122-
l_diff_row_count := ut_compound_data_helper.get_rows_diff;
123-
122+
l_diff_row_count := ut_compound_data_helper.get_rows_diff_count;
123+
124124
if l_diff_row_count > 0 then
125125
l_row_diffs := ut_compound_data_helper.get_rows_diff(
126126
self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath,
127-
a_include_xpath, a_join_by_xpath, a_unordered);
127+
a_include_xpath, a_join_by_xpath, a_other is of (ut_data_value_refcursor));
128128
l_message := chr(10)
129129
||'Rows: [ ' || l_diff_row_count ||' differences'
130130
|| case when l_diff_row_count > c_max_rows and l_row_diffs.count > 0 then ', showing first '||c_max_rows end
@@ -168,7 +168,7 @@ create or replace type body ut_compound_data_value as
168168
if not a_other is of (ut_compound_data_value) then
169169
raise value_error;
170170
end if;
171-
171+
172172
l_other := treat(a_other as ut_compound_data_value);
173173

174174
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);
@@ -194,7 +194,7 @@ create or replace type body ut_compound_data_value as
194194
if sql%rowcount = 0 and self.elements_count = l_other.elements_count then
195195
l_result := 0;
196196
else
197-
ut_compound_data_helper.set_rows_diff(sql%rowcount);
197+
ut_compound_data_helper.set_rows_diff(sql%rowcount);
198198
l_result := 1;
199199
end if;
200200
return l_result;
@@ -216,10 +216,11 @@ create or replace type body ut_compound_data_value as
216216
begin
217217
--TODO : Error on xml when same column is more then once in item data xml.Do we need to cleanup ??
218218
--TODO : Bring diffs row into same place for ref data cursor especially (how we going to do that so we dont break anyval etc)
219+
--TODO : Test binary xml storage (didnt seems to make a diffrence, docker and datafiles layer ??)
219220
l_other := treat(a_other as ut_compound_data_value);
220221
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);
221222

222-
open l_loop_curs for ut_compound_data_helper.gen_compare_sql(treat(a_other as ut_data_value_refcursor).columns_info, a_exclude_xpath,
223+
open l_loop_curs for ut_compound_data_helper.gen_compare_sql(treat(a_other as ut_data_value_refcursor).col_info_desc, a_exclude_xpath,
223224
a_include_xpath, a_join_by_xpath, a_inclusion_compare, a_is_negated, a_unordered ) using self.data_id,l_other.data_id;
224225
loop
225226
fetch l_loop_curs bulk collect into l_diff_tab limit l_max_rows;
@@ -233,15 +234,14 @@ create or replace type body ut_compound_data_value as
233234
if (ut_utils.gc_diff_max_rows <= l_sql_rowcount and l_max_rows != ut_utils.gc_bc_fetch_limit ) then
234235
l_max_rows := ut_utils.gc_bc_fetch_limit;
235236
end if;
236-
end loop;
237-
237+
end loop;
238238
--result is OK only if both are same
239239
if l_sql_rowcount = 0 and ( self.elements_count = l_other.elements_count or a_inclusion_compare )then
240240
l_result := 0;
241241
else
242242
ut_compound_data_helper.set_rows_diff(l_sql_rowcount);
243243
l_result := 1;
244-
end if;
244+
end if;
245245

246246
return l_result;
247247

source/expectations/data_values/ut_curr_usr_compound_helper.pkb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ create or replace package body ut_curr_usr_compound_helper is
232232
return l_result;
233233
end;
234234

235+
function extract_min_col_info(a_full_col_info xmltype) return xmltype is
236+
l_result xmltype;
237+
begin
238+
SELECT deleteXML(a_full_col_info,'/ROW/*/@sql_diffable')
239+
into l_result
240+
from dual;
241+
return l_result ;
242+
end;
243+
235244
begin
236245
g_anytype_name_map(dbms_types.typecode_date) := 'DATE';
237246
g_anytype_name_map(dbms_types.typecode_number) := 'NUMBER';

source/expectations/data_values/ut_curr_usr_compound_helper.pks

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ create or replace package ut_curr_usr_compound_helper authid current_user is
1313

1414
function get_user_defined_type(a_owner varchar2, a_type_name varchar2) return xmltype;
1515

16+
function extract_min_col_info(a_full_col_info xmltype) return xmltype;
17+
1618
end;
1719
/

source/expectations/data_values/ut_data_value_anydata.tpb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ create or replace type body ut_data_value_anydata as
3636
else
3737
self.is_data_null := 1;
3838
end if;
39+
40+
ut_compound_data_helper.cleanup_diff;
3941
if not self.is_null() then
4042
ut_expectation_processor.set_xml_nls_params();
4143
open l_query for select a_value val from dual;

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ create or replace type body ut_data_value_refcursor as
3737
self.self_type := $$plsql_unit;
3838
self.data_id := sys_guid();
3939
self.data_type := 'refcursor';
40+
ut_compound_data_helper.cleanup_diff;
41+
4042
if l_cursor is not null then
4143
if l_cursor%isopen then
4244
--Get some more info regarding cursor, including if it containts collection columns and what is their name
4345

44-
ut_curr_usr_compound_helper.get_columns_info(l_cursor,self.columns_info,self.key_info,
46+
ut_curr_usr_compound_helper.get_columns_info(l_cursor,self.col_info_desc,self.key_info,
4547
self.contain_collection);
4648
self.elements_count := 0;
49+
self.columns_info := ut_curr_usr_compound_helper.extract_min_col_info(self.col_info_desc);
4750

4851
-- We use DBMS_XMLGEN in order to:
4952
-- 1) be able to process data in bulks (set of rows)
@@ -80,7 +83,7 @@ create or replace type body ut_data_value_refcursor as
8083
close l_cursor;
8184
end if;
8285
dbms_xmlgen.closeContext(l_ctx);
83-
86+
8487
elsif not l_cursor%isopen then
8588
raise cursor_not_open;
8689
end if;

source/expectations/data_values/ut_data_value_refcursor.tps

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ create or replace type ut_data_value_refcursor under ut_compound_data_value(
3535
*/
3636
columns_info xmltype,
3737

38+
/**
39+
* Holds information about column names and column data-types and also some supporting attributes
40+
*/
41+
col_info_desc xmltype,
3842
/**
3943
* Holds more detailed information regarding the pk joins
4044
*/

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ create or replace package body test_expectations_cursor is
6262
l_actual sys_refcursor;
6363
begin
6464
-- Arrange
65+
ut.set_nls;
6566
open l_expected for
6667
select 1 as my_num,
6768
'This is my test string' as my_string,
@@ -74,6 +75,7 @@ create or replace package body test_expectations_cursor is
7475
to_clob('This is an even longer test clob') as my_clob,
7576
to_date('1984-09-05', 'YYYY-MM-DD') as my_date
7677
from dual;
78+
ut.reset_nls;
7779
--Act
7880
ut3.ut.expect( l_actual ).to_equal( l_expected );
7981
--Assert
@@ -661,9 +663,7 @@ Diff:
661663
Columns:
662664
Column <COL_4> is misplaced. Expected position: 2, actual position: 4.
663665
Column <COL_2> is misplaced. Expected position: 3, actual position: 2.
664-
Column <COL_3> is misplaced. Expected position: 4, actual position: 3.
665-
Rows: [ 2 differences ]
666-
All rows are different as the columns are not matching.]';
666+
Column <COL_3> is misplaced. Expected position: 4, actual position: 3.]';
667667
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
668668
--Assert
669669
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -893,8 +893,8 @@ Rows: [ 4 differences ]
893893
l_expected sys_refcursor;
894894
begin
895895
--Arrange
896-
open l_actual for select object_name from all_objects where rownum <=1100;
897-
open l_expected for select object_name from all_objects where rownum <=1100;
896+
open l_actual for select object_name from all_objects where rownum <=1100 order by object_id;
897+
open l_expected for select object_name from all_objects where rownum <=1100 order by object_id;
898898
--Act
899899
ut3.ut.expect(l_actual).to_equal(l_expected);
900900

@@ -908,8 +908,8 @@ Rows: [ 4 differences ]
908908
l_expected sys_refcursor;
909909
begin
910910
--Arrange
911-
open l_actual for select object_name from all_objects where rownum <=11000;
912-
open l_expected for select object_name from all_objects where rownum <=11000;
911+
open l_actual for select object_name from all_objects where rownum <=11000 order by object_id;
912+
open l_expected for select object_name from all_objects where rownum <=11000 order by object_id;
913913
--Act
914914
ut3.ut.expect(l_actual).to_equal(l_expected);
915915

@@ -1090,8 +1090,8 @@ Rows: [ 2 differences ]%
10901090
l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]%
10911091
%Diff:%
10921092
%Rows: [ 2 differences ]%
1093-
%Extra: <ROW><USERNAME>test</USERNAME><USER_ID>-666</USER_ID></ROW>%
1094-
%Missing: <ROW><USERNAME>test</USERNAME><USER_ID>-667</USER_ID></ROW>%]';
1093+
%Extra: <USERNAME>test</USERNAME><USER_ID>-666</USER_ID>%
1094+
%Missing: <USERNAME>test</USERNAME><USER_ID>-667</USER_ID>%]';
10951095
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
10961096
--Assert
10971097
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -1289,6 +1289,32 @@ Diff:%
12891289
ut.expect(expectations.failed_expectations_data()).to_be_empty();
12901290
end;
12911291

1292+
procedure cursor_unorder_compare_1000 is
1293+
l_actual SYS_REFCURSOR;
1294+
l_expected SYS_REFCURSOR;
1295+
begin
1296+
--Arrange
1297+
open l_actual for select level object_id, level || '_TEST' object_name from dual connect by level <=1100;
1298+
open l_expected for select level object_id, level || '_TEST' object_name from dual connect by level <=1100;
1299+
--Act
1300+
ut3.ut.expect(l_actual).to_equal(l_expected).unordered;
1301+
--Assert
1302+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
1303+
end;
1304+
1305+
procedure cursor_unorder_compare_10000 is
1306+
l_actual SYS_REFCURSOR;
1307+
l_expected SYS_REFCURSOR;
1308+
begin
1309+
--Arrange
1310+
open l_actual for select level object_id, level || '_TEST' object_name from dual connect by level <=11000;
1311+
open l_expected for select level object_id, level || '_TEST' object_name from dual connect by level <=11000;
1312+
--Act
1313+
ut3.ut.expect(l_actual).to_equal(l_expected).unordered;
1314+
--Assert
1315+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
1316+
end;
1317+
12921318
procedure cursor_joinby_compare_fail is
12931319
l_actual SYS_REFCURSOR;
12941320
l_expected SYS_REFCURSOR;
@@ -1334,8 +1360,8 @@ Diff:%
13341360
l_expected_message := q'[%Actual: refcursor [ count = % ] was expected to equal: refcursor [ count = % ]
13351361
%Diff:%
13361362
%Rows: [ 2 differences ]%
1337-
%PK <USERNAME>TEST</USERNAME><USER_ID>-610</USER_ID> - Extra: <ROW><USERNAME>TEST</USERNAME><USER_ID>-610</USER_ID></ROW>%
1338-
%PK <USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID> - Missing: <ROW><USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID></ROW>%]';
1363+
%PK <USERNAME>TEST</USERNAME><USER_ID>-610</USER_ID> - Extra: <USERNAME>TEST</USERNAME><USER_ID>-610</USER_ID>%
1364+
%PK <USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID> - Missing: <USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID>%]';
13391365
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
13401366
--Assert
13411367
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -1516,12 +1542,12 @@ Diff:%
15161542
ut3.ut.expect(l_actual).to_equal(l_expected).unordered;
15171543
l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ]%
15181544
Diff:%
1519-
Rows: [ 5 differences ]
1520-
%Extra: <ROW><COLVAL><ID>2</ID><name>Something 2</name><Value>2</Value></COLVAL></ROW>%
1521-
%Extra: <ROW><COLVAL><ID>1</ID><name>Something 1</name><Value>1</Value></COLVAL></ROW>%
1522-
%Missing: <ROW><COLVAL><ID>1</ID><name>Somethings 1</name><Value>1</Value></COLVAL></ROW>%
1523-
%Missing: <ROW><COLVAL><ID>2</ID><name>Somethings 2</name><Value>2</Value></COLVAL></ROW>%
1524-
%Missing: <ROW><COLVAL><ID>3</ID><name>Somethings 3</name><Value>3</Value></COLVAL></ROW>%]';
1545+
Rows: [ 5 differences 1
1546+
%Extra: <COLVAL><ID>1</ID><name>Something 1</name><Value>1</Value></COLVAL>%
1547+
%Extra: <COLVAL><ID>2</ID><name>Something 2</name><Value>2</Value></COLVAL>%
1548+
%Missing: <COLVAL><ID>1</ID><name>Somethings 1</name><Value>1</Value></COLVAL>%
1549+
%Missing: <COLVAL><ID>2</ID><name>Somethings 2</name><Value>2</Value></COLVAL>%
1550+
%Missing: <COLVAL><ID>3</ID><name>Somethings 3</name><Value>3</Value></COLVAL>%]';
15251551
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
15261552
--Assert
15271553
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -2036,7 +2062,7 @@ Diff:%
20362062
l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ]
20372063
%Diff:
20382064
%Rows: [ 1 differences ]
2039-
%Missing: <ROW><NAME>Table</NAME></ROW>%]';
2065+
%Missing: <NAME>Table</NAME>%]';
20402066
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
20412067
--Assert
20422068
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -2077,11 +2103,11 @@ Diff:%
20772103
l_expected_message := q'[%Actual: refcursor [ count = 4 ] was expected to include: refcursor [ count = 9 ]
20782104
%Diff:
20792105
%Rows: [ 5 differences ]
2080-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2081-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2082-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2083-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2084-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>%]';
2106+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2107+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2108+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2109+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2110+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%]';
20852111
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
20862112
--Assert
20872113
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -2121,11 +2147,11 @@ Diff:%
21212147
l_expected_message := q'[%Actual: refcursor [ count = 4 ] was expected to include: refcursor [ count = 9 ]
21222148
%Diff:
21232149
%Rows: [ 5 differences ]
2124-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2125-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2126-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2127-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2128-
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>%]';
2150+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2151+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2152+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2153+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%
2154+
%Missing: <OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE>%]';
21292155
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
21302156
--Assert
21312157
ut.expect(l_actual_message).to_be_like(l_expected_message);
@@ -2478,9 +2504,9 @@ Diff:%
24782504
l_expected_message := q'[%Actual: refcursor [ count = 9 ] was expected to include: refcursor [ count = 6 ]
24792505
%Diff:
24802506
%Rows: [ 3 differences ]
2481-
%Missing: <ROW><RN>%</RN></ROW>
2482-
%Missing: <ROW><RN>%</RN></ROW>
2483-
%Missing: <ROW><RN>%</RN></ROW>]';
2507+
%Missing: <RN>%</RN>
2508+
%Missing: <RN>%</RN>
2509+
%Missing: <RN>%</RN>]';
24842510
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
24852511
--Assert
24862512
ut.expect(l_actual_message).to_be_like(l_expected_message);

0 commit comments

Comments
 (0)