From 895fc9066afdf3914215965f95f05a33574c3259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20G=C4=99bal?= Date: Thu, 29 Sep 2016 09:58:15 +0100 Subject: [PATCH] Updated submodule to point to master repo for any_data. Added grants for dbms_crypto (required by any_data MD5 calculation). Added is_null and is_not_null assertions. Updated test for any_data to_string outcomes. Updated CONTRIBUTING.md to include instruction for submodule update. --- .gitmodules | 2 +- .travis/create_utplsql_user.sql | 2 + CONTRIBUTING.md | 1 + lib/any_data | 2 +- source/ut_assert.pkb | 111 ++++++++++++++++++ source/ut_assert.pks | 30 +++++ tests/RunAll.sql | 9 ++ .../common/ut_assert.null.scalar.common.sql | 16 +++ ...l.anydata.PutsObjectStrucureIntoAssert.sql | 7 +- ...not_null.date.GivesFailureForNullValue.sql | 3 + ..._null.date.GivesSuccessForNotNullValue.sql | 3 + ....anydata.GivesFailureWhenDataIsNotNull.sql | 25 ++++ ...ull.anydata.GivesSuccessWhenDataIsNull.sql | 25 ++++ ..._null.date.GivesFailureForNotNullValue.sql | 3 + ....is_null.date.GivesSuccessForNullValue.sql | 3 + 15 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 tests/ut_assert/common/ut_assert.null.scalar.common.sql create mode 100644 tests/ut_assert/ut_assert.is_not_null.date.GivesFailureForNullValue.sql create mode 100644 tests/ut_assert/ut_assert.is_not_null.date.GivesSuccessForNotNullValue.sql create mode 100644 tests/ut_assert/ut_assert.is_null.anydata.GivesFailureWhenDataIsNotNull.sql create mode 100644 tests/ut_assert/ut_assert.is_null.anydata.GivesSuccessWhenDataIsNull.sql create mode 100644 tests/ut_assert/ut_assert.is_null.date.GivesFailureForNotNullValue.sql create mode 100644 tests/ut_assert/ut_assert.is_null.date.GivesSuccessForNullValue.sql diff --git a/.gitmodules b/.gitmodules index 0920fff86..5da42bbad 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "any_data"] path = lib/any_data url = https://github.com/jgebal/any_data.git - branch = 1.0.4 + branch = master diff --git a/.travis/create_utplsql_user.sql b/.travis/create_utplsql_user.sql index 6671dd621..4895f73d5 100644 --- a/.travis/create_utplsql_user.sql +++ b/.travis/create_utplsql_user.sql @@ -13,4 +13,6 @@ create user &ut3_user identified by &ut3_password default tablespace &ut3_tables grant create session, create procedure, create type, create table to &ut3_user; +grant execute on sys.dbms_crypto to &ut3_user; + exit success diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a8466d635..51ef6e8bb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,7 @@ Changes are welcome from all members of the Community. * Each of the steps below are detailed in the [How to Fork](https://help.github.com/articles/fork-a-repo) article! * Clone your Fork to your local machine. * Configure "upstream" remote to the [master utPLSQL repository](https://github.com/utPLSQL/utPLSQL.git). + * Update the git submodules by issuing command: [git submodule update --remote --merge](http://stackoverflow.com/a/21195182) 3. For each change you want to make: * Create a new branch for your change. * Make your change in your new branch. diff --git a/lib/any_data b/lib/any_data index 9bb40cbc8..01841079e 160000 --- a/lib/any_data +++ b/lib/any_data @@ -1 +1 @@ -Subproject commit 9bb40cbc8f818f838d19be4fc4c618d61a1f62e9 +Subproject commit 01841079e1bfa0cecc6b5f3c0b2cbc9e2a322da6 diff --git a/source/ut_assert.pkb b/source/ut_assert.pkb index 61db12e49..8bc3386f0 100644 --- a/source/ut_assert.pkb +++ b/source/ut_assert.pkb @@ -146,5 +146,116 @@ create or replace package body ut_assert is build_assert_result(a_condition, 'this', 'boolean', 'boolean', ut_utils.to_string(true), ut_utils.to_string(a_condition), ut_utils.to_string(a_msg)); end; + procedure is_null(a_actual in number) is + begin + is_null(null, a_actual); + end; + + procedure is_null(a_msg in varchar2, a_actual in number) is + begin + build_assert_result((a_actual is null), 'is_null', 'number', 'number', 'NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + procedure is_null(a_actual in varchar2) is + begin + is_null(null, a_actual); + end; + + procedure is_null(a_msg in varchar2, a_actual in varchar2) is + begin + build_assert_result((a_actual is null), 'is_null', 'varchar2', 'varchar2', 'NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + + procedure is_null(a_actual in date) is + begin + is_null(null, a_actual); + end; + + + procedure is_null(a_msg in varchar2, a_actual in date) is + begin + build_assert_result((a_actual is null), 'is_null', 'date', 'date', 'NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + + procedure is_null(a_actual in timestamp_unconstrained) is + begin + is_null(null, a_actual); + end; + + + procedure is_null(a_msg in varchar2, a_actual in timestamp_unconstrained) is + begin + build_assert_result((a_actual is null), 'is_null', 'timestamp', 'timestamp', 'NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + + procedure is_null(a_actual in anydata) is + begin + is_null(null, a_actual); + end; + + + procedure is_null(a_msg in varchar2, a_actual in anydata) is + l_actual any_data; + begin + l_actual := any_data_builder.build(a_actual); + build_assert_result( l_actual.is_null(), 'is_null', l_actual.type_name, l_actual.type_name, 'NULL', ut_utils.to_string(l_actual.to_string()), ut_utils.to_string(a_msg)); + end; + + procedure is_not_null(a_actual in number) is + begin + is_not_null(null, a_actual); + end; + + procedure is_not_null(a_msg in varchar2, a_actual in number) is + begin + build_assert_result((a_actual is not null), 'is_not_null', 'number', 'number', 'NOT NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + procedure is_not_null(a_actual in varchar2) is + begin + is_not_null(null, a_actual); + end; + + procedure is_not_null(a_msg in varchar2, a_actual in varchar2) is + begin + build_assert_result((a_actual is not null), 'is_not_null', 'varchar2', 'varchar2', 'NOT NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + procedure is_not_null(a_actual in date) is + begin + is_not_null(null, a_actual); + end; + + procedure is_not_null(a_msg in varchar2, a_actual in date) is + begin + build_assert_result((a_actual is not null), 'is_not_null', 'date', 'date', 'NOT NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + procedure is_not_null(a_actual in timestamp_unconstrained) is + begin + is_not_null(null, a_actual); + end; + + procedure is_not_null(a_msg in varchar2, a_actual in timestamp_unconstrained) is + begin + build_assert_result((a_actual is not null), 'is_not_null', 'timestamp', 'timestamp', 'NOT NULL', ut_utils.to_string(a_actual), ut_utils.to_string(a_msg)); + end; + + procedure is_not_null(a_actual in anydata) is + begin + is_not_null(null, a_actual); + end; + + procedure is_not_null(a_msg in varchar2, a_actual in anydata) is + l_actual any_data; + begin + l_actual := any_data_builder.build(a_actual); + build_assert_result( not l_actual.is_null(), 'is_not_null', l_actual.type_name, l_actual.type_name, 'NOT NULL', ut_utils.to_string(l_actual.to_string()), ut_utils.to_string(a_msg)); + end; + + end ut_assert; / diff --git a/source/ut_assert.pks b/source/ut_assert.pks index d89eaabcc..9ab2cda18 100644 --- a/source/ut_assert.pks +++ b/source/ut_assert.pks @@ -27,5 +27,35 @@ create or replace package ut_assert authid current_user as procedure this(a_condition in boolean); procedure this(a_msg in varchar2, a_condition in boolean); + procedure is_null(a_actual in number); + procedure is_null(a_msg in varchar2, a_actual in number); + + procedure is_null(a_actual in varchar2); + procedure is_null(a_msg in varchar2, a_actual in varchar2); + + procedure is_null(a_actual in date); + procedure is_null(a_msg in varchar2, a_actual in date); + + procedure is_null(a_actual in timestamp_unconstrained); + procedure is_null(a_msg in varchar2, a_actual in timestamp_unconstrained); + + procedure is_null(a_actual in anydata); + procedure is_null(a_msg in varchar2, a_actual in anydata); + + procedure is_not_null(a_actual in number); + procedure is_not_null(a_msg in varchar2, a_actual in number); + + procedure is_not_null(a_actual in varchar2); + procedure is_not_null(a_msg in varchar2, a_actual in varchar2); + + procedure is_not_null(a_actual in date); + procedure is_not_null(a_msg in varchar2, a_actual in date); + + procedure is_not_null(a_actual in timestamp_unconstrained); + procedure is_not_null(a_msg in varchar2, a_actual in timestamp_unconstrained); + + procedure is_not_null(a_actual in anydata); + procedure is_not_null(a_msg in varchar2, a_actual in anydata); + end ut_assert; / diff --git a/tests/RunAll.sql b/tests/RunAll.sql index 5fa6aa547..12c6f53b0 100644 --- a/tests/RunAll.sql +++ b/tests/RunAll.sql @@ -71,6 +71,15 @@ set serveroutput on size unlimited format truncated @@lib/RunTest.sql ut_assert/ut_assert.are_equal.scalar.FailsToExecuteWhenNullsPassedAsParameters.sql +@@lib/RunTest.sql ut_assert/ut_assert.is_not_null.date.GivesFailureForNullValue.sql +@@lib/RunTest.sql ut_assert/ut_assert.is_not_null.date.GivesSuccessForNotNullValue.sql + +@@lib/RunTest.sql ut_assert/ut_assert.is_null.anydata.GivesFailureWhenDataIsNotNull.sql +@@lib/RunTest.sql ut_assert/ut_assert.is_null.anydata.GivesSuccessWhenDataIsNull.sql + +@@lib/RunTest.sql ut_assert/ut_assert.is_null.date.GivesFailureForNotNullValue.sql +@@lib/RunTest.sql ut_assert/ut_assert.is_null.date.GivesSuccessForNullValue.sql + @@lib/RunTest.sql ut_utils/ut_utils.to_string.verySmallNumber.sql @@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigNumber.sql @@lib/RunTest.sql ut_utils/ut_utils.to_string.Date.sql diff --git a/tests/ut_assert/common/ut_assert.null.scalar.common.sql b/tests/ut_assert/common/ut_assert.null.scalar.common.sql new file mode 100644 index 000000000..8e1c0722e --- /dev/null +++ b/tests/ut_assert/common/ut_assert.null.scalar.common.sql @@ -0,0 +1,16 @@ +--Arrange +declare + l_actual &&1 := &&2; + l_result integer; +begin +--Act + ut_assert.&&3(l_actual); + l_result := ut_assert.get_aggregate_asserts_result(); +--Assert + if l_result = &&4 then + :test_result := ut_utils.tr_success; + else + dbms_output.put_line('expected: '''||&&4||''', got: '''||l_result||'''' ); + end if; +end; +/ diff --git a/tests/ut_assert/ut_assert.are_equal.anydata.PutsObjectStrucureIntoAssert.sql b/tests/ut_assert/ut_assert.are_equal.anydata.PutsObjectStrucureIntoAssert.sql index d37a4f12b..91e6d768c 100644 --- a/tests/ut_assert/ut_assert.are_equal.anydata.PutsObjectStrucureIntoAssert.sql +++ b/tests/ut_assert/ut_assert.are_equal.anydata.PutsObjectStrucureIntoAssert.sql @@ -17,12 +17,13 @@ begin l_assert_result := treat(ut_assert.get_asserts_results()(1) as ut_assert_result); --Assert - if l_assert_result.expected_value_string like q'[%department(%dept_name => 'HR'%)%]' - and l_assert_result.actual_value_string like q'[%department(%dept_name => 'IT'%)%]' + if l_assert_result.expected_value_string like q'[%DEPARTMENT(%dept_name => 'HR'%)%]' + and l_assert_result.actual_value_string like q'[%DEPARTMENT(%dept_name => 'IT'%)%]' then :test_result := ut_utils.tr_success; else - dbms_output.put_line( 'assert_result.message does not contain the objects' ); + dbms_output.put_line( l_assert_result.expected_value_string ); + dbms_output.put_line( l_assert_result.actual_value_string ); end if; end; / diff --git a/tests/ut_assert/ut_assert.is_not_null.date.GivesFailureForNullValue.sql b/tests/ut_assert/ut_assert.is_not_null.date.GivesFailureForNullValue.sql new file mode 100644 index 000000000..525eea9ef --- /dev/null +++ b/tests/ut_assert/ut_assert.is_not_null.date.GivesFailureForNullValue.sql @@ -0,0 +1,3 @@ +PROMPT Gives a failure when date value is null + +@@ut_assert/common/ut_assert.null.scalar.common.sql 'date' 'null' 'is_not_null' 'ut_utils.tr_failure' diff --git a/tests/ut_assert/ut_assert.is_not_null.date.GivesSuccessForNotNullValue.sql b/tests/ut_assert/ut_assert.is_not_null.date.GivesSuccessForNotNullValue.sql new file mode 100644 index 000000000..040fb1c46 --- /dev/null +++ b/tests/ut_assert/ut_assert.is_not_null.date.GivesSuccessForNotNullValue.sql @@ -0,0 +1,3 @@ +PROMPT Gives a success when date value is not null + +@@ut_assert/common/ut_assert.null.scalar.common.sql 'date' 'sysdate' 'is_not_null' 'ut_utils.tr_success' diff --git a/tests/ut_assert/ut_assert.is_null.anydata.GivesFailureWhenDataIsNotNull.sql b/tests/ut_assert/ut_assert.is_null.anydata.GivesFailureWhenDataIsNotNull.sql new file mode 100644 index 000000000..8004e96a0 --- /dev/null +++ b/tests/ut_assert/ut_assert.is_null.anydata.GivesFailureWhenDataIsNotNull.sql @@ -0,0 +1,25 @@ +PROMPT Gives a falure when oracle object is not null +--Arrange +create or replace type department as object( + dept_name varchar2(30) +); +/ + +declare + l_actual department := department('IT'); + l_result integer; +begin +--Act + ut_assert.is_null( anydata.convertObject(l_actual) ); + l_result := ut_assert.get_aggregate_asserts_result(); +--Assert + if l_result = ut_utils.tr_failure then + :test_result := ut_utils.tr_success; + else + dbms_output.put_line('expected: '''||ut_utils.tr_failure||''', got: '''||l_result||'''' ); + end if; +end; +/ + +--Cleanup +drop type department; diff --git a/tests/ut_assert/ut_assert.is_null.anydata.GivesSuccessWhenDataIsNull.sql b/tests/ut_assert/ut_assert.is_null.anydata.GivesSuccessWhenDataIsNull.sql new file mode 100644 index 000000000..105db2ff4 --- /dev/null +++ b/tests/ut_assert/ut_assert.is_null.anydata.GivesSuccessWhenDataIsNull.sql @@ -0,0 +1,25 @@ +PROMPT Gives a success when oracle object is null +--Arrange +create or replace type department as object( + dept_name varchar2(30) +); +/ + +declare + l_actual department; + l_result integer; +begin +--Act + ut_assert.is_null( anydata.convertObject(l_actual) ); + l_result := ut_assert.get_aggregate_asserts_result(); +--Assert + if l_result = ut_utils.tr_success then + :test_result := ut_utils.tr_success; + else + dbms_output.put_line('expected: '''||ut_utils.tr_success||''', got: '''||l_result||'''' ); + end if; +end; +/ + +--Cleanup +drop type department; diff --git a/tests/ut_assert/ut_assert.is_null.date.GivesFailureForNotNullValue.sql b/tests/ut_assert/ut_assert.is_null.date.GivesFailureForNotNullValue.sql new file mode 100644 index 000000000..d0b85f891 --- /dev/null +++ b/tests/ut_assert/ut_assert.is_null.date.GivesFailureForNotNullValue.sql @@ -0,0 +1,3 @@ +PROMPT Gives a failure when date value is not null + +@@ut_assert/common/ut_assert.null.scalar.common.sql 'date' 'sysdate' 'is_null' 'ut_utils.tr_failure' diff --git a/tests/ut_assert/ut_assert.is_null.date.GivesSuccessForNullValue.sql b/tests/ut_assert/ut_assert.is_null.date.GivesSuccessForNullValue.sql new file mode 100644 index 000000000..7b84ade6a --- /dev/null +++ b/tests/ut_assert/ut_assert.is_null.date.GivesSuccessForNullValue.sql @@ -0,0 +1,3 @@ +PROMPT Gives a success when date value is null + +@@ut_assert/common/ut_assert.null.scalar.common.sql 'date' 'null' 'is_null' 'ut_utils.tr_success'