Skip to content

Commit 6547eba

Browse files
committed
Updated report formatting and separated responsibilities of: report content and report formatting between methods
1 parent abe8195 commit 6547eba

20 files changed

Lines changed: 100 additions & 137 deletions

source/core/ut_utils.pkb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,6 @@ create or replace package body ut_utils is
268268
return l_result;
269269
end;
270270

271-
procedure append_to_clob(a_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2:= chr(10)) is
272-
begin
273-
for i in 1 .. a_clob_table.count loop
274-
append_to_clob(a_clob,a_delimiter);
275-
dbms_lob.append(a_clob,a_clob_table(i));
276-
end loop;
277-
end;
278-
279271
function time_diff(a_start_time timestamp with time zone, a_end_time timestamp with time zone) return number is
280272
begin
281273
return
@@ -316,6 +308,21 @@ create or replace package body ut_utils is
316308
end if;
317309
end append_to_varchar2_list;
318310

311+
procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2:= chr(10)) is
312+
begin
313+
if a_clob_table is not null and cardinality(a_clob_table) > 0 then
314+
if a_src_clob is null then
315+
dbms_lob.createtemporary(a_src_clob, true);
316+
end if;
317+
for i in 1 .. a_clob_table.count loop
318+
dbms_lob.append(a_src_clob,a_clob_table(i));
319+
if i < a_clob_table.count then
320+
append_to_clob(a_src_clob,a_delimiter);
321+
end if;
322+
end loop;
323+
end if;
324+
end;
325+
319326
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data clob) is
320327
begin
321328
if a_new_data is not null and dbms_lob.getlength(a_new_data) > 0 then

source/core/ut_utils.pks

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ create or replace package ut_utils authid definer is
198198

199199
function table_to_clob(a_text_table ut_varchar2_list, a_delimiter varchar2:= chr(10)) return clob;
200200

201-
procedure append_to_clob(a_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2 := chr(10));
202-
203201
/**
204202
* Returns time difference in seconds (with miliseconds) between given timestamps
205203
*/
@@ -221,7 +219,10 @@ create or replace package ut_utils authid definer is
221219
*/
222220
procedure append_to_varchar2_list(a_list in out nocopy ut_varchar2_list, a_line varchar2);
223221

222+
procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab, a_delimiter varchar2 := chr(10));
223+
224224
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data clob);
225+
225226
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data varchar2);
226227

227228
function convert_collection(a_collection ut_varchar2_list) return ut_varchar2_rows;

source/expectations/data_values/ut_data_value.tpb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,26 @@ create or replace type body ut_data_value as
3535
return false;
3636
end;
3737

38-
final member function format_multi_line( a_string varchar2) return varchar2 is
38+
member function get_object_info return varchar2 is
3939
begin
40-
if is_multi_line() then
41-
return chr(10)||rtrim(a_string,chr(10))||chr(10);
42-
else
43-
return a_string;
44-
end if;
40+
return self.data_type;
4541
end;
4642

47-
final member function to_string_report(a_add_new_line_for_multi_line boolean := false, a_with_type_name boolean := true) return varchar2 is
43+
final member function to_string_report(a_add_new_line_for_multi_line boolean := false, a_with_object_info boolean := true) return varchar2 is
4844
l_result varchar2(32767);
45+
l_info varchar2(32767);
4946
begin
50-
l_result := ut_utils.indent_lines( self.to_string() );
51-
if a_with_type_name then
52-
l_result := l_result ||' ('||self.data_type||') ';
47+
if a_with_object_info then
48+
l_info := '('||get_object_info()||')';
5349
end if;
54-
if self.is_multi_line and a_add_new_line_for_multi_line then
55-
l_result := l_result || chr(10);
50+
if self.is_multi_line() then
51+
l_result :=
52+
l_info || chr(10) || ut_utils.indent_lines( rtrim(self.to_string(),chr(10)), a_include_first_line =>true );
53+
if a_add_new_line_for_multi_line then
54+
l_result := l_result || chr(10);
55+
end if;
56+
else
57+
l_result := self.to_string() || ' ' || l_info || ' ';
5658
end if;
5759
return l_result;
5860
end;

