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

Skip to content

Commit a0ee195

Browse files
committed
Added tests for include
1 parent 440670b commit a0ee195

4 files changed

Lines changed: 172 additions & 7 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ create or replace package body ut_compound_data_helper is
176176
l_results tt_row_diffs;
177177
begin
178178
l_column_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath);
179-
180179
/**
181180
* Since its unordered search we cannot select max rows from diffs as we miss some comparision records
182181
* We will restrict output on higher level of select
@@ -600,7 +599,8 @@ create or replace package body ut_compound_data_helper is
600599
source_data s
601600
where t.data_id = :other_guid
602601
and s.data_id = :self_guid
603-
and t.pk_hash = s.pk_hash
602+
and t.pk_hash = s.pk_hash
603+
and t.item_hash != s.item_hash
604604
)
605605
)
606606
tmp';

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,13 @@ create or replace type body ut_compound_data_value as
107107
l_actual := treat(a_other as ut_compound_data_value);
108108

109109
dbms_lob.createtemporary(l_result,true);
110-
111110
--diff rows and row elements
112111
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id);
113112

114113
-- First tell how many rows are different
115114
execute immediate 'select count('||case when a_join_by_xpath is not null then 'distinct pk_hash' else '*' end||') from '
116115
|| l_ut_owner || '.ut_compound_data_diff_tmp
117116
where diff_id = :diff_id' into l_diff_row_count using l_diff_id;
118-
119117
if l_diff_row_count > 0 then
120118
l_compare_type := ut_compound_data_helper.compare_type(a_join_by_xpath,a_unordered);
121119
l_row_diffs := ut_compound_data_helper.get_rows_diff(
@@ -224,7 +222,7 @@ create or replace type body ut_compound_data_value as
224222
if not a_other is of (ut_compound_data_value) then
225223
raise value_error;
226224
end if;
227-
225+
228226
l_other := treat(a_other as ut_compound_data_value);
229227

230228
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);
@@ -264,11 +262,11 @@ create or replace type body ut_compound_data_value as
264262
l_diff_id,
265263
self.data_id, l_other.data_id,
266264
l_other.data_id,self.data_id;
267-
265+
268266
/*!*
269267
* Result OK when is not inclusion matcher and both are the same
270268
* Resullt OK when is inclusion matcher and left contains right set
271-
*/
269+
*/
272270
if sql%rowcount = 0 and self.elements_count = l_other.elements_count and not(a_inclusion_compare ) then
273271
l_result := 0;
274272
elsif sql%rowcount = 0 and a_inclusion_compare then

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,149 @@ Diff:%
19861986
ut.expect(l_actual_message).to_be_like(l_expected_message);
19871987

19881988
end;
1989+
1990+
procedure cursor_contain is
1991+
l_actual SYS_REFCURSOR;
1992+
l_expected SYS_REFCURSOR;
1993+
begin
1994+
--Arrange
1995+
open l_actual for select owner, object_name,object_type from all_objects where owner = user
1996+
order by 1,2,3 asc;
1997+
open l_expected for select owner, object_name,object_type from all_objects where owner = user
1998+
and rownum < 20;
1999+
2000+
--Act
2001+
ut3.ut.expect(l_actual).to_include(l_expected);
2002+
--Assert
2003+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
2004+
end;
2005+
2006+
procedure cursor_contain_fail is
2007+
l_actual SYS_REFCURSOR;
2008+
l_expected SYS_REFCURSOR;
2009+
l_expected_message varchar2(32767);
2010+
l_actual_message varchar2(32767);
2011+
begin
2012+
--Arrange
2013+
open l_actual for select owner, object_name,object_type from all_objects where owner = user
2014+
and rownum < 5;
2015+
open l_expected for select owner, object_name,object_type from all_objects where owner = user
2016+
and rownum < 10;
2017+
2018+
--Act
2019+
ut3.ut.expect(l_actual).to_include(l_expected);
2020+
--Assert
2021+
l_expected_message := q'[%Actual: refcursor [ count = 4 ] was expected to include: refcursor [ count = 9 ]
2022+
%Diff:
2023+
%Rows: [ 5 differences ]
2024+
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2025+
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2026+
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2027+
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>
2028+
%Missing: <ROW><OWNER>%</OWNER><OBJECT_NAME>%</OBJECT_NAME><OBJECT_TYPE>%</OBJECT_TYPE></ROW>%]';
2029+
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
2030+
--Assert
2031+
ut.expect(l_actual_message).to_be_like(l_expected_message);
2032+
end;
2033+
2034+
procedure cursor_contain_joinby is
2035+
l_actual SYS_REFCURSOR;
2036+
l_expected SYS_REFCURSOR;
2037+
begin
2038+
--Arrange
2039+
open l_actual for select username,user_id from all_users;
2040+
open l_expected for select username ,user_id from all_users where rownum < 5;
2041+
2042+
--Act
2043+
ut3.ut.expect(l_actual).to_include(l_expected).join_by('USERNAME');
2044+
--Assert
2045+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
2046+
end;
19892047

