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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/userguide/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Matcher is defining the comparison operation to be performed on expected and act
- `be_greater_or_equal`
- `be_false`
- `be_between`
- `be_empty`

## match
Allows regexp_like validations to be executed against the following datatypes:
Expand Down
1 change: 1 addition & 0 deletions source/api/be_empty.syn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create synonym be_empty for ut_be_empty;
2 changes: 2 additions & 0 deletions source/create_synonyms_and_grants_for_public.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ alter session set current_schema = &&ut3_owner;
prompt Granting privileges on UTPLSQL objects in &&ut3_owner schema to PUBLIC

grant execute on ut_be_between to public;
grant execute on ut_be_empty to public;
grant execute on ut_be_false to public;
grant execute on ut_be_greater_or_equal to public;
grant execute on ut_be_greater_than to public;
Expand All @@ -51,6 +52,7 @@ grant execute on ut_reporter_base to public;
prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to PUBLIC

create public synonym be_between for ut_be_between;
create public synonym be_empty for ut_be_empty;
create public synonym be_false for ut_be_false;
create public synonym be_greater_or_equal for ut_be_greater_or_equal;
create public synonym be_greater_than for ut_be_greater_than;
Expand Down
2 changes: 2 additions & 0 deletions source/create_synonyms_and_grants_for_user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ prompt Granting privileges on UTPLSQL objects in &&ut3_owner schema to user &&ut
alter session set current_schema = &&ut3_owner;

grant execute on ut_be_between to &ut3_user;
grant execute on ut_be_empty to &ut3_user;
grant execute on ut_be_false to &ut3_user;
grant execute on ut_be_greater_or_equal to &ut3_user;
grant execute on ut_be_greater_than to &ut3_user;
Expand All @@ -52,6 +53,7 @@ grant execute on ut_reporter_base to &ut3_user;
prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to user &&ut3_user

create or replace synonym &ut3_user .be_between for be_between;
create or replace synonym &ut3_user .be_empty for be_empty;
create or replace synonym &ut3_user .be_false for be_false;
create or replace synonym &ut3_user .be_greater_or_equal for be_greater_or_equal;
create or replace synonym &ut3_user .be_greater_than for be_greater_than;
Expand Down
20 changes: 19 additions & 1 deletion source/expectations/data_values/ut_data_value_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ create or replace type body ut_data_value_refcursor as
end if;
return ut_utils.to_string(l_result);
end;


member function is_empty return boolean is
l_is_empty boolean := FALSE;
l_result CLOB;
begin
if self.data_value is not null then
ut_assert_processor.set_xml_nls_params();
dbms_xmlgen.restartQuery(self.data_value);
dbms_xmlgen.setMaxRows(self.data_value, 1);
l_result := dbms_xmlgen.getxml(self.data_value);

if l_result is null then
l_is_empty := true;
end if;

ut_assert_processor.reset_nls_params();
end if;
return l_is_empty;
end;
end;
/
4 changes: 3 additions & 1 deletion source/expectations/data_values/ut_data_value_refcursor.tps
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ create or replace type ut_data_value_refcursor under ut_data_value(

overriding member function is_null return boolean,

overriding member function to_string return varchar2
overriding member function to_string return varchar2,

member function is_empty return boolean
)
/
73 changes: 73 additions & 0 deletions source/expectations/matchers/ut_be_empty.tpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
create or replace type body ut_be_empty as
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

member procedure init(self in out nocopy ut_be_empty) is
begin
self.name := 'be_empty';
end;

constructor function ut_be_empty(self in out nocopy ut_be_empty) return self as result is
begin
init();
return;
end;

overriding member function run_matcher(self in out nocopy ut_be_empty, a_actual ut_data_value) return boolean is
l_result boolean;
begin
if a_actual is of(ut_data_value_refcursor) then
declare
l_actual ut_data_value_refcursor := treat(a_actual as ut_data_value_refcursor);
begin
if l_actual.data_value is not null then
l_result := l_actual.is_empty;
else
l_result := false;
end if;
end;
elsif a_actual is of(ut_data_value_anydata) then
declare
l_actual ut_data_value_anydata := treat(a_actual as ut_data_value_anydata);
l_type_name varchar2(61);
l_type anytype;
begin
if l_actual.data_value.gettype(l_type) in
(dbms_types.typecode_varray, dbms_types.typecode_table, dbms_types.typecode_namedcollection) then
if a_actual.is_null() then
l_result := false;
else
ut_assert_processor.set_xml_nls_params();
l_type_name := l_actual.data_value.gettypename();
l_type_name := substr(l_type_name, instr(l_type_name, '.') + 1);
l_result := xmltype(l_actual.data_value).getclobval() = '<' || l_type_name || '/>';
ut_assert_processor.reset_nls_params();
end if;
else
ut_utils.debug_log('Failure - ut_be_empty.run_matcher can only be used with collections and cursors');
self.error_message := 'The matcher can only be used with collections and cursors';
l_result := null;
end if;
end;
else
l_result := (self as ut_matcher).run_matcher(a_actual);
end if;
return l_result;
end;