source/expectations/data_values/ut_data_value.tps

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ create or replace type ut_data_value authid current_user as object (
1919
self_type varchar2(250 char),
2020
not instantiable member function is_null return boolean,
2121
not instantiable member function to_string return varchar2,
22+
member function get_object_info return varchar2,
2223
member function is_multi_line return boolean,
23-
final member function format_multi_line( a_string varchar2) return varchar2,
24-
final member function to_string_report(a_add_new_line_for_multi_line boolean := false, a_with_type_name boolean := true) return varchar2,
24+
final member function to_string_report(a_add_new_line_for_multi_line boolean := false, a_with_object_info boolean := true) return varchar2,
2525
order member function compare( a_other ut_data_value ) return integer,
2626
member function is_diffable return boolean,
2727
member function diff( a_other ut_data_value ) return varchar2,

source/expectations/data_values/ut_data_value_anydata.tpb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ create or replace type body ut_data_value_anydata as
1616
limitations under the License.
1717
*/
1818

19-
overriding member function is_null return boolean is
20-
begin
21-
return true;
22-
end;
23-
2419
overriding member function to_string return varchar2 is
2520
l_result varchar2(32767);
2621
l_clob clob;
@@ -33,7 +28,7 @@ create or replace type body ut_data_value_anydata as
3328
l_result := ut_utils.to_string( l_clob, null );
3429
ut_expectation_processor.reset_nls_params();
3530
end if;
36-
return self.format_multi_line( l_result );
31+
return l_result;
3732
end;
3833

3934
overriding member function compare_implementation(a_other ut_data_value) return integer is
@@ -77,11 +72,26 @@ create or replace type body ut_data_value_anydata as
7772
return l_result;
7873
end;
7974

80-
final member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata, a_self_type varchar2) is
75+
final member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata, a_data_object_type varchar2) is
8176
begin
8277
self.data_value := a_value;
83-
self.self_type := a_self_type;
8478
self.data_type := case when a_value is not null then lower(a_value.gettypename) else 'undefined' end;
79+
if data_value is not null then
80+
execute immediate '
81+
declare
82+
l_data '||self.data_value.gettypename()||';
83+
l_value anydata := :a_value;
84+
l_status integer;
85+
begin
86+
l_status := l_value.get'||a_data_object_type||'(l_data);
87+
:l_data_is_null := case when l_data is null then 1 else 0 end;
88+
end;' using in self.data_value, out self.data_value_is_null;
89+
end if;
90+
end;
91+
92+
overriding member function is_null return boolean is
93+
begin
94+
return self.data_value is null or ut_utils.int_to_boolean(self.data_value_is_null);
8595
end;
8696

8797
static function get_instance(a_data_value anydata, a_exclude varchar2 := null, a_include varchar2 := null) return ut_data_value_anydata is

source/expectations/data_values/ut_data_value_anydata.tps

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ create or replace type ut_data_value_anydata under ut_data_value(
1717
*/
1818

1919
data_value anydata,
20+
21+
data_value_is_null integer,
2022
/**
2123
* Holds xpath (list of attributes) to exclude when comparing object
2224
*/
@@ -26,10 +28,10 @@ create or replace type ut_data_value_anydata under ut_data_value(
2628
*/
2729
include_xpath varchar2(32767),
2830

29-
overriding member function is_null return boolean,
3031
overriding member function to_string return varchar2,
3132
overriding member function compare_implementation( a_other ut_data_value ) return integer,
32-
final member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata, a_self_type varchar2),
33+
final member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata, a_data_object_type varchar2),
34+
overriding member function is_null return boolean,
3335
static function get_instance(a_data_value anydata, a_exclude varchar2 := null, a_include varchar2 := null) return ut_data_value_anydata,
3436
static function get_instance(a_data_value anydata, a_exclude ut_varchar2_list, a_include ut_varchar2_list) return ut_data_value_anydata
3537
) not final not instantiable

