Skip to content

Commit ff59727

Browse files
committed
Refactored ut_data_value, ut_expectation and ut_matchers.
Updated Unit Tests
1 parent 4d9c129 commit ff59727

117 files changed

Lines changed: 1729 additions & 862 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/api/ut.pkb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ create or replace package body ut is
1717
limitations under the License.
1818
*/
1919

20+
g_nls_date_format varchar2(4000);
21+
2022
function version return varchar2 is
2123
begin
2224
return ut_utils.gc_version;
2325
end;
2426

2527
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_anydata is
2628
begin
27-
return ut_expectation_anydata(ut_data_value_anydata(a_actual), a_message);
29+
return ut_expectation_anydata(ut_data_value_anydata.get_instance(a_actual), a_message);
2830
end;
2931

3032
function expect(a_actual in blob, a_message varchar2 := null) return ut_expectation_blob is
@@ -164,5 +166,24 @@ create or replace package body ut is
164166
ut.run(l_paths, a_reporter, a_color_console);
165167
end;
166168

169+
procedure set_nls is
170+
begin
171+
if g_nls_date_format is null then
172+
select nsp.value
173+
into g_nls_date_format
174+
from nls_session_parameters nsp
175+
where parameter = 'NLS_DATE_FORMAT';
176+
end if;
177+
execute immediate 'alter session set nls_date_format = '''||ut_utils.gc_date_format||'''';
178+
end;
179+
180+
procedure reset_nls is
181+
begin
182+
if g_nls_date_format is not null then
183+
execute immediate 'alter session set nls_date_format = '''||g_nls_date_format||'''';
184+
end if;
185+
g_nls_date_format := null;
186+
end;
187+
167188
end ut;
168189
/

source/api/ut.pks

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,19 @@ create or replace package ut authid current_user as
5959

6060
procedure run(a_path varchar2, a_reporter ut_reporter_base := ut_documentation_reporter(), a_color_console boolean := false);
6161

62+
/*
63+
Helper procedure to set NLS session parameter for date processing in refcursor.
64+
It needs to be called before refcursor is open in order to have DATE data type data in refcursor
65+
properly transformed into XML format as a date-time element.
66+
If the function is not called before opening a cursor to be compared, the DATE data is compared using default NLS setting for date.
67+
*/
68+
procedure set_nls;
69+
70+
/*
71+
Helper procedure to reset NLS session parameter to it's original state.
72+
It needs to be called after refcursor is open in order restore the original session state and keep the NLS date setting at default.
73+
*/
74+
procedure reset_nls;
75+
6276
end ut;
6377
/

source/core/types/ut_expectation_result.tpb

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,91 +16,40 @@ create or replace type body ut_expectation_result is
1616
limitations under the License.
1717
*/
1818

19-
constructor function ut_expectation_result(self in out nocopy ut_expectation_result, a_result integer, a_error_message varchar2)
19+
constructor function ut_expectation_result(self in out nocopy ut_expectation_result, a_status integer, a_description varchar2, a_message clob)
2020
return self as result is
2121
begin
22-
self.result := a_result;
23-
self.error_message := a_error_message;
24-
self.caller_info := ut_expectation_processor.who_called_expectation();
25-
return;
26-
end;
27-
28-
constructor function ut_expectation_result(self in out nocopy ut_expectation_result, a_name varchar2, a_additional_info varchar2, a_error_message varchar2, a_result integer, a_expected_type varchar2, a_actual_type varchar2,
29-
a_expected_value_string varchar2, a_actual_value_string varchar2, a_message varchar2 default null)
30-
return self as result is
31-
begin
32-
self.matcher_name := a_name;
33-
self.additional_info := a_additional_info;
34-
self.result := a_result;
35-
self.message := a_message;
36-
self.error_message := a_error_message;
37-
self.expected_type := a_expected_type;
38-
self.actual_type := a_actual_type;
39-
self.expected_value_string := a_expected_value_string;
40-
self.actual_value_string := a_actual_value_string;
41-
if a_result = ut_utils.tr_failure then
42-
self.caller_info := ut_expectation_processor.who_called_expectation();
22+
self.status := a_status;
23+
self.description := a_description;
24+
self.message := a_message;
25+
if self.status = ut_utils.tr_failure then
26+
self.caller_info := ut_expectation_processor.who_called_expectation();
4327
end if;
4428
return;
4529
end;
4630

4731
member function get_result_clob(self in ut_expectation_result) return clob is
4832
l_result clob;
49-
l_actual_val_msg varchar2(1000);
50-
l_actual_val varchar2(32767);
51-
l_expected_msg varchar2(1000);
52-
l_expected_val varchar2(32767);
53-
54-
procedure add_text_line(a_clob in out nocopy clob, a_prefix varchar2, a_text varchar2 := null) is
55-
l_text varchar2(32767);
56-
begin
57-
if a_text is not null then
58-
l_text := a_prefix || ut_utils.indent_lines( a_text, length(a_prefix) );
59-
else
60-
l_text := a_prefix;
61-
end if;
62-
if a_clob is not null and l_text is not null then
63-
l_text := chr(10) || l_text;
64-
end if;
65-
ut_utils.append_to_clob(a_clob, l_text);
66-
end;
6733
begin
68-
if self.result != ut_utils.tr_success or self.error_message is not null then
34+
if self.description is not null then
35+
ut_utils.append_to_clob(l_result, '"'||self.description||'"');
6936
if self.message is not null then
70-
add_text_line(l_result, ' expectation description: ', self.message);
71-
end if;
72-
73-
if self.result != ut_utils.tr_success then
74-
if self.actual_value_string is not null or self.actual_type is not null then
75-
l_actual_val_msg := ' expected this: ';
76-
l_actual_val := self.actual_value_string || '(' || self.actual_type || ')';
77-
end if;
78-
79-
l_expected_msg := ' ' || self.matcher_name || self.additional_info;
80-
if self.expected_value_string is not null or self.expected_type is not null then
81-
l_expected_msg := l_expected_msg || ': ';
82-
l_expected_val := self.expected_value_string||'('||self.expected_type||')';
83-
if length(l_expected_msg) > length(l_actual_val_msg) then
84-
l_actual_val_msg := rpad(l_actual_val_msg , length(l_expected_msg));
85-
else
86-
l_expected_msg := rpad(l_expected_msg , length(l_actual_val_msg));
87-
end if;
88-
end if;
89-
add_text_line(l_result, l_actual_val_msg, l_actual_val);
90-
add_text_line(l_result, l_expected_msg, l_expected_val);
37+
ut_utils.append_to_clob(l_result, chr(10));
9138
end if;
92-
9339
end if;
94-
if self.error_message is not null then
95-
add_text_line(l_result, ' error: '||ut_utils.indent_lines( self.error_message, length(' error: ') ) );
96-
end if;
97-
40+
ut_utils.append_to_clob(l_result, self.message);
9841
return l_result;
9942
end;
10043

10144
member function get_result_lines(self in ut_expectation_result) return ut_varchar2_list is
10245
begin
10346
return ut_utils.clob_to_table(get_result_clob(), 4000 );
10447
end;
48+
49+
member function result return integer is
50+
begin
51+
return self.status;
52+
end;
53+
10554
end;
10655
/

source/core/types/ut_expectation_result.tps

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,29 @@ create or replace type ut_expectation_result as object(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18+
1819
/*
19-
* name of the matcher that was used to check the expectation
20+
* The expectation result status
2021
*/
21-
matcher_name varchar2(250 char),
22+
status integer(1),
2223
/*
23-
* The expectation result
24+
* User description provided with the expectation
2425
*/
25-
result integer(1),
26+
description varchar2(32767),
2627
/*
2728
* Additional information about the expression used by matcher
2829
* Used for complex matcher: like, between, ut_match etc.
2930
*/
30-
additional_info varchar2(4000 char),
31-
/*
32-
* Data type name for the expected value
33-
*/
34-
expected_type varchar2(250 char),
35-
/*
36-
* Data type name for the actual value
37-
*/
38-
actual_type varchar2(250 char),
39-
/*
40-
* String representation of expected value
41-
*/
42-
expected_value_string varchar2(4000 char),
43-
/*
44-
* String representation of actual value
45-
*/
46-
actual_value_string varchar2(4000 char),
47-
/*
48-
* User message (description) provided with the expectation
49-
*/
50-
message varchar2(4000 char),
51-
/*
52-
* Error message that was captured.
53-
*/
54-
error_message varchar2(4000 char),
31+
message varchar2(32767),
5532
/*
5633
* The information about the line of code that invoked the expectation
5734
*/
58-
caller_info varchar2(4000 char),
59-
constructor function ut_expectation_result(self in out nocopy ut_expectation_result, a_result integer, a_error_message varchar2)
60-
return self as result,
61-
constructor function ut_expectation_result(self in out nocopy ut_expectation_result, a_name varchar2, a_additional_info varchar2, a_error_message varchar2,
62-
a_result integer, a_expected_type varchar2, a_actual_type varchar2,
63-
a_expected_value_string varchar2, a_actual_value_string varchar2, a_message varchar2 default null)
35+
caller_info varchar2(32767),
36+
constructor function ut_expectation_result(self in out nocopy ut_expectation_result, a_status integer, a_description varchar2, a_message clob)
6437
return self as result,
6538
member function get_result_clob(self in ut_expectation_result) return clob,
66-
member function get_result_lines(self in ut_expectation_result) return ut_varchar2_list
39+
member function get_result_lines(self in ut_expectation_result) return ut_varchar2_list,
40+
member function result return integer
6741
)
6842
not final
6943
/

source/core/ut_expectation_processor.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ create or replace package body ut_expectation_processor as
4040
ut_utils.debug_log('ut_expectation_processor.get_status');
4141

4242
for i in 1 .. g_expectations_called.count loop
43-
l_result := greatest(l_result, g_expectations_called(i).result);
43+
l_result := greatest(l_result, g_expectations_called(i).status);
4444
exit when l_result = ut_utils.tr_error;
4545
end loop;
4646
return l_result;
@@ -70,7 +70,7 @@ create or replace package body ut_expectation_processor as
7070

7171
procedure report_failure(a_message in varchar2) is
7272
begin
73-
add_expectation_result(ut_expectation_result(ut_utils.tr_failure, a_message));
73+
add_expectation_result(ut_expectation_result(ut_utils.tr_failure, null, a_message));
7474
end;
7575

7676
function get_session_parameters return tt_nls_params is

source/core/ut_utils.pkb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ create or replace package body ut_utils is
1616
limitations under the License.
1717
*/
1818

19-
function quote_string(a_value varchar2) return varchar2 is
19+
function surround_with(a_value varchar2, a_quote_char varchar2) return varchar2 is
2020
begin
21-
return case when a_value is not null then ''''||a_value||'''' else gc_null_string end;
21+
return case when a_quote_char is not null then a_quote_char||a_value||a_quote_char else a_value end;
2222
end;
2323

2424
function test_result_to_char(a_test_result integer) return varchar2 as
@@ -89,42 +89,42 @@ create or replace package body ut_utils is
8989
$end
9090
end;
9191

92-
function to_string(a_value varchar2) return varchar2 is
92+
function to_string(a_value varchar2, a_qoute_char varchar2 := '''') return varchar2 is
9393
l_len integer := coalesce(length(a_value),0);
9494
l_result varchar2(32767);
9595
begin
9696
if l_len = 0 then
9797
l_result := gc_null_string;
9898
elsif l_len <= gc_max_input_string_length then
99-
l_result := quote_string(a_value);
99+
l_result := surround_with(a_value, a_qoute_char);
100100
else
101-
l_result := quote_string(substr(a_value,1,gc_overflow_substr_len)) || gc_more_data_string;
101+
l_result := surround_with(substr(a_value,1,gc_overflow_substr_len),a_qoute_char) || gc_more_data_string;
102102
end if ;
103103
return l_result;
104104
end;
105105