end;
/
22 changes: 22 additions & 0 deletions source/expectations/matchers/ut_be_empty.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
create or replace type ut_be_empty under ut_matcher(
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
member procedure init(self in out nocopy ut_be_empty),
constructor function ut_be_empty(self in out nocopy ut_be_empty) return self as result,
overriding member function run_matcher(self in out nocopy ut_be_empty, a_actual ut_data_value) return boolean
)
/
6 changes: 6 additions & 0 deletions source/expectations/ut_expectation_anydata.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ create or replace type body ut_expectation_anydata as
ut_utils.debug_log('ut_expectation_anydata.to_equal(self in ut_expectation_anydata, a_expected anydata, a_nulls_are_equal boolean := null)');
self.to_( ut_equal(a_expected, a_nulls_are_equal) );
end;

member procedure to_be_empty(self in ut_expectation_anydata) is
begin
ut_utils.debug_log('ut_expectation_anydata.to_be_empty(self in ut_expectation_anydata)');
self.to_( ut_be_empty() );
end;

end;
/
3 changes: 2 additions & 1 deletion source/expectations/ut_expectation_anydata.tps
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ create or replace type ut_expectation_anydata under ut_expectation(
See the License for the specific language governing permissions and
limitations under the License.
*/
overriding member procedure to_equal(self in ut_expectation_anydata, a_expected anydata, a_nulls_are_equal boolean := null)
overriding member procedure to_equal(self in ut_expectation_anydata, a_expected anydata, a_nulls_are_equal boolean := null),
member procedure to_be_empty(self in ut_expectation_anydata)
)
/
7 changes: 6 additions & 1 deletion source/expectations/ut_expectation_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ create or replace type body ut_expectation_refcursor as
ut_utils.debug_log('ut_expectation_refcursor.to_equal(self in ut_expectation_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)');
self.to_( ut_equal(a_expected, a_nulls_are_equal) );
end;


member procedure to_be_empty(self in ut_expectation_refcursor) is
begin
ut_utils.debug_log('ut_expectation_refcursor.to_be_empty(self in ut_expectation_refcursor)');
self.to_( ut_be_empty() );
end;
end;
/
3 changes: 2 additions & 1 deletion source/expectations/ut_expectation_refcursor.tps
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ create or replace type ut_expectation_refcursor under ut_expectation(
See the License for the specific language governing permissions and
limitations under the License.
*/
overriding member procedure to_equal(self in ut_expectation_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)
overriding member procedure to_equal(self in ut_expectation_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null),
member procedure to_be_empty(self in ut_expectation_refcursor)
)
/
3 changes: 3 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ whenever oserror exit failure rollback
@@expectations/matchers/ut_be_true.tps
@@expectations/matchers/ut_equal.tps
@@expectations/matchers/ut_be_between.tps
@@expectations/matchers/ut_be_empty.tps
@@expectations/matchers/ut_match.tps
@@expectations/ut_expectation.tps
@@expectations/ut_expectation_anydata.tps
Expand Down Expand Up @@ -158,6 +159,7 @@ whenever oserror exit failure rollback
@@expectations/matchers/ut_be_true.tpb
@@expectations/matchers/ut_equal.tpb
@@expectations/matchers/ut_be_between.tpb
@@expectations/matchers/ut_be_empty.tpb
@@expectations/matchers/ut_match.tpb
@@expectations/ut_expectation.tpb
@@expectations/ut_expectation_anydata.tpb
Expand Down Expand Up @@ -195,6 +197,7 @@ whenever oserror exit failure rollback
@@reporters/ut_xunit_reporter.tpb

@@api/be_between.syn
@@api/be_empty.syn
@@api/be_false.syn
@@api/be_greater_or_equal.syn
@@api/be_greater_than.syn
Expand Down
4 changes: 4 additions & 0 deletions source/uninstall.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ drop synonym match;

drop synonym be_false;

drop synonym be_empty;

drop synonym be_greater_or_equal;

drop synonym be_greater_than;
Expand Down Expand Up @@ -103,6 +105,8 @@ drop type ut_be_like;

drop type ut_be_greater_or_equal;

drop type ut_be_empty;

drop type ut_be_greater_than;

