Skip to content

Commit 6a4dc99

Browse files
author
Pablo Roldán Ruíz
committed
This commit fixes issue utPLSQL#175 (be_empty matcher)
1 parent 2011354 commit 6a4dc99

16 files changed

Lines changed: 163 additions & 4 deletions

docs/userguide/expectations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Matcher is defining the comparison operation to be performed on expected and act
2727
- `be_greater_or_equal`
2828
- `be_false`
2929
- `be_between`
30+
- `be_empty`
3031

3132
## match
3233
Allows regexp_like validations to be executed against the following datatypes:

source/api/be_emtpy.syn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create synonym be_empty for ut_be_empty;

source/create_synonyms_and_grants_for_public.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ alter session set current_schema = &&ut3_owner;
2828
prompt Granting privileges on UTPLSQL objects in &&ut3_owner schema to PUBLIC
2929

3030
grant execute on ut_be_between to public;
31+
grant execute on ut_be_empty to public;
3132
grant execute on ut_be_false to public;
3233
grant execute on ut_be_greater_or_equal to public;
3334
grant execute on ut_be_greater_than to public;
@@ -51,6 +52,7 @@ grant execute on ut_reporter_base to public;
5152
prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to PUBLIC
5253

5354
create public synonym be_between for ut_be_between;
55+
create public synonym be_empty for ut_be_empty;
5456
create public synonym be_false for ut_be_false;
5557
create public synonym be_greater_or_equal for ut_be_greater_or_equal;
5658
create public synonym be_greater_than for ut_be_greater_than;

source/create_synonyms_and_grants_for_user.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ prompt Granting privileges on UTPLSQL objects in &&ut3_owner schema to user &&ut
2929
alter session set current_schema = &&ut3_owner;
3030

3131
grant execute on ut_be_between to &ut3_user;
32+
grant execute on ut_be_empty to &ut3_user;
3233
grant execute on ut_be_false to &ut3_user;
3334
grant execute on ut_be_greater_or_equal to &ut3_user;
3435
grant execute on ut_be_greater_than to &ut3_user;
@@ -52,6 +53,7 @@ grant execute on ut_reporter_base to &ut3_user;
5253
prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to user &&ut3_user
5354

5455
create or replace synonym &ut3_user .be_between for be_between;
56+
create or replace synonym &ut3_user .be_empty for be_empty;
5557
create or replace synonym &ut3_user .be_false for be_false;
5658
create or replace synonym &ut3_user .be_greater_or_equal for be_greater_or_equal;
5759
create or replace synonym &ut3_user .be_greater_than for be_greater_than;

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ create or replace type body ut_data_value_refcursor as
5353
end if;
5454
return ut_utils.to_string(l_result);
5555
end;
56-
56+
57+
member function is_empty return boolean is
58+
l_is_empty boolean := FALSE;
59+
l_result CLOB;
60+
begin
61+
if self.data_value is not null then
62+
ut_assert_processor.set_xml_nls_params();
63+
dbms_xmlgen.restartQuery(self.data_value);
64+
dbms_xmlgen.setMaxRows(self.data_value, 100);
65+
l_result := dbms_xmlgen.getxml(self.data_value);
66+
67+
if l_result is null then
68+
l_is_empty := true;
69+
end if;
70+
71+
ut_assert_processor.reset_nls_params();
72+
end if;
73+
return l_is_empty;
74+
end;
5775
end;
5876
/

source/expectations/data_values/ut_data_value_refcursor.tps

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ create or replace type ut_data_value_refcursor under ut_data_value(
4545

4646
overriding member function is_null return boolean,
4747

48-
overriding member function to_string return varchar2
48+
overriding member function to_string return varchar2,
49+
50+
member function is_empty return boolean
4951
)
5052
/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
create or replace type body ut_be_empty as
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
member procedure init(self in out nocopy ut_be_empty) is
20+
begin
21+
self.name := 'be_empty';
22+
end;
23+
24+
constructor function ut_be_empty(self in out nocopy ut_be_empty) return self as result is
25+
begin
26+
init();
27+
return;
28+
end;
29+
30+
overriding member function run_matcher(self in out nocopy ut_be_empty, a_actual ut_data_value) return boolean is
31+
l_result boolean;
32+
begin
33+
if a_actual is of (ut_data_value_refcursor) then
34+
declare
35+
l_actual ut_data_value_refcursor := treat(a_actual as ut_data_value_refcursor);
36+
begin
37+
if l_actual.data_value is not null then
38+
l_result := l_actual.is_empty;
39+
else
40+
l_result := false;
41+
end if;
42+
end;
43+
else
44+
l_result := (self as ut_matcher).run_matcher(a_actual);
45+
end if;
46+
return l_result;
47+
end;
48+
49+
end;
50+
/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
create or replace type ut_be_empty under ut_matcher(
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
member procedure init(self in out nocopy ut_be_empty),
19+
constructor function ut_be_empty(self in out nocopy ut_be_empty) return self as result,
20+
overriding member function run_matcher(self in out nocopy ut_be_empty, a_actual ut_data_value) return boolean
21+
)
22+
/

source/expectations/ut_expectation_refcursor.tpb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ create or replace type body ut_expectation_refcursor as
2020
ut_utils.debug_log('ut_expectation_refcursor.to_equal(self in ut_expectation_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)');
2121
self.to_( ut_equal(a_expected, a_nulls_are_equal) );
2222
end;
23-
23+
24+
member procedure to_be_empty(self in ut_expectation_refcursor) is
25+
begin
26+
ut_utils.debug_log('ut_expectation_refcursor.to_be_empty(self in ut_expectation_refcursor)');
27+
self.to_( ut_be_empty() );
28+
end;
2429
end;
2530
/

source/expectations/ut_expectation_refcursor.tps

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ create or replace type ut_expectation_refcursor under ut_expectation(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
overriding member procedure to_equal(self in ut_expectation_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)
18+
overriding member procedure to_equal(self in ut_expectation_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null),
19+
member procedure to_be_empty(self in ut_expectation_refcursor)
1920
)
2021
/

0 commit comments

Comments
 (0)