106-
function to_string(a_value clob) return varchar2 is
106+
function to_string(a_value clob, a_qoute_char varchar2 := '''') return varchar2 is
107107
l_len integer := coalesce(dbms_lob.getlength(a_value), 0);
108108
l_result varchar2(32767);
109109
begin
110110
if l_len = 0 then
111111
l_result := gc_null_string;
112112
elsif l_len <= gc_max_input_string_length then
113-
l_result := quote_string(a_value);
113+
l_result := surround_with(a_value,a_qoute_char);
114114
else
115-
l_result := quote_string(dbms_lob.substr(a_value, gc_overflow_substr_len)) || gc_more_data_string;
115+
l_result := surround_with(dbms_lob.substr(a_value, gc_overflow_substr_len),a_qoute_char) || gc_more_data_string;
116116
end if;
117117
return l_result;
118118
end;
119119

120-
function to_string(a_value blob) return varchar2 is
120+
function to_string(a_value blob, a_qoute_char varchar2 := '''') return varchar2 is
121121
l_len integer := coalesce(dbms_lob.getlength(a_value), 0);
122122
l_result varchar2(32767);
123123
begin
124124
if l_len = 0 then
125125
l_result := gc_null_string;
126126
elsif l_len <= gc_max_input_string_length then
127-
l_result := quote_string(rawtohex(a_value));
127+
l_result := surround_with(rawtohex(a_value),a_qoute_char);
128128
else
129129
l_result := to_string( rawtohex(dbms_lob.substr(a_value, gc_overflow_substr_len)) );
130130
end if ;
@@ -277,9 +277,13 @@ create or replace package body ut_utils is
277277
extract(second from(a_end_time - a_start_time));
278278
end;
279279

280-
function indent_lines(a_text varchar2, a_indent_size integer) return varchar2 is
280+
function indent_lines(a_text varchar2, a_indent_size integer := 4, a_include_first_line boolean := false) return varchar2 is
281281
begin
282-
return replace( a_text, chr(10), chr(10) || lpad( ' ', a_indent_size ) );
282+
if a_include_first_line then
283+
return rtrim(lpad( ' ', a_indent_size ) || replace( a_text, chr(10), chr(10) || lpad( ' ', a_indent_size ) ));
284+
else
285+
return rtrim(replace( a_text, chr(10), chr(10) || lpad( ' ', a_indent_size ) ));
286+
end if;
283287
end;
284288

285289
function get_utplsql_objects_list return ut_object_names is
@@ -313,6 +317,7 @@ create or replace package body ut_utils is
313317
dbms_lob.append(a_src_clob, a_new_data);
314318
end if;
315319
end;
320+
316321
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data varchar2) is
317322
begin
318323
if a_new_data is not null then