source/expectations/data_values/ut_data_value_blob.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ create or replace type body ut_data_value_blob as
3131

3232
overriding member function to_string return varchar2 is
3333
begin
34-
return self.format_multi_line( ut_utils.to_string(self.data_value) );
34+
return ut_utils.to_string(self.data_value);
3535
end;
3636

3737
overriding member function compare_implementation(a_other ut_data_value) return integer is

source/expectations/data_values/ut_data_value_clob.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ create or replace type body ut_data_value_clob as
3131

3232
overriding member function to_string return varchar2 is
3333
begin
34-
return self.format_multi_line( ut_utils.to_string(self.data_value) );
34+
return ut_utils.to_string(self.data_value);
3535
end;
3636

3737
overriding member function compare_implementation(a_other ut_data_value) return integer is

source/expectations/data_values/ut_data_value_collection.tpb

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,27 @@ create or replace type body ut_data_value_collection as
1818

1919
constructor function ut_data_value_collection(self in out nocopy ut_data_value_collection, a_value anydata) return self as result is
2020
begin
21-
self.init(a_value, $$plsql_unit);
22-
return;
23-
end;
24-
25-
overriding member function is_null return boolean is
26-
l_is_null boolean;
27-
l_data_is_null pls_integer;
28-
l_sql varchar2(32767);
29-
l_cursor number;
30-
l_status number;
31-
begin
32-
if self.data_value is null then
33-
l_is_null := true;
34-
--check if typename is a schema based object
35-
else
36-
--XMLTYPE doesn't like the null being passed to ANYDATA so we need to check if anydata holds null Object/collection
37-
l_sql := '
21+
self.self_type := $$plsql_unit;
22+
self.init(a_value, 'collection');
23+
if a_value is not null then
24+
execute immediate '
3825
declare
39-
l_data '||self.data_value.gettypename()||';
26+
l_data '||a_value.gettypename()||';
4027
l_value anydata := :a_value;
41-
x integer;
28+
l_status integer;
4229
begin
43-
x := l_value.getCollection(l_data);
44-
:l_data_is_null := case when l_data is null then 1 else 0 end;
45-
end;';
46-
l_cursor := sys.dbms_sql.open_cursor();
47-
sys.dbms_sql.parse(l_cursor, l_sql, dbms_sql.native);
48-
sys.dbms_sql.bind_variable(l_cursor,'a_value',self.data_value);
49-
sys.dbms_sql.bind_variable(l_cursor,'l_data_is_null',l_data_is_null);
50-
begin
51-
l_status := sys.dbms_sql.execute(l_cursor);
52-
sys.dbms_sql.variable_value(l_cursor,'l_data_is_null',l_data_is_null);
53-
sys.dbms_sql.close_cursor(l_cursor);
54-
exception when others then
55-
if sys.dbms_sql.is_open(l_cursor) then
56-
sys.dbms_sql.close_cursor(l_cursor);
57-
end if;
58-
raise;
59-
end;
60-
l_is_null := ut_utils.int_to_boolean(l_data_is_null);
30+
l_status := l_value.getCollection(l_data);
31+
if l_data is not null then
32+
:l_count := l_data.count;
33+
end if;
34+
end;' using in self.data_value, out self.elements_count;
6135
end if;
62-
return l_is_null;
36+
return;
37+
end;
38+
39+
overriding member function get_object_info return varchar2 is
40+
begin
41+
return self.data_type||' [ count = '||self.elements_count||' ]';
6342
end;
6443

6544
member function is_empty return boolean is

source/expectations/data_values/ut_data_value_collection.tps

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ create or replace type ut_data_value_collection under ut_data_value_anydata(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18+
19+
elements_count integer,
20+
1821
constructor function ut_data_value_collection(self in out nocopy ut_data_value_collection, a_value anydata) return self as result,
19-
overriding member function is_null return boolean,
22+
overriding member function get_object_info return varchar2,
2023
member function is_empty return boolean,
2124
overriding member function is_multi_line return boolean
2225
)

0 commit comments

Comments
 (0)