From 431eee7edf83bb53eb82fd7a45a0a9e45fe28d36 Mon Sep 17 00:00:00 2001 From: MickeM Date: Tue, 2 Jul 2019 15:40:46 +0200 Subject: [PATCH] Updated gilded rose to utplsql version 3 Also rewrote the texttest --- plsql/item_with_id.sql | 50 ------------------------ plsql/run_tests.sql | 5 +++ plsql/texttest.pkb | 78 +++++++++++++++++++++++++++++++++++++ plsql/texttest.pks | 12 ++++++ plsql/texttest_fixture.sql | 36 ----------------- plsql/ut_update_quality.pkb | 40 ++++++++----------- plsql/ut_update_quality.pks | 9 ++++- plsql/ut_update_quality.sql | 5 --- 8 files changed, 118 insertions(+), 117 deletions(-) delete mode 100644 plsql/item_with_id.sql create mode 100644 plsql/run_tests.sql create mode 100644 plsql/texttest.pkb create mode 100644 plsql/texttest.pks delete mode 100644 plsql/texttest_fixture.sql delete mode 100644 plsql/ut_update_quality.sql diff --git a/plsql/item_with_id.sql b/plsql/item_with_id.sql deleted file mode 100644 index 8d431257..00000000 --- a/plsql/item_with_id.sql +++ /dev/null @@ -1,50 +0,0 @@ -PROMPT Creating Table 'ITEM' with auto-increment primary key 'ID' - -BEGIN - EXECUTE IMMEDIATE 'DROP TABLE item'; -EXCEPTION - WHEN OTHERS THEN - IF SQLCODE != -942 THEN - RAISE; - END IF; -END; - -CREATE TABLE item - ( - id NUMBER(6) NOT NULL, - name VARCHAR2(100) NOT NULL, - sell_in NUMBER(6) NOT NULL, - quality NUMBER(6) NOT NULL - ); -/ - -ALTER TABLE item ADD ( - CONSTRAINT item_pk PRIMARY KEY (ID)); -/ - -BEGIN - EXECUTE IMMEDIATE 'DROP SEQUENCE item_id_seq'; -EXCEPTION - WHEN OTHERS THEN - IF SQLCODE != -2289 THEN - RAISE; - END IF; -END; - -CREATE SEQUENCE item_id_seq - INCREMENT BY 1 - START WITH 1 - MAXVALUE 999999 - MINVALUE 1 - NOCYCLE; -/ - -CREATE OR REPLACE TRIGGER item_bis_trg - BEFORE INSERT ON item - FOR EACH ROW -BEGIN - SELECT item_id_seq.NEXTVAL INTO :new.id FROM dual; -END; -/ - -SHOW ERRORS; diff --git a/plsql/run_tests.sql b/plsql/run_tests.sql new file mode 100644 index 00000000..a36d29c4 --- /dev/null +++ b/plsql/run_tests.sql @@ -0,0 +1,5 @@ +exec DBMS_SESSION.RESET_PACKAGE; +set serveroutput on; +exec DBMS_OUTPUT.ENABLE(1000000); + +exec ut.run(USER||':gilded_rose_tests'||''); \ No newline at end of file diff --git a/plsql/texttest.pkb b/plsql/texttest.pkb new file mode 100644 index 00000000..cbd2e0e3 --- /dev/null +++ b/plsql/texttest.pkb @@ -0,0 +1,78 @@ +CREATE OR REPLACE PACKAGE BODY texttest IS + co_lf CONSTANT VARCHAR2(1) := CHR(10); + + PROCEDURE put_line(p_buffer IN OUT NOCOPY VARCHAR2, p_line VARCHAR2) IS + BEGIN + p_buffer := p_buffer || p_line || co_lf; + END put_line; + + PROCEDURE setup IS + BEGIN + DELETE FROM ITEM; + + new_item('+5 Dexterity Vest', 10, 20); + new_item('Aged Brie', 2, 0); + new_item('Elixir of the Mongoose', 5, 7); + new_item('Sulfuras, Hand of Ragnaros', 0, 80); + new_item('Sulfuras, Hand of Ragnaros', -1, 80); + new_item('Backstage passes to a TAFKAL80ETC concert', 15, 20); + new_item('Backstage passes to a TAFKAL80ETC concert', 10, 49); + new_item('Backstage passes to a TAFKAL80ETC concert', 5, 49); + -- this conjured item does not work properly yet ; + new_item('Conjured Mana Cake', 3, 6); + END setup; + + PROCEDURE main_test IS + v_result VARCHAR2(4000) := ''; + + v_expected VARCHAR2(4000) := ''; + + l_days NUMBER(3); + + CURSOR c_items IS SELECT name, sell_in, quality FROM item; + + l_item c_items%ROWTYPE; + BEGIN + put_line(v_expected, 'OMGHAI!'); + put_line(v_expected, '-------- day 0 --------'); + put_line(v_expected, 'name, sellIn, quality'); + put_line(v_expected, '+5 Dexterity Vest, 10, 20' || co_lf || 'Aged Brie, 2, 0'); + put_line(v_expected, 'Elixir of the Mongoose, 5, 7'); + put_line(v_expected, 'Sulfuras, Hand of Ragnaros, 0, 80'); + put_line(v_expected, 'Sulfuras, Hand of Ragnaros, -1, 80'); + put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 15, 20'); + put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 10, 49'); + put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 5, 49'); + put_line(v_expected, 'Conjured Mana Cake, 3, 6'); + put_line(v_expected, '-------- day 1 --------'); + put_line(v_expected, 'name, sellIn, quality'); + put_line(v_expected, '+5 Dexterity Vest, 9, 19'); + put_line(v_expected, 'Aged Brie, 1, 1'); + put_line(v_expected, 'Elixir of the Mongoose, 4, 6'); + put_line(v_expected, 'Sulfuras, Hand of Ragnaros, 0, 80'); + put_line(v_expected, 'Sulfuras, Hand of Ragnaros, -1, 80'); + put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 14, 21'); + put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 9, 50'); + put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 4, 50'); + put_line(v_expected, 'Conjured Mana Cake, 2, 5'); + + put_line(v_result, 'OMGHAI!'); + l_days := 2; + + FOR i IN 0 .. l_days - 1 + LOOP + put_line(v_result, '-------- day ' || TO_CHAR(i) || ' --------'); + put_line(v_result, 'name, sellIn, quality'); + + FOR l_item IN c_items + LOOP + put_line(v_result, l_item.name || ', ' || l_item.sell_in || ', ' || l_item.quality); + END LOOP; + + update_quality(); + END LOOP; + + ut.expect(v_result).to_equal(v_expected); + END; +END texttest; +/ \ No newline at end of file diff --git a/plsql/texttest.pks b/plsql/texttest.pks new file mode 100644 index 00000000..7f65f2d9 --- /dev/null +++ b/plsql/texttest.pks @@ -0,0 +1,12 @@ +CREATE OR REPLACE PACKAGE texttest IS + -- %suite(texttest) + -- %suitepath(gilded_rose_tests) + -- %rollback(manual) + + -- %beforeall + PROCEDURE setup; + + -- %test(main test) + PROCEDURE main_test; +END texttest; +/ \ No newline at end of file diff --git a/plsql/texttest_fixture.sql b/plsql/texttest_fixture.sql deleted file mode 100644 index 6d2bbeef..00000000 --- a/plsql/texttest_fixture.sql +++ /dev/null @@ -1,36 +0,0 @@ -SET SERVEROUTPUT ON; - -DELETE FROM item; - -DECLARE - l_days NUMBER(3); - CURSOR c_items IS - SELECT name, sell_in, quality FROM item; - l_item c_items%ROWTYPE; -BEGIN - DBMS_OUTPUT.PUT_LINE('OMGHAI!'); - - new_item('+5 Dexterity Vest', 10, 20); - new_item('Aged Brie', 2, 0); - new_item('Elixir of the Mongoose', 5, 7); - new_item('Sulfuras, Hand of Ragnaros', 0, 80); - new_item('Sulfuras, Hand of Ragnaros', -1, 80); - new_item('Backstage passes to a TAFKAL80ETC concert', 15, 20); - new_item('Backstage passes to a TAFKAL80ETC concert', 10, 49); - new_item('Backstage passes to a TAFKAL80ETC concert', 5, 49); - -- this conjured item does not work properly yet ; - new_item('Conjured Mana Cake', 3, 6); - - l_days := 2; - - FOR i IN 0 .. l_days - 1 - LOOP - DBMS_OUTPUT.PUT_LINE('-------- day ' || TO_CHAR(i) || ' --------'); - DBMS_OUTPUT.PUT_LINE('name, sellIn, quality'); - FOR l_item IN c_items LOOP - DBMS_OUTPUT.PUT_LINE(l_item.name || ', ' || l_item.sell_in || ', ' || l_item.quality); - END LOOP; - DBMS_OUTPUT.PUT_LINE(''); - update_quality(); - END LOOP; -END; diff --git a/plsql/ut_update_quality.pkb b/plsql/ut_update_quality.pkb index 99520518..95e4b2e3 100644 --- a/plsql/ut_update_quality.pkb +++ b/plsql/ut_update_quality.pkb @@ -1,27 +1,19 @@ -CREATE OR REPLACE PACKAGE BODY ut_update_quality -IS +CREATE OR REPLACE PACKAGE BODY ut_update_quality IS + PROCEDURE cleanup_before_each IS + BEGIN + DELETE FROM item; + END; - PROCEDURE ut_setup IS - BEGIN - DELETE FROM item; - END; - - PROCEDURE ut_teardown IS - BEGIN - NULL; - END; - - PROCEDURE ut_foo - IS - l_name item.name%TYPE; - BEGIN - new_item('foo', 0, 0); - - update_quality(); - - SELECT name INTO l_name FROM item; - utAssert.eq('name did change', l_name, 'fixme'); - END ut_foo; + PROCEDURE ut_foo IS + l_name item.name%TYPE; + BEGIN + new_item('foo', 0, 0); + update_quality(); + + SELECT name INTO l_name FROM item; + + ut.expect(l_name, a_message => 'name did change').to_equal('fixme'); + END ut_foo; END ut_update_quality; -/ +/ \ No newline at end of file diff --git a/plsql/ut_update_quality.pks b/plsql/ut_update_quality.pks index db0a8f1e..167210c3 100644 --- a/plsql/ut_update_quality.pks +++ b/plsql/ut_update_quality.pks @@ -1,8 +1,13 @@ CREATE OR REPLACE PACKAGE ut_update_quality IS - PROCEDURE ut_setup; - PROCEDURE ut_teardown; + -- %suite(UT_REGRESSION_TEST) + -- %suitepath(gilded_rose_tests) + -- %rollback(manual) + + -- %beforeeach + PROCEDURE cleanup_before_each; + -- %test(Foo test) PROCEDURE ut_foo; END ut_update_quality; / diff --git a/plsql/ut_update_quality.sql b/plsql/ut_update_quality.sql deleted file mode 100644 index 2d5cd6a7..00000000 --- a/plsql/ut_update_quality.sql +++ /dev/null @@ -1,5 +0,0 @@ --- unit test using utPLSQL 2.2.1, see http://utplsql.sourceforge.net/ ; --- test package must be named like the procedure we want to test ; - -EXEC utplsql.test ('update_quality', recompile_in => FALSE); --- check DBMS_OUTPUT for output ;