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

Skip to content

Commit f798e39

Browse files
committed
Added tests and negated code
1 parent 6193ff3 commit f798e39

12 files changed

Lines changed: 213 additions & 38 deletions

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,42 @@ create or replace package body ut_compound_data_helper is
607607
return l_sql;
608608
end;
609609

610+
function get_not_inclusion_matcher_sql(a_owner in varchar2) return varchar2 is
611+
l_sql varchar2(32767);
612+
begin
613+
/* Self set does not contain any values from other set */
614+
l_sql := 'with source_data as
615+
( select t.data_id,t.item_hash,row_number() over (partition by t.pk_hash,t.item_hash,t.data_id order by 1,2) duplicate_no,
616+
pk_hash
617+
from ' || a_owner || '.ut_compound_data_tmp t
618+
where data_id = :self_guid or data_id = :other_guid
619+
)
620+
select distinct :diff_id,tmp.item_hash,tmp.pk_hash,tmp.duplicate_no
621+
from
622+
(
623+
select act.item_hash,act. duplicate_no,act.pk_hash
624+
from source_data act where act.data_id = :self_guid
625+
and exists ( select 1
626+
from source_data exp
627+
where exp.data_id = :other_guid
628+
and exp.item_hash = act.item_hash
629+
)
630+
union all
631+
select null,null,null
632+
from dual where :other_guid = :self_guid
633+
)
634+
tmp';
635+
return l_sql;
636+
end;
637+
610638
function get_refcursor_matcher_sql(a_owner in varchar2,a_inclusion_matcher boolean := false, a_negated_match boolean := false) return varchar2 is
611639
l_sql varchar2(32767);
612640
begin
613641
l_sql := 'insert into ' || a_owner || '.ut_compound_data_diff_tmp ( diff_id,item_hash,pk_hash,duplicate_no)'||chr(10);
614642
if a_inclusion_matcher and not(a_negated_match) then
615643
l_sql := l_sql || get_inclusion_matcher_sql(a_owner);
616644
elsif a_inclusion_matcher and a_negated_match then
617-
null;
645+
l_sql := l_sql || get_not_inclusion_matcher_sql(a_owner);
618646
elsif not(a_inclusion_matcher) then
619647
l_sql := l_sql || get_unordered(a_owner);
620648
end if;

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ create or replace type body ut_compound_data_value as
193193
end;
194194

