|
| 1 | +create or replace package test_remove_rooms_by_name as |
| 2 | + |
| 3 | + -- %suite(Remove rooms by name) |
| 4 | + |
| 5 | + -- %suitesetup |
| 6 | + procedure setup_rooms; |
| 7 | + |
| 8 | + -- %test(Removes a room without content in it) |
| 9 | + procedure remove_empty_room; |
| 10 | + |
| 11 | + -- %test(Does not remove room when it has content) |
| 12 | + procedure room_with_content; |
| 13 | + |
| 14 | + -- %test(Raises exception when null room name given) |
| 15 | + procedure null_room_name; |
| 16 | + |
| 17 | +end; |
| 18 | +/ |
| 19 | + |
| 20 | +create or replace package body test_remove_rooms_by_name as |
| 21 | + |
| 22 | + procedure setup_rooms is |
| 23 | + begin |
| 24 | + insert all |
| 25 | + into rooms values(1, 'Dining Room') |
| 26 | + into rooms values(2, 'Living Room') |
| 27 | + into rooms values(3, 'Office') |
| 28 | + into rooms values(4, 'Bathroom') |
| 29 | + into rooms values(5, 'Bedroom') |
| 30 | + select 1 from dual; |
| 31 | + |
| 32 | + insert all |
| 33 | + into room_contents values(1, 1, 'Table') |
| 34 | + into room_contents values(2, 1, 'Hutch') |
| 35 | + into room_contents values(3, 1, 'Chair') |
| 36 | + into room_contents values(4, 2, 'Sofa') |
| 37 | + into room_contents values(5, 2, 'Lamp') |
| 38 | + into room_contents values(6, 3, 'Desk') |
| 39 | + into room_contents values(7, 3, 'Chair') |
| 40 | + into room_contents values(8, 3, 'Computer') |
| 41 | + into room_contents values(9, 3, 'Whiteboard') |
| 42 | + select 1 from dual; |
| 43 | + end; |
| 44 | + |
| 45 | + procedure remove_empty_room is |
| 46 | + l_rooms_not_named_b sys_refcursor; |
| 47 | + l_remaining_rooms sys_refcursor; |
| 48 | + begin |
| 49 | + open l_rooms_not_named_b for select * from rooms where name not like 'B%'; |
| 50 | + |
| 51 | + remove_rooms_by_name('B%'); |
| 52 | + |
| 53 | + open l_remaining_rooms for select * from rooms; |
| 54 | + ut.expect( l_remaining_rooms ).to_(equal(l_rooms_not_named_b)); |
| 55 | + end; |
| 56 | + |
| 57 | + procedure room_with_content is |
| 58 | + l_rooms sys_refcursor; |
| 59 | + l_remaining_rooms sys_refcursor; |
| 60 | + begin |
| 61 | + open l_rooms for select * from rooms; |
| 62 | + |
| 63 | + begin |
| 64 | + remove_rooms_by_name('Living Room'); |
| 65 | + ut.expect( sqlcode ).to_( equal(-2292) ); |
| 66 | + exception |
| 67 | + when others then |
| 68 | + ut.expect( sqlcode ).to_( equal(-2292) ); |
| 69 | + end; |
| 70 | + |
| 71 | + open l_remaining_rooms for select * from rooms; |
| 72 | + |
| 73 | + ut.expect( l_remaining_rooms ).to_( equal( l_rooms ) ); |
| 74 | + end; |
| 75 | + |
| 76 | + procedure null_room_name is |
| 77 | + l_rooms sys_refcursor; |
| 78 | + l_remaining_rooms sys_refcursor; |
| 79 | + begin |
| 80 | + open l_rooms for select * from rooms; |
| 81 | + |
| 82 | + begin |
| 83 | + remove_rooms_by_name(NULL); |
| 84 | + ut.expect( sqlcode ).to_( equal(-6501) ); |
| 85 | + exception |
| 86 | + when others then |
| 87 | + ut.expect( sqlcode ).to_( equal(-6501) ); |
| 88 | + end; |
| 89 | + |
| 90 | + open l_remaining_rooms for select * from rooms; |
| 91 | + |
| 92 | + ut.expect( l_remaining_rooms ).to_( equal( l_rooms ) ); |
| 93 | + end; |
| 94 | + |
| 95 | +end; |
| 96 | +/ |
0 commit comments