2048+
procedure cursor_contain_joinby_fail is
2049+
l_actual SYS_REFCURSOR;
2050+
l_expected SYS_REFCURSOR;
2051+
l_expected_message varchar2(32767);
2052+
l_actual_message varchar2(32767);
2053+
begin
2054+
--Arrange
2055+
open l_actual for select username, user_id from all_users
2056+
union all
2057+
select 'TEST' username, -600 user_id from dual
2058+
order by 1 desc;
2059+
open l_expected for select username, user_id from all_users
2060+
union all
2061+
select 'TEST' username, -601 user_id from dual
2062+
order by 1 asc;
2063+
2064+
--Act
2065+
ut3.ut.expect(l_actual).to_include(l_expected).join_by('USERNAME');
2066+
--Assert
2067+
l_expected_message := q'[%Actual: refcursor [ count = % ] was expected to include: refcursor [ count = % ]
2068+
%Diff:
2069+
%Rows: [ 1 differences ]
2070+
%PK <USERNAME>TEST</USERNAME> - Actual: <USER_ID>-600</USER_ID>
2071+
%PK <USERNAME>TEST</USERNAME> - Expected: <USER_ID>-601</USER_ID>%]';
2072+
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
2073+
--Assert
2074+
ut.expect(l_actual_message).to_be_like(l_expected_message);
2075+
2076+
end;
2077+
2078+
procedure contain_incl_cols_as_list
2079+
as
2080+
l_actual sys_refcursor;
2081+
l_expected sys_refcursor;
2082+
begin
2083+
--Arrange
2084+
open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 6;
2085+
open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4;
2086+
--Act
2087+
ut3.ut.expect(l_actual).to_include(l_expected).include(ut3.ut_varchar2_list('RN','//A_Column','SOME_COL'));
2088+
--Assert
2089+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
2090+
end;
2091+
2092+
procedure contain_join_incl_cols_as_lst
2093+
as
2094+
l_actual sys_refcursor;
2095+
l_expected sys_refcursor;
2096+
begin
2097+
--Arrange
2098+
open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 10;
2099+
open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4;
2100+
--Act
2101+
ut3.ut.expect(l_actual).to_include(l_expected).include(ut3.ut_varchar2_list('RN','//A_Column','SOME_COL')).join_by('RN');
2102+
--Assert
2103+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
2104+
end;
2105+
2106+
procedure contain_join_excl_cols_as_lst
2107+
as
2108+
l_actual sys_refcursor;
2109+
l_expected sys_refcursor;
2110+
begin
2111+
--Arrange
2112+
open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 10;
2113+
open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4;
2114+
--Act
2115+
ut3.ut.expect(l_actual).to_include(l_expected).exclude(ut3.ut_varchar2_list('//Some_Col','A_COLUMN')).join_by('RN');
2116+
--Assert
2117+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
2118+
end;
2119+
2120+
procedure contain_excl_cols_as_list
2121+
as
2122+
l_actual sys_refcursor;
2123+
l_expected sys_refcursor;
2124+
begin
2125+
--Arrange
2126+
open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 10;
2127+
open l_expected for select rownum as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4;
2128+
--Act
2129+
ut3.ut.expect(l_actual).to_include(l_expected).exclude(ut3.ut_varchar2_list('A_COLUMN|//Some_Col'));
2130+
--Assert
2131+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
2132+
end;
19902133
end;
19912134
/

test/core/expectations/test_expectations_cursor.pks

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,29 @@ create or replace package test_expectations_cursor is
316316
--%test(Trying to join on collection element inside record )
317317
procedure compare_rec_coll_as_join;
318318

319+
--%test( Cursor contains data from another cursor)
320+
procedure cursor_contain;
321+
322+
--%test( Fail cursor contains data from another cursor )
323+
procedure cursor_contain_fail;
324+
325+
--%test( Cursor contains data from another cursor with joinby)
326+
procedure cursor_contain_joinby;
327+
328+
--%test( Fail cursor contains data from another cursor with joinby)
329+
procedure cursor_contain_joinby_fail;
330+
331+
--%test(Cursor contains data with of columns to include)
332+
procedure contain_incl_cols_as_list;
333+
334+
--%test(Cursor contains data with of columns to include and join by value)
335+
procedure contain_join_incl_cols_as_lst;
336+
337+
--%test(Cursor contains data with of columns to exclude and join by value)
338+
procedure contain_join_excl_cols_as_lst;
339+
340+
--%test(Cursor contains data with of columns to exclude)
341+
procedure contain_excl_cols_as_list;
342+
319343
end;
320344
/

0 commit comments

Comments
 (0)