195195
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2,
196-
a_unordered boolean , a_inclusion_compare boolean := false ) return integer is
196+
a_unordered boolean , a_inclusion_compare boolean := false, a_is_negated boolean := false ) return integer is
197197
l_other ut_compound_data_value;
198198
l_ut_owner varchar2(250) := ut_utils.ut_owner;
199199
l_column_filter varchar2(32767);
@@ -255,14 +255,14 @@ create or replace type body ut_compound_data_value as
255255
* SELF is expected.
256256
* Due to growing complexity I have moved a dynamic SQL into helper package.
257257
*/
258-
l_sql := ut_compound_data_helper.get_refcursor_matcher_sql(l_ut_owner,a_inclusion_compare);
259-
258+
l_sql := ut_compound_data_helper.get_refcursor_matcher_sql(l_ut_owner,a_inclusion_compare,a_is_negated);
259+
260260
execute immediate l_sql
261261
using self.data_id, l_other.data_id,
262262
l_diff_id,
263263
self.data_id, l_other.data_id,
264264
l_other.data_id,self.data_id;
265-
265+
266266
/*!*
267267
* Result OK when is not inclusion matcher and both are the same
268268
* Resullt OK when is inclusion matcher and left contains right set

source/expectations/data_values/ut_compound_data_value.tps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ create or replace type ut_compound_data_value force under ut_data_value(
4545
member function get_data_diff(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return clob,
4646
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer,
4747
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2,
48-
a_unordered boolean , a_inclusion_compare boolean := false) return integer
48+
a_unordered boolean , a_inclusion_compare boolean := false, a_is_negated boolean := false) return integer
4949
) not final not instantiable
5050
/

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ create or replace type body ut_data_value_refcursor as
221221
end;
222222

223223
overriding member function compare_implementation (a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2,
224-
a_unordered boolean, a_inclusion_compare boolean := false) return integer is
224+
a_unordered boolean, a_inclusion_compare boolean := false, a_is_negated boolean := false) return integer is
225225
l_result integer := 0;
226226
l_other ut_data_value_refcursor;
227227
function is_pk_missing (a_pk_missing_tab ut_compound_data_helper.tt_missing_pk) return integer is
@@ -251,7 +251,7 @@ create or replace type body ut_data_value_refcursor as
251251

252252
if a_unordered then
253253
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath,
254-
a_join_by_xpath, a_unordered, a_inclusion_compare);
254+
a_join_by_xpath, a_unordered, a_inclusion_compare, a_is_negated);
255255
else
256256
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath);
257257
end if;
@@ -265,6 +265,5 @@ create or replace type body ut_data_value_refcursor as
265265
return self.elements_count = 0;
266266
end;
267267

268-
269268
end;
270269
/

source/expectations/data_values/ut_data_value_refcursor.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ create or replace type ut_data_value_refcursor under ut_compound_data_value(
4545
overriding member function to_string return varchar2,
4646
overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2,
4747
overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2,
48-
a_unordered boolean, a_inclusion_compare boolean := false) return integer,
48+
a_unordered boolean, a_inclusion_compare boolean := false, a_is_negated boolean := false) return integer,
4949
overriding member function is_empty return boolean
50-
5150
)
5251
/

source/expectations/matchers/ut_include.tpb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ create or replace type body ut_include as
4343
return l_result;
4444
end;
4545

46+
member function get_negated return boolean is
47+
begin
48+
return ut_utils.int_to_boolean(nvl(is_negated,0));
49+
end;
50+
4651
overriding member function run_matcher(self in out nocopy ut_include, a_actual ut_data_value) return boolean is
4752
l_result boolean;
4853
begin
4954
if self.expected.data_type = a_actual.data_type then
50-
if nvl(self.is_negated,0) = 0 then
51-
l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, self.get_exclude_xpath(), self.get_include_xpath(), self.get_join_by_xpath(),
52-
true,get_inclusion_compare());
53-
else
5455
l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, self.get_exclude_xpath(), self.get_include_xpath(), self.get_join_by_xpath(),
55-
true,get_inclusion_compare());
56-
end if;
56+
true,self.get_inclusion_compare(), self.get_negated());
5757
else
5858
l_result := (self as ut_matcher).run_matcher(a_actual);
5959
end if;
@@ -73,5 +73,11 @@ create or replace type body ut_include as
7373
return l_result;
7474
end;
7575

76+
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2 is
77+
l_result varchar2(32767);
78+
begin
79+
return (self as ut_matcher).failure_message_when_negated(a_actual) || ':'|| expected.to_string_report();
80+
end;
81+
7682
end;
7783
/

source/expectations/matchers/ut_include.tps

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ create or replace type ut_include under ut_equal(
2828
constructor function ut_include(self in out nocopy ut_include, a_expected sys_refcursor) return self as result,
2929
member function get_inclusion_compare return boolean,
3030
member function negated return ut_include,
31+
member function get_negated return boolean,
3132
overriding member function run_matcher(self in out nocopy ut_include, a_actual ut_data_value) return boolean,
32-
overriding member function failure_message(a_actual ut_data_value) return varchar2
33+
overriding member function failure_message(a_actual ut_data_value) return varchar2,
34+
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2
3335
)
3436
/

source/expectations/ut_expectation.tpb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ create or replace type body ut_expectation as
3838
ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) );
3939
end;
4040

41+
member procedure not_include(self in ut_expectation, a_matcher ut_matcher) is
42+
l_expectation_result boolean;
43+
l_matcher ut_matcher := a_matcher;
44+
l_message varchar2(32767);
45+
begin
46+
l_expectation_result := l_matcher.run_matcher( self.actual_data );
47+
l_expectation_result := coalesce(l_expectation_result,false);
48+
l_message := coalesce( l_matcher.error_message( self.actual_data ), l_matcher.failure_message_when_negated( self.actual_data ) );
49+
ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) );
50+
end;
51+
4152
member procedure to_be_null(self in ut_expectation) is
4253
begin
4354
self.to_( ut_be_null() );
@@ -690,12 +701,12 @@ create or replace type body ut_expectation as
690701

691702
member procedure not_to_include(self in ut_expectation, a_expected sys_refcursor) is
692703
begin
693-
self.not_to( ut_include(a_expected).negated );
704+
self.not_include( ut_include(a_expected).negated );
694705
end;
695706

696707
member procedure not_to_contain(self in ut_expectation, a_expected sys_refcursor) is
697708
begin
698-
self.not_to( ut_include(a_expected).negated );
709+
self.not_include( ut_include(a_expected).negated );
699710
end;
700711

701712
end;

source/expectations/ut_expectation.tps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ create or replace type ut_expectation authid current_user as object(
2121
--base matcher executors
2222
member procedure to_(self in ut_expectation, a_matcher ut_matcher),
2323
member procedure not_to(self in ut_expectation, a_matcher ut_matcher),
24+
member procedure not_include(self in ut_expectation, a_matcher ut_matcher),
2425

2526
--shortcuts
2627
member procedure to_be_null(self in ut_expectation),

source/expectations/ut_expectation_compound.tpb

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,30 @@ create or replace type body ut_expectation_compound as
123123

124124
member procedure include(self in ut_expectation_compound, a_items varchar2) is
125125
begin
126-
if ut_utils.int_to_boolean(negated) then
127-
self.not_to( treat(matcher as ut_equal).include(a_items) );
128-
else
129-
self.to_( treat(matcher as ut_equal).include(a_items) );
130-
end if;
131-
end;
126+
if ut_utils.int_to_boolean(negated) then
127+
if (matcher is of (ut_include)) then
128+
self.not_include( treat(matcher as ut_equal).include(a_items) );
129+
else
130+
self.not_to( treat(matcher as ut_equal).include(a_items) );
131+
end if;
132+
else
133+
self.to_( treat(matcher as ut_equal).include(a_items) );
134+
end if;
135+
end;
132136

133137
member procedure include(self in ut_expectation_compound, a_items ut_varchar2_list) is
134138
begin
139+
if ut_utils.int_to_boolean(negated) then
140+
if (matcher is of (ut_include)) then
141+
self.not_include( treat(matcher as ut_equal).include(a_items) );
142+
else
143+
self.not_to( treat(matcher as ut_equal).include(a_items) );
144+
end if;
145+
else
146+
self.to_( treat(matcher as ut_equal).include(a_items) );
147+
end if;
148+
end;
135149

136-
if ut_utils.int_to_boolean(negated) then
137-
self.not_to( treat(matcher as ut_equal).include(a_items) );
138-
else
139-
self.to_( treat(matcher as ut_equal).include(a_items) );
140-
end if;
141-
end;
142150

143151

144152
member function exclude(a_items varchar2) return ut_expectation_compound is
@@ -160,17 +168,24 @@ create or replace type body ut_expectation_compound as
160168
member procedure exclude(self in ut_expectation_compound, a_items varchar2) is
161169
begin
162170
if ut_utils.int_to_boolean(negated) then
163-
self.not_to( treat(matcher as ut_equal).exclude(a_items) );
171+
if (matcher is of (ut_include)) then
172+
self.not_include( treat(matcher as ut_equal).exclude(a_items) );
173+
else
174+
self.not_to( treat(matcher as ut_equal).exclude(a_items) );
175+
end if;
164176
else
165177
self.to_( treat(matcher as ut_equal).exclude(a_items) );
166178
end if;
167179
end;
168180

169181
member procedure exclude(self in ut_expectation_compound, a_items ut_varchar2_list) is
170182
begin
171-
172183
if ut_utils.int_to_boolean(negated) then
173-
self.not_to( treat(matcher as ut_equal).exclude(a_items) );
184+
if (matcher is of (ut_include)) then
185+
self.not_include( treat(matcher as ut_equal).exclude(a_items) );
186+
else
187+
self.not_to( treat(matcher as ut_equal).exclude(a_items) );
188+
end if;
174189
else
175190
self.to_( treat(matcher as ut_equal).exclude(a_items) );
176191
end if;
@@ -213,17 +228,24 @@ create or replace type body ut_expectation_compound as
213228
member procedure join_by(self in ut_expectation_compound, a_columns varchar2) is
214229
begin
215230
if ut_utils.int_to_boolean(negated) then
216-
self.not_to( treat(matcher as ut_equal).join_by(a_columns) );
231+
if (matcher is of (ut_include)) then
232+
self.not_include( treat(matcher as ut_equal).join_by(a_columns) );
233+
else
234+
self.not_to( treat(matcher as ut_equal).join_by(a_columns) );
235+
end if;
217236
else
218237
self.to_( treat(matcher as ut_equal).join_by(a_columns) );
219238
end if;
220239
end;
221240

222241
member procedure join_by(self in ut_expectation_compound, a_columns ut_varchar2_list) is
223242
begin
224-
225243
if ut_utils.int_to_boolean(negated) then
226-
self.not_to( treat(matcher as ut_equal).join_by(a_columns) );
244+
if (matcher is of (ut_include)) then
245+
self.not_include( treat(matcher as ut_equal).join_by(a_columns) );
246+
else
247+
self.not_to( treat(matcher as ut_equal).join_by(a_columns) );
248+
end if;
227249
else
228250
self.to_( treat(matcher as ut_equal).join_by(a_columns) );
229251
end if;

0 commit comments

Comments
 (0)