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

Skip to content

Commit ca9dadc

Browse files
authored
Merge pull request #201 from proldan/develop
This commit fixes issue #175 (be_empty matcher)
2 parents 2011354 + 9000d46 commit ca9dadc

22 files changed

Lines changed: 283 additions & 5 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_empty.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, 1);
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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
elsif a_actual is of(ut_data_value_anydata) then
44+
declare
45+
l_actual ut_data_value_anydata := treat(a_actual as ut_data_value_anydata);
46+
l_type_name varchar2(61);
47+
l_type anytype;
48+
begin
49+
if l_actual.data_value.gettype(l_type) in
50+
(dbms_types.typecode_varray, dbms_types.typecode_table, dbms_types.typecode_namedcollection) then
51+
if a_actual.is_null() then
52+
l_result := false;
53+
else
54+
ut_assert_processor.set_xml_nls_params();
55+
l_type_name := l_actual.data_value.gettypename();
56+
l_type_name := substr(l_type_name, instr(l_type_name, '.') + 1);
57+
l_result := xmltype(l_actual.data_value).getclobval() = '<' || l_type_name || '/>';
58+
ut_assert_processor.reset_nls_params();
59+
end if;
60+
else
61+
ut_utils.debug_log('Failure - ut_be_empty.run_matcher can only be used with collections and cursors');
62+
self.error_message := 'The matcher can only be used with collections and cursors';
63+
l_result := null;
64+
end if;
65+
end;
66+
else
67+
l_result := (self as ut_matcher).run_matcher(a_actual);
68+
end if;
69+
return l_result;
70+
end;
71+
72+
end;
73+
/
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_anydata.tpb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ create or replace type body ut_expectation_anydata as
2020
ut_utils.debug_log('ut_expectation_anydata.to_equal(self in ut_expectation_anydata, a_expected anydata, a_nulls_are_equal boolean := null)');
2121
self.to_( ut_equal(a_expected, a_nulls_are_equal) );
2222
end;
23+
24+
member procedure to_be_empty(self in ut_expectation_anydata) is
25+
begin
26+
ut_utils.debug_log('ut_expectation_anydata.to_be_empty(self in ut_expectation_anydata)');
27+
self.to_( ut_be_empty() );
28+
end;
2329

2430
end;
2531
/

source/expectations/ut_expectation_anydata.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_anydata 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_anydata, a_expected anydata, a_nulls_are_equal boolean := null)
18+
overriding member procedure to_equal(self in ut_expectation_anydata, a_expected anydata, a_nulls_are_equal boolean := null),
19+
member procedure to_be_empty(self in ut_expectation_anydata)
1920
)
2021
/

0 commit comments

Comments
 (0)