-
Notifications
You must be signed in to change notification settings - Fork 189
Feature/better examples #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ede9fa1
Added award_bonus example (based on https://docs.oracle.com/database/…
jgebal f6b4e96
Added betwnstr example
jgebal 3a19187
Added remove rooms example
jgebal 91fd638
Fixed examples and added examples to main examples run.
jgebal 776cc32
Fixed examples execution and improved performance and visibility for …
jgebal 66b9b08
Merge branch 'version3' into feature/better_examples
jgebal 72471a6
Merge branch 'version3' into feature/better_examples
jgebal 9502f16
Adressed code review comments.
jgebal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --https://docs.oracle.com/database/sql-developer-4.2/RPTUG/sql-developer-unit-testing.htm#RPTUG45065 | ||
|
|
||
|
|
||
| create or replace procedure award_bonus (emp_id number, sales_amt number) as | ||
| commission real; | ||
| comm_missing exception; | ||
| begin | ||
| select commission_pct into commission | ||
| from employees_test | ||
| where employee_id = emp_id; | ||
|
|
||
| if commission is null then | ||
| raise comm_missing; | ||
| else | ||
| update employees_test | ||
| set salary = nvl(salary,0) + sales_amt*commission | ||
| where employee_id = emp_id; | ||
| end if; | ||
| end; | ||
| / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| create table employees_test (employee_id number primary key, commission_pct number, salary number); | ||
| insert into employees_test values (1001, 0.2, 8400); | ||
| insert into employees_test values (1002, 0.25, 6000); | ||
| insert into employees_test values (1003, 0.3, 5000); | ||
| -- next employee is not in the sales department, thus is not on commission. | ||
| insert into employees_test values (1004, null, 10000); | ||
| commit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| @@employees_test.sql | ||
| @@award_bonus.sql | ||
| @@test_award_bonus.pkg | ||
|
|
||
| set serveroutput on size unlimited format truncated | ||
|
|
||
| exec ut.run(user||'.test_award_bonus',ut_documentation_reporter()); | ||
|
|
||
| drop package test_award_bonus; | ||
| drop procedure award_bonus; | ||
| drop table employees_test; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| create or replace package test_award_bonus as | ||
|
|
||
| -- %suite(Award bonus) | ||
|
|
||
| -- %test(Sets new salary as pct commision * sales amount) | ||
| -- %testsetup(add_test_employee) | ||
| procedure update_employee_salary; | ||
|
|
||
| -- %test(Raises exception if null bonus is passed) | ||
| -- %testsetup(add_employee_with_null_comm) | ||
| procedure fail_on_null_bonus; | ||
|
|
||
| procedure add_test_employee; | ||
|
|
||
| procedure add_employee_with_null_comm; | ||
|
|
||
| end; | ||
| / | ||
|
|
||
| create or replace package body test_award_bonus as | ||
|
|
||
| gc_test_employee constant integer := -1; | ||
| gc_salary constant number := 4500; | ||
| gc_commision_pct constant number := 0.2; | ||
|
|
||
| procedure update_employee_salary is | ||
| results sys_refcursor; | ||
| expected sys_refcursor; | ||
| not_affected sys_refcursor; | ||
| c_sales_amount constant number := 1000; | ||
| begin | ||
| --arrange | ||
| open expected for | ||
| select (salary + c_sales_amount * gc_commision_pct) as new_salary | ||
| from employees_test where employee_id = gc_test_employee; | ||
|
|
||
| open not_affected for | ||
| select * from employees_test where employee_id <> gc_test_employee; | ||
|
|
||
| --act | ||
| award_bonus(emp_id => gc_test_employee, sales_amt => c_sales_amount); | ||
|
|
||
| --assert | ||
| open results for | ||
| select salary as new_salary | ||
| from employees_test where employee_id = gc_test_employee; | ||
|
|
||
| ut.expect( results ).to_( equal( expected ) ); | ||
|
|
||
| open results for | ||
| select * from employees_test where employee_id != gc_test_employee; | ||
|
|
||
| ut.expect( results ).to_( equal( not_affected ) ); | ||
| end; | ||
|
|
||
| procedure fail_on_null_bonus is | ||
| begin | ||
| award_bonus(emp_id => gc_test_employee, sales_amt => null); | ||
| ut.expect( sqlcode ).not_to( equal( 0 ) ); | ||
| exception | ||
| when others then | ||
| ut.expect( sqlcode ).not_to( equal( 0 ) ); | ||
| end; | ||
|
|
||
| procedure add_employee( emp_id number, comm_pct number, sal number ) is | ||
| begin | ||
| insert into employees_test (employee_id, commission_pct, salary) | ||
| values (emp_id, comm_pct, sal); | ||
| end; | ||
|
|
||
| procedure add_test_employee is | ||
| begin | ||
| add_employee(gc_test_employee, 0.2, gc_salary); | ||
| end; | ||
|
|
||
| procedure add_employee_with_null_comm is | ||
| begin | ||
| add_employee(gc_test_employee, null, gc_salary); | ||
| end; | ||
|
|
||
| end; | ||
| / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| create or replace function betwnstr( a_string varchar2, a_start_pos integer, a_end_pos integer ) return varchar2 is | ||
| l_start_pos pls_integer := a_start_pos; | ||
| begin | ||
| if l_start_pos = 0 then | ||
| l_start_pos := 1; | ||
| end if; | ||
| return substr( a_string, l_start_pos, a_end_pos - l_start_pos + 1); | ||
| end; | ||
| / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| @@betwnstr.sql | ||
| @@test_betwnstr.pkg | ||
|
|
||
| set serveroutput on size unlimited format truncated | ||
|
|
||
| exec ut.run(user||'.test_betwnstr',ut_documentation_reporter()); | ||
|
|
||
| drop package test_betwnstr; | ||
| drop function betwnstr; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| create or replace package test_betwnstr as | ||
|
|
||
| -- %suite(Between string function) | ||
|
|
||
| -- %test(Returns substring from start position to end position) | ||
| procedure normal_case; | ||
|
|
||
| -- %test(Returns substring when start position is zero) | ||
| procedure zero_start_position; | ||
|
|
||
| -- %test(Returns string until end if end position is greated than string length) | ||
| procedure big_end_position; | ||
|
|
||
| -- %test(Returns null for null inlut srting value) | ||
| procedure null_string; | ||
| end; | ||
| / | ||
|
|
||
| create or replace package body test_betwnstr as | ||
|
|
||
| procedure normal_case is | ||
| begin | ||
| ut.expect( betwnstr( '1234567', 2, 5 ) ).to_( equal('2345') ); | ||
| end; | ||
|
|
||
| procedure zero_start_position is | ||
| begin | ||
| ut.expect( betwnstr( '1234567', 0, 5 ) ).to_( equal('12345') ); | ||
| end; | ||
|
|
||
|
|
||
| procedure big_end_position is | ||
| begin | ||
| ut.expect( betwnstr( '1234567', 0, 500 ) ).to_( equal('1234567') ); | ||
| end; | ||
|
|
||
| procedure null_string is | ||
| begin | ||
| ut.expect( betwnstr( null, 2, 5 ) ).to_( be_null ); | ||
| end; | ||
|
|
||
| end; | ||
| / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| create or replace procedure remove_rooms_by_name( l_name rooms.name%type ) is | ||
| begin | ||
| if l_name is null then | ||
| raise program_error; | ||
| end if; | ||
| delete from rooms where name like l_name; | ||
| end; | ||
| / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| create table rooms ( | ||
| room_key number primary key, | ||
| name varchar2(100) | ||
| ); | ||
|
|
||
| create table room_contents ( | ||
| contents_key number primary key, | ||
| room_key number, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit simpler: |
||
| name varchar2(100) | ||
| ); | ||
|
|
||
| alter table room_contents add constraint fk_rooms foreign key (room_key) references rooms (room_key); | ||
13 changes: 13 additions & 0 deletions
13
examples/remove_rooms_by_name/run_remove_rooms_by_name_test.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| @@rooms.sql | ||
| @@remove_rooms_by_name.sql | ||
| @@test_remove_rooms_by_name.pkg | ||
|
|
||
| set serveroutput on size unlimited format truncated | ||
|
|
||
| exec ut.run(user||'.test_remove_rooms_by_name',ut_documentation_reporter()); | ||
|
|
||
| drop package test_remove_rooms_by_name; | ||
| drop procedure remove_rooms_by_name; | ||
| drop table room_contents; | ||
| drop table rooms; | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache invalidation is fixed in another PR, no more need in that