Skip to content

Commit 528808b

Browse files
committed
Refactored responsibilities.
Added `.include(...)` and `.exclude(...)` as builder patterns for collections and cursors
1 parent 6547eba commit 528808b

23 files changed

+470
-299
lines changed

source/api/ut.pkb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ create or replace package body ut is
2424
return ut_runner.version();
2525
end;
2626

27-
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation is
27+
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_compound is
2828
begin
29-
return ut_expectation(ut_data_value_anydata.get_instance(a_actual), a_message);
29+
return ut_expectation_compound(ut_data_value_anydata.get_instance(a_actual), a_message);
3030
end;
3131

3232
function expect(a_actual in blob, a_message varchar2 := null) return ut_expectation is
@@ -74,9 +74,9 @@ create or replace package body ut is
7474
return ut_expectation(ut_data_value_varchar2(a_actual), a_message);
7575
end;
7676

77-
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_expectation is
77+
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_expectation_compound is
7878
begin
79-
return ut_expectation(ut_data_value_refcursor(a_actual), a_message);
79+
return ut_expectation_compound(ut_data_value_refcursor(a_actual), a_message);
8080
end;
8181

8282
function expect(a_actual in yminterval_unconstrained, a_message varchar2 := null) return ut_expectation is

source/api/ut.pks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ create or replace package ut authid current_user as
1919

2020
function version return varchar2;
2121

22-
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation;
22+
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_compound;
2323

2424
function expect(a_actual in blob, a_message varchar2 := null) return ut_expectation;
2525

@@ -31,7 +31,7 @@ create or replace package ut authid current_user as
3131

3232
function expect(a_actual in number, a_message varchar2 := null) return ut_expectation;
3333

34-
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_expectation;
34+
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_expectation_compound;
3535

3636
function expect(a_actual in timestamp_unconstrained, a_message varchar2 := null) return ut_expectation;
3737

source/core/types/ut_suite.tpb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ create or replace type body ut_suite as
9797
overriding member function get_error_stack_traces(self ut_suite) return ut_varchar2_list is
9898
l_stack_traces ut_varchar2_list := ut_varchar2_list();
9999
begin
100-
ut_utils.append_to_varchar2_list(l_stack_traces, self.before_all.get_error_stack_trace());
101-
ut_utils.append_to_varchar2_list(l_stack_traces, self.after_all.get_error_stack_trace());
100+
ut_utils.append_to_list(l_stack_traces, self.before_all.get_error_stack_trace());
101+
ut_utils.append_to_list(l_stack_traces, self.after_all.get_error_stack_trace());
102102
return l_stack_traces;
103103
end;
104104

source/core/types/ut_test.tpb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ create or replace type body ut_test as
120120
--expectation results need to be part of test results
121121
self.all_expectations := ut_expectation_processor.get_all_expectations();
122122
self.failed_expectations := ut_expectation_processor.get_failed_expectations();
123+
self.warnings := ut_expectation_processor.get_warnings();
123124
ut_expectation_processor.clear_expectations();
124125
self.results_count.set_counter_values(self.result);
125126
end;
@@ -138,12 +139,12 @@ create or replace type body ut_test as
138139
overriding member function get_error_stack_traces(self ut_test) return ut_varchar2_list is
139140
l_stack_traces ut_varchar2_list := ut_varchar2_list();
140141
begin
141-
ut_utils.append_to_varchar2_list(l_stack_traces, self.parent_error_stack_trace);
142-
ut_utils.append_to_varchar2_list(l_stack_traces, self.before_each.get_error_stack_trace());
143-
ut_utils.append_to_varchar2_list(l_stack_traces, self.before_test.get_error_stack_trace());
144-
ut_utils.append_to_varchar2_list(l_stack_traces, self.item.get_error_stack_trace());
145-
ut_utils.append_to_varchar2_list(l_stack_traces, self.after_test.get_error_stack_trace());
146-
ut_utils.append_to_varchar2_list(l_stack_traces, self.after_each.get_error_stack_trace());
142+
ut_utils.append_to_list(l_stack_traces, self.parent_error_stack_trace);
143+
ut_utils.append_to_list(l_stack_traces, self.before_each.get_error_stack_trace());
144+
ut_utils.append_to_list(l_stack_traces, self.before_test.get_error_stack_trace());
145+
ut_utils.append_to_list(l_stack_traces, self.item.get_error_stack_trace());
146+
ut_utils.append_to_list(l_stack_traces, self.after_test.get_error_stack_trace());
147+
ut_utils.append_to_list(l_stack_traces, self.after_each.get_error_stack_trace());
147148
return l_stack_traces;
148149
end;
149150
overriding member function get_serveroutputs return clob is

source/core/ut_expectation_processor.pkb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ create or replace package body ut_expectation_processor as
2222

2323
g_expectations_called ut_expectation_results := ut_expectation_results();
2424

25+
g_warnings ut_varchar2_list := ut_varchar2_list();
26+
2527
g_nulls_are_equal boolean_not_null := gc_default_nulls_are_equal;
2628

