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

Skip to content

Commit 9bf11e7

Browse files
committed
Added prototype of cursor assertions using XMLtype.
1 parent bae866e commit 9bf11e7

19 files changed

Lines changed: 308 additions & 122 deletions

examples/demo_expectations.pck

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ create or replace package body demo_expectations is
3636
l_actual_timestamp_ltz timestamp with local time zone := sysdate - 1;
3737
l_actual_timestamp_tz timestamp with time zone := sysdate - 1;
3838
l_actual_varchar2 varchar2(100) := 'a different string';
39+
l_actual_cursor sys_refcursor;
40+
l_expected_cursor sys_refcursor;
3941
begin
4042
ut.expect( l_actual_blob ).to_equal( l_expected_blob );
4143
ut.expect( l_actual_boolean ).to_equal( l_expected_boolean );
@@ -60,6 +62,11 @@ create or replace package body demo_expectations is
6062
ut.expect( false ).to_be_true;
6163
ut.expect( false ).to_( be_true );
6264

65+
open l_actual_cursor for select * from user_objects where rownum <100;
66+
open l_expected_cursor for select * from user_objects where rownum <5;
67+
68+
ut.expect(l_actual_cursor).to_equal(l_expected_cursor);
69+
6370
end;
6471

6572
procedure demo_to_equal_failure_types is
@@ -72,6 +79,7 @@ create or replace package body demo_expectations is
7279
l_timestamp_ltz timestamp with local time zone := sysdate;
7380
l_timestamp_tz timestamp with time zone := sysdate;
7481
l_varchar2 varchar2(100) := 'a string';
82+
l_cursor sys_refcursor;
7583
begin
7684
ut.expect( l_blob ).to_equal( l_clob );
7785
ut.expect( l_boolean ).to_equal( l_number );
@@ -96,6 +104,8 @@ create or replace package body demo_expectations is
96104
--ut.expect( l_varchar2 ).to_be_true; -- this will not compile
97105
ut.expect( l_varchar2 ).to_( be_true );
98106

107+
open l_cursor for select * from user_objects where rownum <100;
108+
ut.expect(l_cursor).to_equal(l_varchar2);
99109
end;
100110

101111

@@ -109,6 +119,8 @@ create or replace package body demo_expectations is
109119
l_timestamp_ltz timestamp with local time zone := sysdate;
110120
l_timestamp_tz timestamp with time zone := sysdate;
111121
l_varchar2 varchar2(100) := 'a string';
122+
l_cursor1 sys_refcursor;
123+
l_cursor2 sys_refcursor;
112124
begin
113125
ut.expect( l_blob ).to_equal( l_blob );
114126
ut.expect( l_boolean ).to_equal( l_boolean );
@@ -133,6 +145,9 @@ create or replace package body demo_expectations is
133145
ut.expect( true ).to_be_true;
134146
ut.expect( true ).to_( be_true );
135147

148+
open l_cursor1 for select * from all_objects;
149+
open l_cursor2 for select * from all_objects;
150+
ut.expect(l_cursor1).to_equal(l_cursor2);
136151
end;
137152

138153
end;

source/assertions/ut.pkb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ create or replace package body ut is
4545
return ut_assertion_varchar2(ut_data_value_varchar2(a_actual), a_message);
4646
end;
4747

48+
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_assertion_refcursor is
49+
begin
50+
return ut_assertion_refcursor(ut_data_value_refcursor(a_actual), a_message);
51+
end;
52+
4853
-- function expect(a_actual in anydata, a_message varchar2 := null) return ut_assertion_anydata;
4954
--
50-
-- function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_assertion_cursor;
5155

5256
end ut;
5357
/

source/assertions/ut.pks

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ create or replace package ut authid current_user as
1818

1919
function expect(a_actual in varchar2, a_message varchar2 := null) return ut_assertion_varchar2;
2020

21-
-- function expect(a_message varchar2 := null, a_actual in anydata) return ut_assertion_anydata;
22-
--
23-
-- function expect(a_message varchar2 := null, a_actual in sys_refcursor) return ut_assertion_cursor;
21+
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_assertion_refcursor;
2422

23+
-- function expect(a_actual in anydata, a_message varchar2 := null) return ut_assertion_anydata;
24+
--
2525

2626
end ut;
2727
/

source/assertions/ut_assertion.tpb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ create or replace type body ut_assertion as
4141
self.build_assert_result( false, 'to_equal', ut_utils.to_string(a_expected), 'number');
4242
end;
4343

