Skip to content

Commit 943d72f

Browse files
committed
Initial version of demo project.
1 parent 498c853 commit 943d72f

23 files changed

+486
-0
lines changed

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### JetBrains template
2+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
3+
4+
*.iml
5+
6+
## Directory-based project format:
7+
.idea/
8+

Diff for: .travis.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
sudo: required
2+
3+
language: java
4+
jdk:
5+
- oraclejdk8
6+
7+
addons:
8+
sonarqube:
9+
token:
10+
secure: ${SONAR_TOKEN}
11+
branches:
12+
- develop
13+
- master
14+
15+
cache:
16+
directories:
17+
- node_modules
18+
19+
env:
20+
global:
21+
#Oracle 11g XE R2 variables
22+
- ORACLE_COOKIE=sqldev
23+
- ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
24+
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
25+
- ORACLE_SID=XE
26+
# utPLSQL variables
27+
- UTPLSQL_VERSION="v3.0.0-beta"
28+
- UTPLSQL_FILE="utPLSQLv3.0.0.562-beta"
29+
# project variables
30+
- DB_USER=ut3_demo
31+
- DB_PASS=LHZYPbWvYdu2ctp8
32+
33+
before_install:
34+
# download Oracle XE installer for Travis
35+
- curl -L -O 'https://github.com/cbandy/travis-oracle/archive/v2.0.1.tar.gz'
36+
- mkdir -p .travis/oracle
37+
- tar x -C .travis/oracle --strip-components=1 -f v2.0.1.tar.gz
38+
# download utPLSQL
39+
- curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/${UTPLSQL_VERSION}/${UTPLSQL_FILE}.tar.gz"
40+
- tar -xzf ${UTPLSQL_FILE}.tar.gz
41+
- cp ${UTPLSQL_FILE}/client_source/sqlplus/ut_run.sql .
42+
43+
install:
44+
- . .travis/oracle/download.sh
45+
- . .travis/oracle/install.sh
46+
#
47+
- . .travis/setup_account.sh
48+
- . .travis/install_utplsql.sh
49+
- . source/install.sh
50+
- . test/install.sh
51+
52+
script:
53+
- . tests/run.sh

Diff for: .travis/install_utplsql.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -ev
4+
5+
cd $UTPLSQL_FILE/source
6+
7+
sqlplus -S -L sys/oracle@xe AS SYSDBA @install_headless.sql
8+
9+
10+

Diff for: .travis/setup_account.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -ev
4+
5+
"$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA <<SQL
6+
create user ${DB_USER} identified by ${DB_PASS} quota unlimited on USERS default tablespace USERS;
7+
8+
grant create session, create procedure, create type, create table, create sequence, create view to ${DB_USER};
9+
10+
exit
11+
SQL

Diff for: sonar-project.properties

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# must be unique in a given SonarQube instance
2+
sonar.projectKey=utPLSQL:utPLSQL-demo-project
3+
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
4+
sonar.projectName=utPLSQL-demo-project
5+
6+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
7+
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
8+
# If not set, SonarQube starts looking for source code from the directory containing
9+
# the sonar-project.properties file.
10+
sonar.sources=./source
11+
sonar.coverageReportPaths=./sonar-coverage.xml
12+
sonar.links.issue=https://github.com/utPLSQL/utPLSQL-demo-project/issues
13+
sonar.links.ci=https://travis-ci.org/utPLSQL/utPLSQL-demo-project
14+
sonar.links.homepage=https://github.com/utPLSQL/utPLSQL-demo-project
15+
sonar.projectDescription=Demo of a project using utPLSQL, TravisCI and Sonar integrations
16+
sonar.plsql.file.suffixes=sql,tab,pkb,tpb,prc,fnc
17+
sonar.language=plsql
18+
19+
# Encoding of the source code. Default is default system encoding
20+
#sonar.sourceEncoding=UTF-8

Diff for: source/award_bonus/award_bonus.prc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
create or replace procedure award_bonus (emp_id number, sales_amt number) as
2+
--https://docs.oracle.com/database/sql-developer-4.2/RPTUG/sql-developer-unit-testing.htm#RPTUG45065
3+
commission real;
4+
comm_missing exception;
5+
begin
6+
select commission_pct into commission
7+
from employees_test
8+
where employee_id = emp_id;
9+
10+
if commission is null then
11+
raise comm_missing;
12+
else
13+
update employees_test
14+
set salary = nvl(salary,0) + sales_amt*commission
15+
where employee_id = emp_id;
16+
end if;
17+
end;
18+
/

