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

Skip to content

Commit c11aa24

Browse files
committed
Initial check in.
Covers issues of displaying wrong info in diff message for nested objects. Exclude object type from being part of the SQL generation.
1 parent f28ae62 commit c11aa24

5 files changed

Lines changed: 70 additions & 8 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ create or replace package body ut_compound_data_helper is
144144
l_index := a_pk_table.next(l_index);
145145
end loop;
146146
end if;
147-
if not(l_exists) then
147+
if a_data_info.column_type in ('OBJECT') then
148+
null;
149+
elsif not(l_exists) then
148150
l_sql_stmt := ' (decode(a.'||a_data_info.transformed_name||','||' e.'||a_data_info.transformed_name||',1,0) = 0)';
149151
end if;
150152
return l_sql_stmt;
@@ -161,7 +163,9 @@ create or replace package body ut_compound_data_helper is
161163
if l_pk_tab.count <> 0 then
162164
l_index:= l_pk_tab.first;
163165
loop
164-
if l_pk_tab(l_index) in (a_data_info.access_path, a_data_info.parent_name) then
166+
if a_data_info.column_type in ('OBJECT') then
167+
null;
168+
elsif l_pk_tab(l_index) in (a_data_info.access_path, a_data_info.parent_name) then
165169
--When then table is nested and join is on whole table
166170
l_sql_stmt := l_sql_stmt ||' a.'||a_data_info.transformed_name||q'[ = ]'||' e.'||a_data_info.transformed_name;
167171
end if;
@@ -187,15 +191,21 @@ create or replace package body ut_compound_data_helper is
187191
if a_pk_table is not empty then
188192
l_index:= a_pk_table.first;
189193
loop
190-
if a_pk_table(l_index) in (a_data_info.access_path, a_data_info.parent_name) then
194+
if a_data_info.column_type in ('OBJECT') then
195+
null;
196+
elsif a_pk_table(l_index) in (a_data_info.access_path, a_data_info.parent_name) then
191197
--When then table is nested and join is on whole table
192198
l_sql_stmt := l_sql_stmt ||a_alias||a_data_info.transformed_name;
193199
end if;
194200
exit when (a_data_info.access_path = a_pk_table(l_index)) or l_index = a_pk_table.count;
195201
l_index := a_pk_table.next(l_index);
196202
end loop;
197203
else
198-
l_sql_stmt := a_alias||a_data_info.transformed_name;
204+
if a_data_info.column_type in ('OBJECT') then
205+
null;
206+
else
207+
l_sql_stmt := a_alias||a_data_info.transformed_name;
208+
end if;
199209
end if;
200210
return l_sql_stmt;
201211
end;
@@ -206,7 +216,9 @@ create or replace package body ut_compound_data_helper is
206216
l_alias varchar2(10) := a_alias;
207217
l_col_syntax varchar2(4000);
208218
begin
209-
if a_data_info.is_sql_diffable = 0 then
219+
if a_data_info.column_type in ('OBJECT') then
220+
null;
221+
elsif a_data_info.is_sql_diffable = 0 then
210222
l_col_syntax := 'ut_utils.get_hash('||l_alias||a_data_info.transformed_name||'.getClobVal()) as '||a_data_info.transformed_name ;
211223
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type = 'DATE' then
212224
l_col_syntax := 'to_date('||l_alias||a_data_info.transformed_name||') as '|| a_data_info.transformed_name;
@@ -238,14 +250,20 @@ create or replace package body ut_compound_data_helper is
238250
--We cannot use a precision and scale as dbms_sql.describe_columns3 return precision 0 for dual table
239251
-- there is also no need for that as we not process data but only read and compare as they are stored
240252
l_col_type := a_data_info.column_type;
253+
elsif a_data_info.column_type in ('OBJECT') then
254+
null;
241255
else
242256
l_col_type := a_data_info.column_type
243257
||case when a_data_info.column_len is not null
244258
then '('||a_data_info.column_len||')'
245259
else null
246260
end;
247261
end if;
248-
return a_data_info.transformed_name||' '||l_col_type||q'[ PATH ']'||a_data_info.access_path||q'[']';
262+
if a_data_info.column_type in ('OBJECT') then
263+
return null;
264+
else
265+
return a_data_info.transformed_name||' '||l_col_type||q'[ PATH ']'||a_data_info.access_path||q'[']';
266+
end if;
249267
end;
250268

251269
procedure gen_sql_pieces_out_of_cursor(
@@ -398,8 +416,12 @@ create or replace package body ut_compound_data_helper is
398416
l_column_list ut_varchar2_list := ut_varchar2_list();
399417
begin
400418
for i in 1..a_cursor_info.count loop
401-
l_column_list.extend;
402-
l_column_list(l_column_list.last) := a_cursor_info(i).access_path;
419+
--This avoids extracting single columns from nested objects.
420+
--as we can go down to any level but we will lose visibility of parent.
421+
if a_cursor_info(i).hierarchy_level = 1 then
422+
l_column_list.extend;
423+
l_column_list(l_column_list.last) := a_cursor_info(i).access_path;
424+
end if;
403425
end loop;
404426
return l_column_list;
405427
end;
@@ -571,6 +593,7 @@ create or replace package body ut_compound_data_helper is
571593
xmlelement( name "ROW", a_diff_tab(idx).act_item_data), a_diff_tab(idx).act_data_id,
572594
xmlelement( name "ROW", a_diff_tab(idx).exp_item_data), a_diff_tab(idx).exp_data_id,
573595
a_diff_tab(idx).item_no, a_diff_tab(idx).dup_no);
596+
574597
exception
575598
when ut_utils.ex_failure_for_all then
576599
raise_application_error(ut_utils.gc_dml_for_all,'Failure to insert a diff tmp data.');

test/install_ut3_tester_helper.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ alter session set plsql_optimize_level=0;
66
--Install ut3_tester_helper
77
@@ut3_tester_helper/test_dummy_object.tps
88
@@ut3_tester_helper/other_dummy_object.tps
9+
@@ut3_tester_helper/test_dummy_nested_object.tps
910
@@ut3_tester_helper/test_dummy_object_list.tps
1011
@@ut3_tester_helper/test_tab_varchar2.tps
1112
@@ut3_tester_helper/test_tab_varray.tps
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_NESTED_OBJECT';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_nested_object force';
7+
end if;
8+
end;
9+
/
10+
11+
create or replace type test_dummy_nested_object as object (
12+
first_nested_obj test_dummy_object,
13+
sec_nested_obj test_dummy_object
14+
)
15+
/

test/ut3_user/expectations/test_expectation_anydata.pkb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,25 @@ Rows: [ 60 differences, showing first 20 ]
991991
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
992992

993993
end;
994+
995+
procedure failure_nesting_objects is
996+
l_actual_message varchar2(32767);
997+
l_expected_message varchar2(32767);
998+
begin
999+
--Arrange
1000+
g_test_expected := anydata.convertObject( ut3_tester_helper.test_dummy_nested_object(ut3_tester_helper.test_dummy_object(1, 'A', '0'),ut3_tester_helper.test_dummy_object(1, 'B', '0') ));
1001+
g_test_actual := anydata.convertObject( ut3_tester_helper.test_dummy_nested_object(ut3_tester_helper.test_dummy_object(1, 'A', '0'),ut3_tester_helper.test_dummy_object(1, 'C', '0') ));
1002+
--Act
1003+
l_expected_message := q'[%Actual: ut3_develop.some_item was expected to equal: ut3_develop.some_item
1004+
%Diff:
1005+
%Rows: [ 1 differences ]
1006+
%Row No. 1 - Actual: <SEC_NESTED_OBJ><ID>1</ID><name>B</name><Value>0</Value></SEC_NESTED_OBJ>
1007+
%Row No. 1 - Expected: <SEC_NESTED_OBJ><ID>1</ID><name>C</name><Value>0</Value></SEC_NESTED_OBJ>]';
1008+
ut3_develop.ut.expect(g_test_actual).to_equal(g_test_expected);
1009+
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
1010+
--Assert
1011+
ut.expect(l_actual_message).to_be_like(l_expected_message);
1012+
end;
9941013

9951014
end;
9961015
/

test/ut3_user/expectations/test_expectation_anydata.pks

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ create or replace package test_expectation_anydata is
203203

204204
--%test ( Empty Array not equal array with space )
205205
procedure arr_empty_nqua_arr_e_unord;
206+
207+
--%test ( Failure of comparing nesting objects )
208+
procedure failure_nesting_objects;
209+
206210
end;
207211
/

0 commit comments

Comments
 (0)