44+
member procedure to_equal(self in ut_assertion, a_expected sys_refcursor, a_nulls_are_equal boolean := null) is
45+
begin
46+
ut_utils.debug_log('ut_assertion.to_equal(self in ut_assertion, a_expected sys_refcursor, a_nulls_are_equal boolean := null)');
47+
self.build_assert_result( false, 'to_equal', ut_utils.to_string(to_char(null)), 'refcursor');
48+
end;
49+
4450
member procedure to_equal(self in ut_assertion, a_expected timestamp_unconstrained, a_nulls_are_equal boolean := null) is
4551
begin
4652
ut_utils.debug_log('ut_assertion.to_equal(self in ut_assertion, a_expected timestamp_unconstrained, a_nulls_are_equal boolean := null)');
@@ -76,6 +82,7 @@ create or replace type body ut_assertion as
7682
when self.actual_data is of (ut_data_value_clob) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_clob) )
7783
when self.actual_data is of (ut_data_value_date) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_date) )
7884
when self.actual_data is of (ut_data_value_number) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_number) )
85+
when self.actual_data is of (ut_data_value_refcursor) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_refcursor) )
7986
when self.actual_data is of (ut_data_value_timestamp) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_timestamp) )
8087
when self.actual_data is of (ut_data_value_timestamp_tz) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_timestamp_tz) )
8188
when self.actual_data is of (ut_data_value_timestamp_ltz) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_timestamp_ltz) )

source/assertions/ut_assertion.tps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ create or replace type ut_assertion as object
99
member procedure to_equal(self in ut_assertion, a_expected clob, a_nulls_are_equal boolean := null),
1010
member procedure to_equal(self in ut_assertion, a_expected date, a_nulls_are_equal boolean := null),
1111
member procedure to_equal(self in ut_assertion, a_expected number, a_nulls_are_equal boolean := null),
12+
member procedure to_equal(self in ut_assertion, a_expected sys_refcursor, a_nulls_are_equal boolean := null),
1213
member procedure to_equal(self in ut_assertion, a_expected timestamp_unconstrained, a_nulls_are_equal boolean := null),
1314
member procedure to_equal(self in ut_assertion, a_expected timestamp_ltz_unconstrained, a_nulls_are_equal boolean := null),
1415
member procedure to_equal(self in ut_assertion, a_expected timestamp_tz_unconstrained, a_nulls_are_equal boolean := null),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create or replace type body ut_assertion_refcursor as
2+
3+
overriding member procedure to_equal(self in ut_assertion_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null) is
4+
begin
5+
ut_utils.debug_log('ut_assertion_refcursor.to_equal(self in ut_assertion_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)');
6+
self.to_( equal(a_expected, a_nulls_are_equal) );
7+
end;
8+
9+
end;
10+
/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create or replace type ut_assertion_refcursor under ut_assertion
2+
(
3+
overriding member procedure to_equal(self in ut_assertion_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)
4+
)
5+
/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
create or replace type ut_data_value_boolean under ut_data_value(
2-
value number(1,0),
2+
value number(1,0), --holds int representation of boolean
33
constructor function ut_data_value_boolean(self in out nocopy ut_data_value_boolean, a_value boolean) return self as result
44
)
55
/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
create or replace type body ut_data_value_refcursor as
2+
3+
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor) return self as result is
4+
l_crsr sys_refcursor := a_value;
5+
begin
6+
if a_value is not null then
7+
self.value := dbms_sql.to_cursor_number(l_crsr);
8+
end if;
9+
self.init('refcursor', ut_utils.boolean_to_int(a_value is null), null);
10+
return;
11+
end;
12+
13+
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value varchar2) return self as result is
14+
l_crsr sys_refcursor;
15+
begin
16+
if a_value is not null then
17+
open l_crsr for a_value;
18+
self.value := dbms_sql.to_cursor_number(l_crsr);
19+
end if;
20+
self.init('refcursor', ut_utils.boolean_to_int(a_value is null), null);
21+
return;
22+
end;
23+
24+
end;
25+
/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
create or replace type ut_data_value_refcursor under ut_data_value(
2+
/*
3+
class: ut_data_value_refcursor
4+
5+
Holds information about ref cursor to be processed by assertion
6+
*/
7+
8+
9+
/*
10+
var: value
11+
12+
Holds a cursor number obtained by calling dbms_sql.to_cursor_number(sys_refcursor)
13+
*/
14+
value number,
15+
16+
/*
17+
function: ut_data_value_refcursor
18+
19+
constructor function that builds a cursor from a sql_statement that was passed in
20+
*/
21+
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor) return self as result,
22+
23+
/*
24+
function: ut_data_value_refcursor
25+
26+
constructor function that builds a cursor from a sql_statement that was passed in
27+
*/
28+
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value varchar2) return self as result
29+
)
30+
/

0 commit comments

Comments
 (0)