Diff for: source/award_bonus/employees_test.sql

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
create table employees_test (employee_id number primary key, commission_pct number, salary number);
2+
insert into employees_test values (1001, 0.2, 8400);
3+
insert into employees_test values (1002, 0.25, 6000);
4+
insert into employees_test values (1003, 0.3, 5000);
5+
-- next employee is not in the sales department, thus is not on commission.
6+
insert into employees_test values (1004, null, 10000);
7+
commit;

Diff for: source/between_string/betwnstr.fnc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
create or replace function betwnstr( a_string varchar2, a_start_pos integer, a_end_pos integer ) return varchar2 is
2+
l_start_pos pls_integer := a_start_pos;
3+
begin
4+
if l_start_pos = 0 then
5+
l_start_pos := 1;
6+
end if;
7+
return substr( a_string, l_start_pos, a_end_pos - l_start_pos + 1);
8+
end;
9+
/

Diff for: source/install.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -ev
4+
5+
"$ORACLE_HOME/bin/sqlplus" -L -S ${DB_USER}/${DB_PASS} <<SQL
6+
whenever sqlerror exit failure rollback
7+
whenever oserror exit failure rollback
8+
9+
@source/award_bonus/employees_test.sql
10+
@source/award_bonus/award_bonus.prc
11+
12+
@source/between_string/betwnstr.fnc
13+
14+
@source/remove_rooms_by_name/rooms.sql
15+
@source/remove_rooms_by_name/remove_rooms_by_name.prc
16+
17+
exit
18+
SQL

Diff for: source/remove_rooms_by_name/remove_rooms_by_name.prc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
create or replace procedure remove_rooms_by_name( l_name rooms.name%type ) is
2+
begin
3+
if l_name is null then
4+
raise program_error;
5+
end if;
6+
delete from rooms where name like l_name;
7+
end;
8+
/

Diff for: source/remove_rooms_by_name/rooms.sql

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
create table rooms (
2+
room_key number primary key,
3+
name varchar2(100)
4+
);
5+
6+
create table room_contents (
7+
contents_key number primary key,
8+
room_key number,
9+
name varchar2(100),
10+
constraint fk_rooms foreign key (room_key) references rooms (room_key)
11+
);

Diff for: test/award_bonus/run_award_bonus_test.sql

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@@employees_test.sql
2+
@@award_bonus.sql
3+
@@test_award_bonus.pkg
4+
5+
set serveroutput on size unlimited format truncated
6+
7+
exec ut.run(user||'.test_award_bonus');
8+
9+
drop package test_award_bonus;
10+
drop procedure award_bonus;
11+
drop table employees_test;

Diff for: test/award_bonus/test_award_bonus.pkb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
create or replace package body test_award_bonus as
2+
3+
gc_test_employee constant integer := -1;
4+
gc_salary constant number := 4500;
5+
gc_commision_pct constant number := 0.2;
6+
7+
procedure update_employee_salary is
8+
results sys_refcursor;
9+
expected sys_refcursor;
10+
not_affected sys_refcursor;
11+
c_sales_amount constant number := 1000;
12+
begin
13+
--arrange
14+
open expected for
15+
select (salary + c_sales_amount * gc_commision_pct) as new_salary
16+
from employees_test where employee_id = gc_test_employee;
17+
18+
open not_affected for
19+
select * from employees_test where employee_id <> gc_test_employee;
20+
21+
--act
22+
award_bonus(emp_id => gc_test_employee, sales_amt => c_sales_amount);
23+
24+
--assert
25+
open results for
26+
select salary as new_salary
27+
from employees_test where employee_id = gc_test_employee;
28+
29+
ut.expect( results ).to_( equal( expected ) );
30+
31+
open results for
32+
select * from employees_test where employee_id != gc_test_employee;
33+
34+
ut.expect( results ).to_( equal( not_affected ) );
35+
end;
36+
37+
procedure fail_on_null_bonus is
38+
begin
39+
award_bonus(emp_id => gc_test_employee, sales_amt => null);
40+
ut.expect( sqlcode ).not_to( equal( 0 ) );
41+
exception
42+
when others then
43+
ut.expect( sqlcode ).not_to( equal( 0 ) );
44+
end;
45+
46+
procedure add_employee( emp_id number, comm_pct number, sal number ) is
47+
begin
48+
insert into employees_test (employee_id, commission_pct, salary)
49+
values (emp_id, comm_pct, sal);
50+
end;
51+
52+
procedure add_test_employee is
53+
begin
54+
add_employee(gc_test_employee, 0.2, gc_salary);
55+
end;
56+
57+
procedure add_employee_with_null_comm is
58+
begin
59+
add_employee(gc_test_employee, null, gc_salary);
60+
end;
61+
62+
end;
63+
/