drop type ut_be_less_or_equal;
Expand Down
3 changes: 3 additions & 0 deletions tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ create table ut$test_table (val varchar2(1));
@@ut_matchers/greater_than.sql
@@ut_matchers/less_or_equal.sql
@@ut_matchers/less_than.sql
@@ut_matchers/be_empty.sql

@@lib/RunTest.sql ut_matchers/timestamp_between.sql
@@lib/RunTest.sql ut_matchers/timestamp_ltz_between.sql
@@lib/RunTest.sql ut_matchers/timestamp_ltz_not_between.sql
Expand Down Expand Up @@ -172,6 +174,7 @@ create table ut$test_table (val varchar2(1));
@@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigVarchar2.sql
@@lib/RunTest.sql ut_utils/ut_utils.to_string.verySmallNumber.sql


--Global cleanup
drop package ut_example_tests;
drop procedure check_annotation_parsing;
Expand Down
14 changes: 14 additions & 0 deletions tests/ut_matchers/be_empty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.refcursor.be_empty.sql 'select * from dual where 1 = 1' 'ut_utils.tr_failure'"
@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.refcursor.be_empty.sql 'select * from dual where 1 <> 1' 'ut_utils.tr_success'"

@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.refcursor.not_to_be_empty.sql 'select * from dual where 1 = 1' 'ut_utils.tr_success'"
@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.refcursor.not_to_be_empty.sql 'select * from dual where 1 <> 1' 'ut_utils.tr_failure'"

@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.collection.be_empty.sql 'ora_mining_varchar2_nt' 'ora_mining_varchar2_nt()' 'ut_utils.tr_success'"
@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.collection.be_empty.sql 'ora_mining_varchar2_nt' 'ora_mining_varchar2_nt(''a'')' 'ut_utils.tr_failure'"

@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.collection.not_be_empty.sql 'ora_mining_varchar2_nt' 'ora_mining_varchar2_nt()' 'ut_utils.tr_failure'"
@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.collection.not_be_empty.sql 'ora_mining_varchar2_nt' 'ora_mining_varchar2_nt(''a'')' 'ut_utils.tr_success'"

@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.other.be_empty.sql 'ut_data_value_number' 'ut_data_value_number(1)' 'ConvertObject' 'ut_utils.tr_failure'"
@@lib/RunTest.sql "ut_matchers/common/ut.expect.common.other.not_be_empty.sql 'ut_data_value_varchar2' 'NULL' 'ConvertObject' 'ut_utils.tr_failure'"
20 changes: 20 additions & 0 deletions tests/ut_matchers/common/ut.expect.common.collection.be_empty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--Arrange
declare
l_var &&1;
l_result integer;
l_asserts_results ut_assert_results;
begin
--Act
l_var := &&2;
ut.expect(anydata.convertcollection(l_var)).to_(be_empty());
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = &&3 then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||&&3||''', got: '''||l_result||'''' );
end if;
end;
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--Arrange
declare
l_var &&1;
l_result integer;
l_asserts_results ut_assert_results;
begin
--Act
l_var := &&2;
ut.expect(anydata.convertcollection(l_var)).not_to(be_empty());
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = &&3 then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||&&3||''', got: '''||l_result||'''' );
end if;
end;
/
20 changes: 20 additions & 0 deletions tests/ut_matchers/common/ut.expect.common.other.be_empty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--Arrange
declare
l_var &&1;
l_result integer;
l_asserts_results ut_assert_results;
begin
--Act
l_var := &&2;
ut.expect(anydata.&&3(l_var)).to_(be_empty());
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = &&4 then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||&&4||''', got: '''||l_result||'''' );
end if;
end;
/
20 changes: 20 additions & 0 deletions tests/ut_matchers/common/ut.expect.common.other.not_be_empty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--Arrange
declare
l_var &&1;
l_result integer;
l_asserts_results ut_assert_results;
begin
--Act
l_var := &&2;
ut.expect(anydata.&&3(l_var)).not_to(be_empty());
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = &&4 then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||&&4||''', got: '''||l_result||'''' );
end if;
end;
/
20 changes: 20 additions & 0 deletions tests/ut_matchers/common/ut.expect.common.refcursor.be_empty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--Arrange
declare
l_cursor sys_refcursor;
l_result integer;
l_asserts_results ut_assert_results;
begin
--Act
open l_cursor for &&1;
ut.expect(l_cursor).to_be_empty();
l_asserts_results := ut_assert_processor.get_asserts_results();
l_result := l_asserts_results(l_asserts_results.last).result;
--Assert
if l_result = &&2 then
:test_result := ut_utils.tr_success;
else
:test_result := ut_utils.tr_failure;
dbms_output.put_line('expected: '''||&&2||''', got: '''||l_result||'''' );
end if;
end;
/
Loading