source/core/ut_utils.pks

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ create or replace package ut_utils authid definer is
111111
procedure debug_log(a_message varchar2);
112112
procedure debug_log(a_message clob);
113113

114-
function to_string(a_value varchar2) return varchar2;
114+
function to_string(a_value varchar2, a_qoute_char varchar2 := '''') return varchar2;
115115

116-
function to_string(a_value clob) return varchar2;
116+
function to_string(a_value clob, a_qoute_char varchar2 := '''') return varchar2;
117117

118-
function to_string(a_value blob) return varchar2;
118+
function to_string(a_value blob, a_qoute_char varchar2 := '''') return varchar2;
119119

120120
function to_string(a_value boolean) return varchar2;
121121

@@ -195,7 +195,7 @@ create or replace package ut_utils authid definer is
195195
/*
196196
* Returns a text indented with spaces except the first line.
197197
*/
198-
function indent_lines(a_text varchar2, a_indent_size integer) return varchar2;
198+
function indent_lines(a_text varchar2, a_indent_size integer := 4, a_include_first_line boolean := false) return varchar2;
199199

200200

201201
/*
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
create global temporary table ut_cursor_data(
2+
cursor_data_guid raw(16),
3+
row_no integer,
4+
row_data xmltype,
5+
constraint ut_cursor_data_pk primary key(cursor_data_guid, row_no)
6+
) on commit preserve rows;

0 commit comments

Comments
 (0)