2729
function nulls_are_equal return boolean is
@@ -50,6 +52,7 @@ create or replace package body ut_expectation_processor as
5052
begin
5153
ut_utils.debug_log('ut_expectation_processor.clear_expectations');
5254
g_expectations_called.delete;
55+
g_warnings.delete;
5356
end;
5457

5558
function get_all_expectations return ut_expectation_results is
@@ -156,5 +159,17 @@ create or replace package body ut_expectation_processor as
156159
end if;
157160
return l_result;
158161
end;
162+
163+
procedure add_warning(a_messsage varchar2) is
164+
begin
165+
g_warnings.extend;
166+
g_warnings(g_warnings.last) := a_messsage;
167+
end;
168+
169+
function get_warnings return ut_varchar2_list is
170+
begin
171+
return g_warnings;
172+
end;
173+
159174
end;
160175
/

source/core/ut_expectation_processor.pks

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,9 @@ create or replace package ut_expectation_processor authid current_user as
4848
-- The text is to be consumed by expectation result
4949
function who_called_expectation(a_call_stack varchar2) return varchar2;
5050

51+
procedure add_warning(a_messsage varchar2);
52+
53+
function get_warnings return ut_varchar2_list;
54+
5155
end;
5256
/

source/core/ut_utils.pkb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,18 @@ create or replace package body ut_utils is
297297
return l_result;
298298
end;
299299

300-
procedure append_to_varchar2_list(a_list in out nocopy ut_varchar2_list, a_line varchar2) is
300+
procedure append_to_list(a_list in out nocopy ut_varchar2_list, a_item varchar2) is
301301
begin
302-
if a_line is not null then
302+
if a_item is not null then
303303
if a_list is null then
304304
a_list := ut_varchar2_list();
305305
end if;
306306
a_list.extend;
307-
a_list(a_list.last) := a_line;
307+
a_list(a_list.last) := a_item;
308308
end if;
309-
end append_to_varchar2_list;
309+
end append_to_list;
310310

311-
procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2:= chr(10)) is
311+
procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2:= chr(10)) is
312312
begin
313313
if a_clob_table is not null and cardinality(a_clob_table) > 0 then
314314
if a_src_clob is null then
@@ -369,9 +369,7 @@ create or replace package body ut_utils is
369369
function to_xpath(a_list varchar2, a_ancestors varchar2 := '/*/') return varchar2 is
370370
l_xpath varchar2(32767) := a_list;
371371
begin
372-
if l_xpath not like '/%' then
373-
l_xpath := to_xpath( clob_to_table(a_clob=>a_list, a_delimiter=>','), a_ancestors);
374-
end if;
372+
l_xpath := to_xpath( clob_to_table(a_clob=>a_list, a_delimiter=>','), a_ancestors);
375373
return l_xpath;
376374
end;
377375

@@ -385,7 +383,13 @@ create or replace package body ut_utils is
385383
while i is not null loop
386384
l_item := trim(a_list(i));
387385
if l_item is not null then
388-
l_xpath := l_xpath || a_ancestors ||a_list(i)||'|';
386+
if l_item like '%,%' then
387+
l_xpath := l_xpath || to_xpath( l_item, a_ancestors ) || '|';
388+
elsif l_item like '/%' then
389+
l_xpath := l_xpath || l_item || '|';
390+
else
391+
l_xpath := l_xpath || a_ancestors || l_item || '|';
392+
end if;
389393
end if;
390394
i := a_list.next(i);
391395
end loop;

source/core/ut_utils.pks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ create or replace package ut_utils authid definer is
215215
function get_utplsql_objects_list return ut_object_names;
216216

217217
/**
218-
* Append a line to the end of ut_varchar2_lst
218+
* Append a item to the end of ut_varchar2_list
219219
*/
220-
procedure append_to_varchar2_list(a_list in out nocopy ut_varchar2_list, a_line varchar2);
220+
procedure append_to_list(a_list in out nocopy ut_varchar2_list, a_item varchar2);
221221

222222
procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2 := chr(10));
223223

source/expectations/data_values/ut_data_value_anydata.tpb

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ create or replace type body ut_data_value_anydata as
3232
end;
3333

