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

Skip to content

Commit b756e71

Browse files
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into allow_multi_before_after_procedures
2 parents 5e5fea4 + b691505 commit b756e71

44 files changed

Lines changed: 2603 additions & 250 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ env:
4646
- DOCKHER_HUB_REPO="${DOCKER_BASE_TAG:-$UT3_DOCKER_REPO}"
4747
#utPLSQL released version directory
4848
- UTPLSQL_DIR="utPLSQL_latest_release"
49-
- SELFTESTING_BRANCH="develop"
49+
- SELFTESTING_BRANCH=${TRAVIS_BRANCH}
5050
- UTPLSQL_CLI_VERSION="3.1.0"
5151
# Maven
5252
- MAVEN_HOME=/usr/local/maven
@@ -97,6 +97,7 @@ before_script:
9797

9898
script:
9999
- if [[ ! $TRAVIS_TAG ]]; then bash test/install_and_run_tests.sh; fi
100+
- if [[ ! $TRAVIS_TAG ]]; then bash .travis/validate_report_files.sh; fi
100101
- if [[ ! $TRAVIS_TAG ]] && [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sonar-scanner; fi
101102
- if [[ ! $TRAVIS_TAG ]]; then bash .travis/coveralls_uploader.sh; fi
102103
- bash .travis/build_docs.sh

.travis/validate_report_files.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
echo "validate html"
4+
5+
HTML_FILENAME="coverage.html"
6+
#Exclude existing issue with OL nested in PRE
7+
EXCLUSION_REGEX=".*Element\s.?ol.?\snot\sallowed\sas\schild\sof\selement\s.?pre.*"
8+
HTML_VALIDATOR_URL="https://validator.w3.org/nu/"
9+
VALIDATOR_OUT="gnu"
10+
WARNING_REGEX="info warning:"
11+
ERROR_REGEX="error:"
12+
13+
VALIDATION_RESULTS=$(curl -H "Content-Type: text/html; charset=utf-8" --data-binary @$HTML_FILENAME "$HTML_VALIDATOR_URL?out=$VALIDATOR_OUT&filterpattern=$EXCLUSION_REGEX")
14+
15+
ERROR_COUNT=`echo "$VALIDATION_RESULTS" | grep -c "$ERROR_REGEX"`
16+
WARNING_COUNT=`echo "$VALIDATION_RESULTS" | grep -c "$WARNING_REGEX"`
17+
18+
echo "There are $ERROR_COUNT errors, $WARNING_COUNT warning in $HTML_FILENAME"
19+
20+
if [ $ERROR_COUNT -gt 0 ]; then
21+
echo "$VALIDATION_RESULTS" | grep "$ERROR_REGEX"
22+
exit 1
23+
else
24+
exit 0
25+
fi

docs/userguide/advanced_data_comparison.md

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ utPLSQL expectations incorporates advanced data comparison options when comparin
77
- nested table and varray
88

99
Advanced data-comparison options are available for the [`equal`](expectations.md#equal) matcher.
10-
10+
1111
## Syntax
1212

1313
```
@@ -23,6 +23,9 @@ Advanced data-comparison options are available for the [`equal`](expectations.md
2323
- `exclude(a_items varchar2)` - item or comma separated list of items to exclude
2424
- `include(a_items ut_varchar2_list)` - table of items to include
2525
- `exclude(a_items ut_varchar2_list)` - table of items to exclude
26+
- `unordered` - perform compare on unordered set of data, return only missing or actual
27+
- `join_by(a_columns varchar2)` - columns or comma seperated list of columns to join two cursors by
28+
- `join_by(a_columns ut_varchar2_list)` - table of columns to join two cursors by
2629

2730
Each item in the comma separated list can be:
2831
- a column name of cursor to be compared
@@ -55,7 +58,7 @@ Columns 'ignore_me' and "ADate" will get excluded from cursor comparison.
5558
The cursor data is equal, when those columns are excluded.
5659

5760
This option is useful in scenarios, when you need to exclude incomparable/unpredictable column data like CREATE_DATE of a record that is maintained by default value on a table column.
58-
61+
5962
## Selecting columns for data comparison
6063

6164
Consider the following example
@@ -92,6 +95,135 @@ Only the columns 'RN', "A_Column" will be compared. Column 'SOME_COL' is exclude
9295

9396
This option can be useful in scenarios where you need to narrow-down the scope of test so that the test is only focused on very specific data.
9497

98+
##Unordered
99+
100+
Unordered option allows for quick comparison of two cursors without need of ordering them in any way.
101+
102+
Result of such comparison will be limited to only information about row existing or not existing in given set without actual information about exact differences.
103+
104+
105+
106+
```sql
107+
procedure unordered_tst is
108+
l_actual sys_refcursor;
109+
l_expected sys_refcursor;
110+
begin
111+
open l_expected for select username, user_id from all_users
112+
union all
113+
select 'TEST' username, -600 user_id from dual
114+
order by 1 desc;
115+
open l_actual for select username, user_id from all_users
116+
union all
117+
select 'TEST' username, -610 user_id from dual
118+
order by 1 asc;
119+
ut.expect( l_actual ).to_equal( l_expected ).unordered;
120+
end;
121+
```
122+
123+
124+
125+
Above test will result in two differences of one row extra and one row missing.
126+
127+
128+
129+
```sql
130+
Diff:
131+
Rows: [ 2 differences ]
132+
Missing: <ROW><USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID></ROW>
133+
Extra: <ROW><USERNAME>TEST</USERNAME><USER_ID>-610</USER_ID></ROW>
134+
```
135+
136+
137+
138+
139+
140+
## Join By option
141+
142+
You can now join two cursors by defining a primary key or composite key that will be used to uniquely identify and compare rows. This option allows us to exactly show which rows are missing, extra and which are different without ordering clause. In the situation where the join key is not unique, join will partition set over rows with a same key and join on row number as well as given join key. The extra rows or missing will be presented to user as well as not matching rows.
143+
144+
Join by option can be used in conjunction with include or exclude options. However if any of the join keys is part of exclude set, comparison will fail and report to user that sets could not be joined on specific key (excluded).
145+
146+
```sql
147+
procedure join_by_username is
148+
l_actual sys_refcursor;
149+
l_expected sys_refcursor;
150+
begin
151+
open l_expected for select username, user_id from all_users
152+
union all
153+
select 'TEST' username, -600 user_id from dual
154+
order by 1 desc;
155+
open l_actual for select username, user_id from all_users
156+
union all
157+
select 'TEST' username, -610 user_id from dual
158+
order by 1 asc;
159+
ut.expect( l_actual ).to_equal( l_expected ).join_by('USERNAME');
160+
end;
161+
```
162+
This will show you difference in row 'TEST' regardless of order.
163+
164+
```sql
165+
Rows: [ 1 differences ]
166+
PK <USERNAME>TEST</USERNAME> - Expected: <USER_ID>-600</USER_ID>
167+
PK <USERNAME>TEST</USERNAME> - Actual: <USER_ID>-610</USER_ID>
168+
```
169+
170+
Assumption is that join by is made by column name so that what will be displayed as part of results.
171+
172+
Join by options currently doesn't support nested table inside cursor comparison, however is still possible to compare a collection as a whole.
173+
174+
Example.
175+
176+
```sql
177+
procedure compare_collection_in_rec is
178+
l_actual sys_refcursor;
179+
l_expected sys_refcursor;
180+
l_actual_tab ut3.ut_annotated_object;
181+
l_expected_tab ut3.ut_annotated_object;
182+
l_expected_message varchar2(32767);
183+
l_actual_message varchar2(32767);
184+
begin
185+
select ut3.ut_annotated_object('TEST','TEST','TEST',
186+
ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'),
187+
ut3.ut_annotation(2,'test','test','test'))
188+
)
189+
into l_actual_tab from dual;
190+
191+
select ut3.ut_annotated_object('TEST','TEST','TEST',
192+
ut3.ut_annotations(ut3.ut_annotation(1,'test','test','test'),
193+
ut3.ut_annotation(2,'test','test','test'))
194+
)
195+
into l_expected_tab from dual;
196+
197+
--Arrange
198+
open l_actual for select l_actual_tab as nested_table from dual;
199+
200+
open l_expected for select l_expected_tab as nested_table from dual;
201+
202+
--Act
203+
ut3.ut.expect(l_actual).to_equal(l_expected).join_by('NESTED_TABLE/ANNOTATIONS');
204+
205+
end;
206+
```
207+
208+
209+
210+
In case when a there is detected collection inside cursor and we cannot join key. Comparison will present a failed joins and also a message about collection being detected.
211+
212+
```sql
213+
Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ]
214+
Diff:
215+
Unable to join sets:
216+
Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in expected
217+
Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in actual
218+
Please make sure that your join clause is not refferring to collection element
219+
```
220+
221+
222+
223+
224+
225+
**Please note that .join_by option will take longer to process due to need of parsing via primary keys.**
226+
95227
## Defining item as XPath
96228
When using XPath expression, keep in mind the following:
97229

@@ -109,4 +241,4 @@ begin
109241
open l_actual for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL, a.* from all_objects a where rownum < 4;
110242
ut.expect( l_actual ).to_equal( l_expected ).include( '/ROW/RN|/ROW/A_Column|/ROW/SOME_COL' );
111243
end;
112-
```
244+
```

0 commit comments

Comments
 (0)