|
7 | 7 |
|
8 | 8 | l_package_spec varchar2(32737); |
9 | 9 | l_package_body varchar2(32737); |
| 10 | + l_exception_spec varchar2(32737); |
10 | 11 | l_test_results ut3.ut_varchar2_list; |
11 | 12 | begin |
| 13 | + l_exception_spec := q'[ |
| 14 | + create or replace package exc_pkg is |
| 15 | + c_e_single_exc constant number := -20200; |
| 16 | + c_e_varch_exc constant varchar2(10) := '-20201'; |
| 17 | + c_e_list_1 number := -20202; |
| 18 | + c_e_list_2 constant number := -20203; |
| 19 | + c_e_diff_exc constant number := -20204; |
| 20 | + c_e_mix_list constant number := -20205; |
| 21 | + c_e_mix_missin constant number := -20206; |
| 22 | + |
| 23 | + e_some_exception exception; |
| 24 | + pragma exception_init(e_some_exception, -20207); |
| 25 | + |
| 26 | + end;]'; |
| 27 | + |
12 | 28 | l_package_spec := ' |
13 | 29 | create package annotated_package_with_throws is |
14 | 30 | --%suite(Dummy package to test annotation throws) |
|
45 | 61 | --%throws(7894562, operaqk, -=1, -1, pow74d, posdfk3) |
46 | 62 | procedure one_valid_exception_number; |
47 | 63 |
|
48 | | - --%test(Givess failure when a exception is expected and nothing is thrown) |
| 64 | + --%test(Gives failure when a exception is expected and nothing is thrown) |
49 | 65 | --%throws(-20459, -20136, -20145) |
50 | 66 | procedure nothing_thrown; |
| 67 | + |
| 68 | + --%test(Single exception defined as a constant number in package) |
| 69 | + --%throws(exc_pkg.c_e_single_exc) |
| 70 | + procedure single_exc_const_pkg; |
| 71 | + |
| 72 | + --%test(Gives success when one of annotated exception using constant is thrown) |
| 73 | + --%throws(exc_pkg.c_e_list_1,exc_pkg.c_e_list_2) |
| 74 | + procedure list_of_exc_constant; |
| 75 | + |
| 76 | + --%test(Gives failure when the raised exception is different that the annotated one using variable) |
| 77 | + --%throws(exc_pkg.c_e_diff_exc) |
| 78 | + procedure fail_not_match_exc; |
| 79 | + |
| 80 | + --%test(Success when one of exception from mixed list of number and constant is thrown) |
| 81 | + --%throws(exc_pkg.c_e_mix_list,-20105) |
| 82 | + procedure mixed_exc_list; |
| 83 | + |
| 84 | + --%test(Success when match exception even if other variable on list dont exists) |
| 85 | + --%throws(exc_pkg.c_e_mix_missin,utter_rubbish) |
| 86 | + procedure mixed_list_notexi; |
| 87 | + |
| 88 | + --%test(Success resolve and match named exception defined in pragma exception init) |
| 89 | + --%throws(exc_pkg.e_some_exception) |
| 90 | + procedure named_exc_pragma; |
| 91 | + |
| 92 | + --%test(Success resolve and match oracle named exception) |
| 93 | + --%throws(NO_DATA_FOUND) |
| 94 | + procedure named_exc_ora; |
| 95 | + |
| 96 | + --%test(Success resolve and match oracle named exception dup val index) |
| 97 | + --%throws(DUP_VAL_ON_INDEX) |
| 98 | + procedure named_exc_ora_dup_ind; |
| 99 | + |
51 | 100 | end; |
52 | 101 | '; |
53 | 102 |
|
|
98 | 147 | begin |
99 | 148 | null; |
100 | 149 | end; |
| 150 | + |
| 151 | + procedure single_exc_const_pkg is |
| 152 | + begin |
| 153 | + raise_application_error(exc_pkg.c_e_single_exc,''Test''); |
| 154 | + end; |
| 155 | + |
| 156 | + procedure list_of_exc_constant is |
| 157 | + begin |
| 158 | + raise_application_error(exc_pkg.c_e_list_1,''Test''); |
| 159 | + end; |
| 160 | + |
| 161 | + procedure fail_not_match_exc is |
| 162 | + begin |
| 163 | + raise NO_DATA_FOUND; |
| 164 | + end; |
| 165 | + |
| 166 | + procedure mixed_exc_list is |
| 167 | + begin |
| 168 | + raise_application_error(exc_pkg.c_e_mix_list,''Test''); |
| 169 | + end; |
| 170 | + |
| 171 | + procedure mixed_list_notexi is |
| 172 | + begin |
| 173 | + raise_application_error(exc_pkg.c_e_mix_missin,''Test''); |
| 174 | + end; |
| 175 | + |
| 176 | + procedure named_exc_pragma is |
| 177 | + begin |
| 178 | + raise exc_pkg.e_some_exception; |
| 179 | + end; |
| 180 | + |
| 181 | + procedure named_exc_ora is |
| 182 | + begin |
| 183 | + raise NO_DATA_FOUND; |
| 184 | + end; |
| 185 | + |
| 186 | + procedure named_exc_ora_dup_ind is |
| 187 | + begin |
| 188 | + raise DUP_VAL_ON_INDEX; |
| 189 | + end; |
| 190 | + |
101 | 191 | end; |
102 | 192 | '; |
103 | 193 |
|
| 194 | + execute immediate l_exception_spec; |
104 | 195 | execute immediate l_package_spec; |
105 | 196 | execute immediate l_package_body; |
106 | 197 |
|
| 198 | + |
107 | 199 | select * bulk collect into l_test_results from table(ut3.ut.run(('annotated_package_with_throws'))); |
108 | 200 |
|
109 | 201 | g_tests_results := ut3.ut_utils.table_to_clob(l_test_results); |
|
159 | 251 |
|
160 | 252 | procedure nothing_thrown is |
161 | 253 | begin |
162 | | - ut.expect(g_tests_results).to_match('^\s*Givess failure when a exception is expected and nothing is thrown \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 254 | + ut.expect(g_tests_results).to_match('^\s*Gives failure when a exception is expected and nothing is thrown \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
163 | 255 | ut.expect(g_tests_results).to_match('nothing_thrown\s*Expected one of exceptions \(-20459, -20136, -20145\) but nothing was raised.'); |
164 | 256 | end; |
165 | 257 |
|
| 258 | + procedure single_exc_const_pkg is |
| 259 | + begin |
| 260 | + ut.expect(g_tests_results).to_match('^\s*Single exception defined as a constant number in package \[[\.0-9]+ sec\]\s*$','m'); |
| 261 | + ut.expect(g_tests_results).not_to_match('single_exc_const_pkg'); |
| 262 | + end; |
| 263 | + |
| 264 | + procedure list_of_exc_constant is |
| 265 | + begin |
| 266 | + ut.expect(g_tests_results).to_match('^\s*Gives success when one of annotated exception using constant is thrown \[[\.0-9]+ sec\]\s*$','m'); |
| 267 | + ut.expect(g_tests_results).not_to_match('list_of_exc_constant'); |
| 268 | + end; |
| 269 | + |
| 270 | + procedure fail_not_match_exc is |
| 271 | + begin |
| 272 | + ut.expect(g_tests_results).to_match('^\s*Gives failure when the raised exception is different that the annotated one using variable \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 273 | + ut.expect(g_tests_results).to_match('fail_not_match_exc\s+Actual: -1403 was expected to equal: -20204\s+ORA-01403: no data found\s+ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); |
| 274 | + end; |
166 | 275 |
|
| 276 | + procedure mixed_exc_list is |
| 277 | + begin |
| 278 | + ut.expect(g_tests_results).to_match('^\s*Success when one of exception from mixed list of number and constant is thrown \[[\.0-9]+ sec\]\s*$','m'); |
| 279 | + ut.expect(g_tests_results).not_to_match('mixed_exc_list'); |
| 280 | + end; |
| 281 | + |
| 282 | + procedure mixed_list_notexi is |
| 283 | + begin |
| 284 | + ut.expect(g_tests_results).to_match('^\s*Success when match exception even if other variable on list dont exists \[[\.0-9]+ sec\]\s*$','m'); |
| 285 | + ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); |
| 286 | + end; |
| 287 | + |
| 288 | + procedure named_exc_pragma is |
| 289 | + begin |
| 290 | + ut.expect(g_tests_results).to_match('^\s*Success resolve and match named exception defined in pragma exception init \[[\.0-9]+ sec\]\s*$','m'); |
| 291 | + ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); |
| 292 | + end; |
| 293 | + |
| 294 | + procedure named_exc_ora is |
| 295 | + begin |
| 296 | + ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception \[[\.0-9]+ sec\]\s*$','m'); |
| 297 | + ut.expect(g_tests_results).not_to_match('named_exc_ora'); |
| 298 | + end; |
| 299 | + |
| 300 | + procedure named_exc_ora_dup_ind is |
| 301 | + begin |
| 302 | + ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception dup val index \[[\.0-9]+ sec\]\s*$','m'); |
| 303 | + ut.expect(g_tests_results).not_to_match('named_exc_ora_dup_ind'); |
| 304 | + end; |
| 305 | + |
167 | 306 | procedure drop_test_package is |
168 | 307 | pragma autonomous_transaction; |
169 | 308 | begin |
170 | 309 | execute immediate 'drop package annotated_package_with_throws'; |
| 310 | + execute immediate 'drop package exc_pkg'; |
171 | 311 | end; |
172 | 312 |
|
173 | 313 | end; |
|
0 commit comments