3434
overriding member function compare_implementation(a_other ut_data_value) return integer is
35+
begin
36+
return compare_implementation( a_other, null, null);
37+
end;
38+
39+
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer is
3540
l_self_data xmltype;
3641
l_other_data xmltype;
3742
l_other ut_data_value_anydata;
3843
l_result integer;
44+
l_ancestors varchar2(20);
3945
procedure filter_by_xpaths(a_xml in out nocopy xmltype, a_exclude varchar2, a_include varchar2) is
4046
begin
4147
if a_exclude is not null then
@@ -50,17 +56,16 @@ create or replace type body ut_data_value_anydata as
5056
l_other := treat(a_other as ut_data_value_anydata);
5157
--needed for 11g xe as it fails on constructing XMLTYPE from null ANYDATA
5258
if not self.is_null() and not l_other.is_null() then
59+
if self is of (ut_data_value_object) then
60+
l_ancestors := '/*/';
61+
else
62+
l_ancestors := '/*/*/';
63+
end if;
5364
ut_expectation_processor.set_xml_nls_params();
5465
l_self_data := xmltype.createxml(self.data_value);
5566
l_other_data := xmltype.createxml(l_other.data_value);
56-
--We use `order member function compare` to do data comparison.
57-
--Therefore, in the `ut_equals` matcher, comparison is done by simply checking
58-
-- `l_result := equal_with_nulls((self.expected = a_actual), a_actual)`
59-
--We cannot guarantee that we will always use `expected = actual ` and not `actual = expected`.
60-
--We should expect the same behaviour regardless of that is the order.
61-
-- This is why we need to coalesce `exclude_xpath` though at most one of them will always be populated
62-
filter_by_xpaths(l_self_data, coalesce(self.exclude_xpath, l_other.exclude_xpath), coalesce(self.include_xpath, l_other.include_xpath));
63-
filter_by_xpaths(l_other_data, coalesce(self.exclude_xpath, l_other.exclude_xpath), coalesce(self.include_xpath, l_other.include_xpath));
67+
filter_by_xpaths(l_self_data, a_exclude_xpath, a_include_xpath);
68+
filter_by_xpaths(l_other_data, a_exclude_xpath, a_include_xpath);
6469
ut_expectation_processor.reset_nls_params();
6570
if l_self_data is not null and l_other_data is not null then
6671
l_result := dbms_lob.compare( l_self_data.getclobval(), l_other_data.getclobval() );
@@ -94,10 +99,9 @@ create or replace type body ut_data_value_anydata as
9499
return self.data_value is null or ut_utils.int_to_boolean(self.data_value_is_null);
95100
end;
96101

97-
static function get_instance(a_data_value anydata, a_exclude varchar2 := null, a_include varchar2 := null) return ut_data_value_anydata is
102+
static function get_instance(a_data_value anydata) return ut_data_value_anydata is
98103
l_result ut_data_value_anydata := ut_data_value_object(null);
99104
l_type anytype;
100-
l_ancestors varchar2(20) := '/*/';
101105
l_type_code integer;
102106
begin
103107
if a_data_value is not null then
@@ -107,27 +111,13 @@ create or replace type body ut_data_value_anydata as
107111
l_result := ut_data_value_object(a_data_value);
108112
else
109113
l_result := ut_data_value_collection(a_data_value);
110-
l_ancestors := '/*/*/';
111114
end if;
112-
l_result.exclude_xpath := ut_utils.to_xpath( a_exclude, l_ancestors );
113-
l_result.include_xpath := ut_utils.to_xpath( a_include, l_ancestors );
114115
else
115116
raise_application_error(-20000, 'Data type '||a_data_value.gettypename||' in ANYDATA is not supported by utPLSQL');
116117
end if;
117118
end if;
118119
return l_result;
119120
end;
120121

121-
static function get_instance(a_data_value anydata, a_exclude ut_varchar2_list, a_include ut_varchar2_list) return ut_data_value_anydata is
122-
l_result ut_data_value_anydata;
123-
l_exclude varchar2(32767);
124-
l_include varchar2(32767);
125-
begin
126-
l_exclude := substr(ut_utils.table_to_clob(a_exclude, ','), 1, 32767);
127-
l_include := substr(ut_utils.table_to_clob(a_include, ','), 1, 32767);
128-
l_result := ut_data_value_anydata.get_instance(a_data_value, l_exclude, l_include );
129-
return l_result;
130-
end;
131-
132122
end;
133123
/

source/expectations/data_values/ut_data_value_anydata.tps

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,11 @@ create or replace type ut_data_value_anydata under ut_data_value(
1919
data_value anydata,
2020

2121
data_value_is_null integer,
22-
/**
23-
* Holds xpath (list of attributes) to exclude when comparing object
24-
*/
25-
exclude_xpath varchar2(32767),
26-
/**
27-
* Holds xpath (list of attributes) to include when comparing cursors
28-
*/
29-
include_xpath varchar2(32767),
30-
3122
overriding member function to_string return varchar2,
32-
overriding member function compare_implementation( a_other ut_data_value ) return integer,
23+
overriding member function compare_implementation(a_other ut_data_value) return integer,
24+
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer,
3325
final member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata, a_data_object_type varchar2),
3426
overriding member function is_null return boolean,
35-
static function get_instance(a_data_value anydata, a_exclude varchar2 := null, a_include varchar2 := null) return ut_data_value_anydata,
36-
static function get_instance(a_data_value anydata, a_exclude ut_varchar2_list, a_include ut_varchar2_list) return ut_data_value_anydata
27+
static function get_instance(a_data_value anydata) return ut_data_value_anydata
3728
) not final not instantiable
3829
/

0 commit comments

Comments
 (0)