|
| 1 | +create or replace package body test_annot_throws_exception |
| 2 | +is |
| 3 | + g_tests_results clob; |
| 4 | + |
| 5 | + procedure recollect_tests_results is |
| 6 | + pragma autonomous_transaction; |
| 7 | + |
| 8 | + l_package_spec varchar2(32737); |
| 9 | + l_package_body varchar2(32737); |
| 10 | + l_exception_spec varchar2(32737); |
| 11 | + l_test_results ut3.ut_varchar2_list; |
| 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_dummy constant varchar2(10) := 'dummy'; |
| 17 | + c_e_varch_exc constant varchar2(10) := '-20201'; |
| 18 | + c_e_list_1 number := -20202; |
| 19 | + c_e_list_2 constant number := -20203; |
| 20 | + c_e_diff_exc constant number := -20204; |
| 21 | + c_e_mix_list constant number := -20205; |
| 22 | + c_e_mix_missin constant number := -20206; |
| 23 | + |
| 24 | + e_some_exception exception; |
| 25 | + pragma exception_init(e_some_exception, -20207); |
| 26 | + |
| 27 | + end;]'; |
| 28 | + |
| 29 | + l_package_spec := ' |
| 30 | + create package annotated_package_with_throws is |
| 31 | + --%suite(Dummy package to test annotation throws) |
| 32 | + |
| 33 | + --%test(Throws same annotated exception) |
| 34 | + --%throws(-20145) |
| 35 | + procedure raised_same_exception; |
| 36 | + |
| 37 | + --%test(Throws one of the listed exceptions) |
| 38 | + --%throws(-20145,-20146, -20189 ,-20563) |
| 39 | + procedure raised_one_listed_exception; |
| 40 | + |
| 41 | + --%test(Leading zero is ignored in exception list) |
| 42 | + --%throws(-01476) |
| 43 | + procedure leading_0_exception_no; |
| 44 | + |
| 45 | + --%test(Throws diff exception) |
| 46 | + --%throws(-20144) |
| 47 | + procedure raised_diff_exception; |
| 48 | + |
| 49 | + --%test(Throws empty) |
| 50 | + --%throws() |
| 51 | + procedure empty_throws; |
| 52 | + |
| 53 | + --%test(Ignores annotation and fails when exception was thrown) |
| 54 | + --%throws(hello,784#,0-=234,,u1234) |
| 55 | + procedure bad_paramters_with_except; |
| 56 | + |
| 57 | + --%test(Ignores annotation and succeeds when no exception thrown) |
| 58 | + --%throws(hello,784#,0-=234,,u1234) |
| 59 | + procedure bad_paramters_without_except; |
| 60 | + |
| 61 | + --%test(Detects a valid exception number within many invalid ones) |
| 62 | + --%throws(7894562, operaqk, -=1, -1, pow74d, posdfk3) |
| 63 | + procedure one_valid_exception_number; |
| 64 | + |
| 65 | + --%test(Gives failure when a exception is expected and nothing is thrown) |
| 66 | + --%throws(-20459, -20136, -20145) |
| 67 | + procedure nothing_thrown; |
| 68 | + |
| 69 | + --%test(Single exception defined as a constant number in package) |
| 70 | + --%throws(exc_pkg.c_e_single_exc) |
| 71 | + procedure single_exc_const_pkg; |
| 72 | + |
| 73 | + --%test(Gives success when one of annotated exception using constant is thrown) |
| 74 | + --%throws(exc_pkg.c_e_list_1,exc_pkg.c_e_list_2) |
| 75 | + procedure list_of_exc_constant; |
| 76 | + |
| 77 | + --%test(Gives failure when the raised exception is different that the annotated one using variable) |
| 78 | + --%throws(exc_pkg.c_e_diff_exc) |
| 79 | + procedure fail_not_match_exc; |
| 80 | + |
| 81 | + --%test(Success when one of exception from mixed list of number and constant is thrown) |
| 82 | + --%throws(exc_pkg.c_e_mix_list,-20105) |
| 83 | + procedure mixed_exc_list; |
| 84 | + |
| 85 | + --%test(Success when match exception even if other variable on list dont exists) |
| 86 | + --%throws(exc_pkg.c_e_mix_missin,utter_rubbish) |
| 87 | + procedure mixed_list_notexi; |
| 88 | + |
| 89 | + --%test(Success resolve and match named exception defined in pragma exception init) |
| 90 | + --%throws(exc_pkg.e_some_exception) |
| 91 | + procedure named_exc_pragma; |
| 92 | + |
| 93 | + --%test(Success resolve and match oracle named exception) |
| 94 | + --%throws(NO_DATA_FOUND) |
| 95 | + procedure named_exc_ora; |
| 96 | + |
| 97 | + --%test(Success resolve and match oracle named exception dup val index) |
| 98 | + --%throws(DUP_VAL_ON_INDEX) |
| 99 | + procedure named_exc_ora_dup_ind; |
| 100 | + |
| 101 | + --%test(Success map no data 100 to -1403) |
| 102 | + --%throws(-1403) |
| 103 | + procedure nodata_exc_ora; |
| 104 | + |
| 105 | + --%test(Success for exception defined as varchar) |
| 106 | + --%throws(exc_pkg.c_e_varch_exc) |
| 107 | + procedure defined_varchar_exc; |
| 108 | + |
| 109 | + --%test(Non existing constant exception) |
| 110 | + --%throws(dummy.c_dummy); |
| 111 | + procedure non_existing_const; |
| 112 | + |
| 113 | + --%test(Bad exception constant) |
| 114 | + --%throws(exc_pkg.c_e_dummy); |
| 115 | + procedure bad_exc_const; |
| 116 | + |
| 117 | + end; |
| 118 | + '; |
| 119 | + |
| 120 | + l_package_body := ' |
| 121 | + create package body annotated_package_with_throws is |
| 122 | + procedure raised_same_exception is |
| 123 | + begin |
| 124 | + raise_application_error(-20145, ''Test error''); |
| 125 | + end; |
| 126 | + |
| 127 | + procedure raised_one_listed_exception is |
| 128 | + begin |
| 129 | + raise_application_error(-20189, ''Test error''); |
| 130 | + end; |
| 131 | + |
| 132 | + procedure leading_0_exception_no is |
| 133 | + x integer; |
| 134 | + begin |
| 135 | + x := 1 / 0; |
| 136 | + end; |
| 137 | + |
| 138 | + procedure raised_diff_exception is |
| 139 | + begin |
| 140 | + raise_application_error(-20143, ''Test error''); |
| 141 | + end; |
| 142 | + |
| 143 | + procedure empty_throws is |
| 144 | + begin |
| 145 | + raise_application_error(-20143, ''Test error''); |
| 146 | + end; |
| 147 | + |
| 148 | + procedure bad_paramters_with_except is |
| 149 | + begin |
| 150 | + raise_application_error(-20143, ''Test error''); |
| 151 | + end; |
| 152 | + |
| 153 | + procedure bad_paramters_without_except is |
| 154 | + begin |
| 155 | + null; |
| 156 | + end; |
| 157 | + |
| 158 | + procedure one_valid_exception_number is |
| 159 | + begin |
| 160 | + raise dup_val_on_index; |
| 161 | + end; |
| 162 | + |
| 163 | + procedure nothing_thrown is |
| 164 | + begin |
| 165 | + null; |
| 166 | + end; |
| 167 | + |
| 168 | + procedure single_exc_const_pkg is |
| 169 | + begin |
| 170 | + raise_application_error(exc_pkg.c_e_single_exc,''Test''); |
| 171 | + end; |
| 172 | + |
| 173 | + procedure list_of_exc_constant is |
| 174 | + begin |
| 175 | + raise_application_error(exc_pkg.c_e_list_1,''Test''); |
| 176 | + end; |
| 177 | + |
| 178 | + procedure fail_not_match_exc is |
| 179 | + begin |
| 180 | + raise NO_DATA_FOUND; |
| 181 | + end; |
| 182 | + |
| 183 | + procedure mixed_exc_list is |
| 184 | + begin |
| 185 | + raise_application_error(exc_pkg.c_e_mix_list,''Test''); |
| 186 | + end; |
| 187 | + |
| 188 | + procedure mixed_list_notexi is |
| 189 | + begin |
| 190 | + raise_application_error(exc_pkg.c_e_mix_missin,''Test''); |
| 191 | + end; |
| 192 | + |
| 193 | + procedure named_exc_pragma is |
| 194 | + begin |
| 195 | + raise exc_pkg.e_some_exception; |
| 196 | + end; |
| 197 | + |
| 198 | + procedure named_exc_ora is |
| 199 | + begin |
| 200 | + raise NO_DATA_FOUND; |
| 201 | + end; |
| 202 | + |
| 203 | + procedure named_exc_ora_dup_ind is |
| 204 | + begin |
| 205 | + raise DUP_VAL_ON_INDEX; |
| 206 | + end; |
| 207 | + |
| 208 | + procedure nodata_exc_ora is |
| 209 | + begin |
| 210 | + raise NO_DATA_FOUND; |
| 211 | + end; |
| 212 | + |
| 213 | + procedure defined_varchar_exc is |
| 214 | + begin |
| 215 | + raise_application_error(exc_pkg.c_e_varch_exc,''Test''); |
| 216 | + end; |
| 217 | + |
| 218 | + procedure non_existing_const is |
| 219 | + begin |
| 220 | + raise_application_error(-20143, ''Test error''); |
| 221 | + end; |
| 222 | + |
| 223 | + procedure bad_exc_const is |
| 224 | + begin |
| 225 | + raise_application_error(-20143, ''Test error''); |
| 226 | + end; |
| 227 | + |
| 228 | + end; |
| 229 | + '; |
| 230 | + |
| 231 | + execute immediate l_exception_spec; |
| 232 | + execute immediate l_package_spec; |
| 233 | + execute immediate l_package_body; |
| 234 | + |
| 235 | + |
| 236 | + select * bulk collect into l_test_results from table(ut3.ut.run(('annotated_package_with_throws'))); |
| 237 | + |
| 238 | + g_tests_results := ut3.ut_utils.table_to_clob(l_test_results); |
| 239 | + end; |
| 240 | + |
| 241 | + procedure throws_same_annotated_except is |
| 242 | + begin |
| 243 | + ut.expect(g_tests_results).to_match('^\s*Throws same annotated exception \[[,\.0-9]+ sec\]\s*$','m'); |
| 244 | + ut.expect(g_tests_results).not_to_match('raised_same_exception'); |
| 245 | + end; |
| 246 | + |
| 247 | + procedure throws_one_of_annotated_excpt is |
| 248 | + begin |
| 249 | + ut.expect(g_tests_results).to_match('^\s*Throws one of the listed exceptions \[[,\.0-9]+ sec\]\s*$','m'); |
| 250 | + ut.expect(g_tests_results).not_to_match('raised_one_listed_exception'); |
| 251 | + end; |
| 252 | + |
| 253 | + procedure throws_with_leading_zero is |
| 254 | + begin |
| 255 | + ut.expect(g_tests_results).to_match('^\s*Leading zero is ignored in exception list \[[,\.0-9]+ sec\]\s*$','m'); |
| 256 | + ut.expect(g_tests_results).not_to_match('leading_0_exception_no'); |
| 257 | + end; |
| 258 | + |
| 259 | + procedure throws_diff_annotated_except is |
| 260 | + begin |
| 261 | + ut.expect(g_tests_results).to_match('^\s*Throws diff exception \[[,\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 262 | + ut.expect(g_tests_results).to_match('raised_diff_exception\s+Actual: -20143 was expected to equal: -20144\s+ORA-20143: Test error\s+ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); |
| 263 | + end; |
| 264 | + |
| 265 | + procedure throws_empty is |
| 266 | + begin |
| 267 | + ut.expect(g_tests_results).to_match('^\s*Throws empty \[[,\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 268 | + ut.expect(g_tests_results).to_match('empty_throws\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); |
| 269 | + end; |
| 270 | + |
| 271 | + procedure bad_paramters_with_except is |
| 272 | + begin |
| 273 | + ut.expect(g_tests_results).to_match('^\s*Ignores annotation and fails when exception was thrown \[[,\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 274 | + ut.expect(g_tests_results).to_match('bad_paramters_with_except\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); |
| 275 | + end; |
| 276 | + |
| 277 | + procedure bad_paramters_without_except is |
| 278 | + begin |
| 279 | + ut.expect(g_tests_results).to_match('^\s*Ignores annotation and succeeds when no exception thrown \[[,\.0-9]+ sec\]\s*$','m'); |
| 280 | + ut.expect(g_tests_results).not_to_match('bad_paramters_without_except'); |
| 281 | + end; |
| 282 | + |
| 283 | + procedure one_valid_exception_number is |
| 284 | + begin |
| 285 | + ut.expect(g_tests_results).to_match('^\s*Detects a valid exception number within many invalid ones \[[\.0-9]+ sec\]\s*$','m'); |
| 286 | + ut.expect(g_tests_results).not_to_match('one_valid_exception_number'); |
| 287 | + end; |
| 288 | + |
| 289 | + procedure nothing_thrown is |
| 290 | + begin |
| 291 | + 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'); |
| 292 | + ut.expect(g_tests_results).to_match('nothing_thrown\s*Expected one of exceptions \(-20459, -20136, -20145\) but nothing was raised.'); |
| 293 | + end; |
| 294 | + |
| 295 | + procedure single_exc_const_pkg is |
| 296 | + begin |
| 297 | + ut.expect(g_tests_results).to_match('^\s*Single exception defined as a constant number in package \[[,\.0-9]+ sec\]\s*$','m'); |
| 298 | + ut.expect(g_tests_results).not_to_match('single_exc_const_pkg'); |
| 299 | + end; |
| 300 | + |
| 301 | + procedure list_of_exc_constant is |
| 302 | + begin |
| 303 | + ut.expect(g_tests_results).to_match('^\s*Gives success when one of annotated exception using constant is thrown \[[,\.0-9]+ sec\]\s*$','m'); |
| 304 | + ut.expect(g_tests_results).not_to_match('list_of_exc_constant'); |
| 305 | + end; |
| 306 | + |
| 307 | + procedure fail_not_match_exc is |
| 308 | + begin |
| 309 | + 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'); |
| 310 | + 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"'); |
| 311 | + end; |
| 312 | + |
| 313 | + procedure mixed_exc_list is |
| 314 | + begin |
| 315 | + 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'); |
| 316 | + ut.expect(g_tests_results).not_to_match('mixed_exc_list'); |
| 317 | + end; |
| 318 | + |
| 319 | + procedure mixed_list_notexi is |
| 320 | + begin |
| 321 | + 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'); |
| 322 | + ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); |
| 323 | + end; |
| 324 | + |
| 325 | + procedure named_exc_pragma is |
| 326 | + begin |
| 327 | + ut.expect(g_tests_results).to_match('^\s*Success resolve and match named exception defined in pragma exception init \[[,\.0-9]+ sec\]\s*$','m'); |
| 328 | + ut.expect(g_tests_results).not_to_match('mixed_list_notexi'); |
| 329 | + end; |
| 330 | + |
| 331 | + procedure named_exc_ora is |
| 332 | + begin |
| 333 | + ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception \[[,\.0-9]+ sec\]\s*$','m'); |
| 334 | + ut.expect(g_tests_results).not_to_match('named_exc_ora'); |
| 335 | + end; |
| 336 | + |
| 337 | + procedure named_exc_ora_dup_ind is |
| 338 | + begin |
| 339 | + ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception dup val index \[[,\.0-9]+ sec\]\s*$','m'); |
| 340 | + ut.expect(g_tests_results).not_to_match('named_exc_ora_dup_ind'); |
| 341 | + end; |
| 342 | + |
| 343 | + procedure nodata_exc_ora is |
| 344 | + begin |
| 345 | + ut.expect(g_tests_results).to_match('^\s*Success map no data 100 to -1403 \[[,\.0-9]+ sec\]\s*$','m'); |
| 346 | + ut.expect(g_tests_results).not_to_match('nodata_exc_ora'); |
| 347 | + end; |
| 348 | + |
| 349 | + procedure defined_varchar_exc is |
| 350 | + begin |
| 351 | + ut.expect(g_tests_results).to_match('^\s*Success for exception defined as varchar \[[,\.0-9]+ sec\]\s*$','m'); |
| 352 | + ut.expect(g_tests_results).not_to_match('defined_varchar_exc'); |
| 353 | + end; |
| 354 | + |
| 355 | + procedure non_existing_const is |
| 356 | + begin |
| 357 | + ut.expect(g_tests_results).to_match('^\s*Non existing constant exception \[[,\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 358 | + ut.expect(g_tests_results).to_match('non_existing_const\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); |
| 359 | + end; |
| 360 | + |
| 361 | + procedure bad_exc_const is |
| 362 | + begin |
| 363 | + ut.expect(g_tests_results).to_match('^\s*Bad exception constant \[[,\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m'); |
| 364 | + ut.expect(g_tests_results).to_match('bad_exc_const\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"'); |
| 365 | + end; |
| 366 | + |
| 367 | + procedure drop_test_package is |
| 368 | + pragma autonomous_transaction; |
| 369 | + begin |
| 370 | + execute immediate 'drop package annotated_package_with_throws'; |
| 371 | + execute immediate 'drop package exc_pkg'; |
| 372 | + end; |
| 373 | + |
| 374 | +end; |
| 375 | +/ |
0 commit comments