Diff for: test/award_bonus/test_award_bonus.pks

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
create or replace package test_award_bonus as
2+
3+
-- %suite
4+
-- %displayname(Award bonus)
5+
6+
-- %test
7+
-- %displayname(Sets new salary as pct commision * sales amount)
8+
-- %beforetest(add_test_employee)
9+
procedure update_employee_salary;
10+
11+
-- %test
12+
-- %displayname(Raises exception if null bonus is passed)
13+
-- %beforetest(add_employee_with_null_comm)
14+
procedure fail_on_null_bonus;
15+
16+
procedure add_test_employee;
17+
18+
procedure add_employee_with_null_comm;
19+
20+
end;
21+
/

Diff for: test/between_string/run_betwnstr_test.sql

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@@betwnstr.sql
2+
@@test_betwnstr.pkg
3+
4+
set serveroutput on size unlimited format truncated
5+
6+
exec ut.run(user||'.test_betwnstr');
7+
8+
drop package test_betwnstr;
9+
drop function betwnstr;
10+

Diff for: test/between_string/run_betwnstr_test_coverage.sql

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set trimspool on
2+
set linesize 32767
3+
set pagesize 0
4+
set long 200000000
5+
set longchunksize 1000000
6+
@@betwnstr.sql
7+
@@test_betwnstr.pkg
8+
9+
set serveroutput on size unlimited format truncated
10+
11+
set feedback off
12+
set termout off
13+
spool coverage.html
14+
exec ut.run(user, ut_coverage_html_reporter(a_project_name=>'Demo of between string function tests', a_include_object_list=>ut_varchar2_list('ut3.betwnstr')));
15+
spool off
16+
17+
18+
drop package test_betwnstr;
19+
drop function betwnstr;
20+
21+
exit

Diff for: test/between_string/test_betwnstr.pkb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
create or replace package body test_betwnstr as
2+
3+
procedure normal_case is
4+
begin
5+
ut.expect( betwnstr( '1234567', 2, 5 ) ).to_equal('2345');
6+
end;
7+
8+
procedure zero_start_position is
9+
begin
10+
ut.expect( betwnstr( '1234567', 0, 5 ) ).to_( equal('12345') );
11+
end;
12+
13+
procedure big_end_position is
14+
begin
15+
ut.expect( betwnstr( '1234567', 0, 500 ) ).to_( equal('1234567') );
16+
end;
17+
18+
procedure null_string is
19+
begin
20+
ut.expect( betwnstr( null, 2, 5 ) ).to_( be_null );
21+
end;
22+
23+
procedure disabled_test is
24+
begin
25+
ut.expect( betwnstr( null, null, null) ).not_to( be_null );
26+
end;
27+
28+
end;
29+
/

Diff for: test/between_string/test_betwnstr.pks

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
create or replace package test_betwnstr as
2+
3+
-- %suite(Between string function)
4+
5+
-- %test(Returns substring from start position to end position)
6+
procedure normal_case;
7+
8+
-- %test(Returns substring when start position is zero)
9+
procedure zero_start_position;
10+
11+
-- %test(Returns string until end if end position is greater than string length)
12+
procedure big_end_position;
13+
14+
-- %test(Returns null for null input string value)
15+
procedure null_string;
16+
17+
-- %test(Demo of a disabled test)
18+
-- %disabled
19+
procedure disabled_test;
20+
21+
end;
22+
/

Diff for: test/install.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -ev
4+
5+
"$ORACLE_HOME/bin/sqlplus" -L -S ${DB_USER}/${DB_PASS} <<SQL
6+
whenever sqlerror exit failure rollback
7+
whenever oserror exit failure rollback
8+
9+
@test/award_bonus/test_award_bonus.pks
10+
@test/award_bonus/test_award_bonus.pkb
11+
12+
@test/between_string/test_betwnstr.pks
13+
@test/between_string/test_betwnstr.pkb
14+
15+
@test/remove_rooms_by_name/test_remove_rooms_by_name.pks
16+
@test/remove_rooms_by_name/test_remove_rooms_by_name.pkb
17+
18+
exit
19+
SQL

0 commit comments

Comments
 (0)