Humble Trader

Saturday, September 16, 2006

Country Dimension - m_s2s_countries_test.sql

SET SERVEROUTPUT ON SIZE 1000000;

DECLARE
l_run_no NUMBER;
l_raw_html_count NUMBER;
l_parsed_html_count NUMBER;
l_mapping_histories_count NUMBER;
l_s_countries_count NUMBER;
l_row_data VARCHAR2(4000);
l_passed BOOLEAN := TRUE;
BEGIN
-- Initialisation code.
dbms_output.put_line('-');
dbms_output.put_line('- Fetch countries data from web page using ' ||
'get_html.fetch_html:');

get_html.fetch_html('COUNTRIES');

commit;

dbms_output.put_line('- Fetch countries data done.');

SELECT COUNT(*)
INTO l_raw_html_count
FROM raw_html
WHERE run_no =
(SELECT MAX(run_no)
FROM mapping_histories);

dbms_output.put_line('- ' || l_raw_html_count ||
' html pieces fetched');
dbms_output.put_line('-');

dbms_output.put_line('- Parse countries data from web page using ' ||
'get_html.parse_html:');

get_html.parse_html;

commit;

dbms_output.put_line('- Parse countries data done.');

SELECT COUNT(*)
INTO l_parsed_html_count
FROM parsed_html
WHERE parse_run_no =
(SELECT MAX(parse_run_no)
FROM html_parse_passes
WHERE raw_run_no =
(SELECT MAX(run_no)
FROM html_page_access
WHERE html_page_name = 'COUNTRIES'))
AND raw_run_no =
(SELECT MAX(run_no)
FROM html_page_access
WHERE html_page_name = 'COUNTRIES');

dbms_output.put_line('- ' || l_parsed_html_count ||
' parsed html rows');
dbms_output.put_line('-');

dbms_output.put_line('+- PROCEDURE m_s2s_countries.map test start:');
dbms_output.put_line('|');

dbms_output.put_line
('| Test 1: Pass : NO PARAMETERS');
dbms_output.put_line('|');
dbms_output.put_line
('| Expected Result: Inserts a row into MAPPING_HISTORIES');
dbms_output.put_line
('| Expected Result: Inserts 240 rows into S_COUNTRIES');
dbms_output.put_line('|');

m_s2s_countries.map;

SELECT MAX(run_no)
INTO l_run_no
FROM mapping_histories
WHERE mapping_library = 'M_S2S_COUNTRIES';

SELECT COUNT(*)
INTO l_mapping_histories_count
FROM mapping_histories
WHERE run_no = l_run_no;

dbms_output.put_line('| Result: MAPPING_HISTORIES row count = ' ||
l_mapping_histories_count);
dbms_output.put_line('| MAPPING_HISTORIES data :');

SELECT '| [' || run_no || ', ' || mapping_library || ', ' ||
TO_CHAR(start_tsp, 'DD-MON-YYYY HH24:MI:SS') ||
', ' || NVL(TO_CHAR(end_tsp, 'DD-MON-YYYY HH24:MI:SS'), '*NULL*') ||
']'
INTO l_row_data
FROM mapping_histories
WHERE run_no = l_run_no;

dbms_output.put_line(l_row_data);

SELECT COUNT(*)
INTO l_s_countries_count
FROM s_countries;

dbms_output.put_line('| S_COUNTRIES row count = ' ||
l_s_countries_count);
dbms_output.put_line('|');

dbms_output.put_line('| +----------+');
IF l_mapping_histories_count = 1
AND
l_s_countries_count = 240
THEN
dbms_output.put_line('| | PASSED |');
ELSE
dbms_output.put_line('| | FAILED |');
l_passed := FALSE;
END IF;
dbms_output.put_line('| +----------+');

dbms_output.put_line('|');
dbms_output.put_line('+- PROCEDURE m_s2s_countries.map test end:');

dbms_output.put_line('-');
dbms_output.put_line('- Overall result:');
dbms_output.put_line('-');
dbms_output.put_line('- +----------+');
IF l_passed = TRUE
THEN
dbms_output.put_line('- | PASSED |');
ELSE
dbms_output.put_line('- | FAILED |');
END IF;
dbms_output.put_line('- +----------+');
dbms_output.put_line('-');

END;
/

0 Comments:

Post a Comment

<< Home