diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/sp_mamba_dim_agegroup.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/sp_mamba_dim_agegroup.sql index d00b5051..3363fe67 100644 --- a/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/sp_mamba_dim_agegroup.sql +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/sp_mamba_dim_agegroup.sql @@ -2,4 +2,6 @@ CALL sp_mamba_dim_agegroup_create(); CALL sp_mamba_dim_agegroup_insert(); -CALL sp_mamba_dim_agegroup_update(); \ No newline at end of file +CALL sp_mamba_dim_agegroup_update(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test.sql new file mode 100644 index 00000000..9d83e868 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_agegroup_test_create(); +CALL sp_mamba_dim_agegroup_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_create.sql new file mode 100644 index 00000000..5b7226d3 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_create.sql @@ -0,0 +1,68 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_agegroup_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_agegroup_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test + DROP TABLE IF EXISTS mamba_dim_agegroup; + + -- Step 3: Call the sp_mamba_dim_agegroup_create procedure to create the table + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_agegroup table via sp_mamba_dim_agegroup_create.'; + END; + + -- Call the stored procedure to create the table + CALL sp_mamba_dim_agegroup_create(); + END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_agegroup') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_agegroup was not created by sp_mamba_dim_agegroup_create.'; + END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'id, age, datim_agegroup, datim_age_val, normal_agegroup, normal_age_val'; + DECLARE actual_columns VARCHAR(255); + + SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns + FROM information_schema.columns + WHERE table_name = 'mamba_dim_agegroup'; + + -- Check if the actual columns match the expected columns + IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: mamba_dim_agegroup table created successfully via sp_mamba_dim_agegroup_create with the correct structure.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_agegroup_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_create; + + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_insert.sql new file mode 100644 index 00000000..d25ed1db --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_agegroup/test/sp_mamba_dim_agegroup_test_insert.sql @@ -0,0 +1,72 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_agegroup_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_agegroup_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE test_failed INT DEFAULT 0; + DECLARE failed_message VARCHAR(255) DEFAULT ''; + + -- Step 2: Clean up existing data in the table before running the test + DELETE FROM mamba_dim_agegroup; + + -- Step 3: Insert test data into the source table (if necessary) + -- Assuming the source table has already existing data and no new data is inserted here + -- (If source data needs setup, do it here by inserting test data) + + -- Step 4: Call the sp_mamba_dim_agegroup_insert procedure to insert the data + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_agegroup via sp_mamba_dim_agegroup_insert.'; + END; + + -- Call the stored procedure to insert data + CALL sp_mamba_dim_agegroup_insert(); + END; + + -- Step 5: Validate that data has been inserted into the mamba_dim_agegroup table + DECLARE row_count INT; + + SELECT COUNT(*) INTO row_count FROM mamba_dim_agegroup; + + -- Check if data has been inserted + IF row_count = 0 THEN + SET test_failed = 1; + SET failed_message = 'No data was inserted into the mamba_dim_agegroup table.'; + END IF; + + -- Step 6: Optionally, validate some specific values in the inserted rows (e.g., check a specific age group) + DECLARE test_agegroup VARCHAR(50); + SELECT datim_agegroup INTO test_agegroup FROM mamba_dim_agegroup LIMIT 1; + + IF test_agegroup IS NULL THEN + SET test_failed = 1; + SET failed_message = 'Data in mamba_dim_agegroup is not as expected.'; + END IF; + + -- Step 7: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: Data successfully inserted into mamba_dim_agegroup via sp_mamba_dim_agegroup_insert.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_agegroup_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_agegroup_insert; + + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test.sql new file mode 100644 index 00000000..808437a1 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test.sql @@ -0,0 +1,5 @@ +-- $BEGIN + CALL sp_mamba_dim_concept_test_create; + CALL sp_mamba_dim_concept_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_create.sql new file mode 100644 index 00000000..6f965ac9 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_create.sql @@ -0,0 +1,64 @@ +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_create +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test + DROP TABLE IF EXISTS mamba_dim_concept; + + -- Step 3: Execute the procedure to be tested + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Procedure sp_mamba_dim_concept_create failed to execute.'; + END; + + -- Call the procedure to create the table + CALL sp_mamba_dim_concept_create(); + END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_concept was not created.'; + END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'concept_id, name, description, date_created, date_retired, retired, retire_reason, retired_by, incremental_record'; + DECLARE actual_columns VARCHAR(255); + + SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns + FROM information_schema.columns + WHERE table_name = 'mamba_dim_concept'; + + -- Check if the actual columns match expected columns + IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: sp_mamba_dim_concept_create executed successfully and table created.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_create; diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_insert.sql new file mode 100644 index 00000000..b4ba453a --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept/test/sp_mamba_dim_concept_test_insert.sql @@ -0,0 +1,62 @@ +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_insert +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clear relevant test data in the target table for isolation +TRUNCATE TABLE mamba_dim_concept; + +-- Step 3: Ensure the ETL settings table (_mamba_etl_user_settings) has relevant locales +DELETE FROM _mamba_etl_user_settings WHERE concepts_locale IN ('en', 'fr'); +INSERT INTO _mamba_etl_user_settings (concepts_locale) VALUES ('en'), ('fr'); + +-- Step 4: Execute the procedure to be tested +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Procedure sp_mamba_dim_concept_insert failed.'; +END; + + -- Call the procedure to insert data +CALL sp_mamba_dim_concept_insert(); +END; + + -- Step 5: Validate the data inserted into `mamba_dim_concept` + -- Assuming existing source data matches the criteria for insert + IF NOT EXISTS (SELECT * FROM mamba_dim_concept WHERE concept_id IN (SELECT concept_id FROM openmrs.concept WHERE voided = 0) LIMIT 1) THEN + SET test_failed = 1; + SET failed_message = 'No expected rows found in mamba_dim_concept after insert.'; +END IF; + + -- Check if there are duplicate entries for existing concepts + IF (SELECT COUNT(*) FROM mamba_dim_concept WHERE concept_id IN (SELECT concept_id FROM openmrs.concept WHERE voided = 0)) > + (SELECT COUNT(*) FROM openmrs.concept WHERE voided = 0) THEN + SET test_failed = 1; +SET failed_message = 'Unexpected duplicate entries found in mamba_dim_concept.'; +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: sp_mamba_dim_concept_insert executed successfully.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_insert; diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test.sql new file mode 100644 index 00000000..0fa64b75 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test.sql @@ -0,0 +1,5 @@ +-- $BEGIN + CALL sp_mamba_dim_concept_answer_test_create(); + CALL sp_mamba_dim_concept_answer_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_create.sql new file mode 100644 index 00000000..25b731ae --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_create.sql @@ -0,0 +1,68 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_answer_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_answer_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_answer_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test + DROP TABLE IF EXISTS mamba_dim_concept_answer; + + -- Step 3: Call the sp_mamba_dim_concept_answer_create procedure to create the table + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_concept_answer table via sp_mamba_dim_concept_answer_create.'; + END; + + -- Call the stored procedure to create the table + CALL sp_mamba_dim_concept_answer_create(); + END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept_answer') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_concept_answer was not created by sp_mamba_dim_concept_answer_create.'; + END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'concept_answer_id, concept_id, answer_concept, answer_drug, incremental_record'; + DECLARE actual_columns VARCHAR(255); + + SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns + FROM information_schema.columns + WHERE table_name = 'mamba_dim_concept_answer'; + + -- Check if the actual columns match the expected columns + IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: mamba_dim_concept_answer table created successfully via sp_mamba_dim_concept_answer_create with the correct structure.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_answer_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_answer_create; + + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_insert.sql new file mode 100644 index 00000000..dee46c7e --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_answer/test/sp_mamba_dim_concept_answer_test_insert.sql @@ -0,0 +1,78 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_answer_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_answer_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_answer_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing records before running the test + DELETE FROM mamba_dim_concept_answer; + + -- Step 3: Prepare test data + INSERT INTO mamba_dim_concept_answer (concept_answer_id, concept_id, answer_concept, answer_drug, incremental_record) + VALUES + (1, 101, 1001, 2001, 0), + (2, 102, 1002, NULL, 0), + (3, 103, NULL, 2003, 0); + + -- Step 4: Call the sp_mamba_dim_concept_answer_insert procedure to insert data + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_concept_answer table via sp_mamba_dim_concept_answer_insert.'; + END; + + -- Call the stored procedure to insert data + CALL sp_mamba_dim_concept_answer_insert(); + END; + + -- Step 5: Validate the data insertion + DECLARE expected_count INT DEFAULT 3; + DECLARE actual_count INT; + + SELECT COUNT(*) INTO actual_count FROM mamba_dim_concept_answer; + + IF actual_count != expected_count THEN + SET test_failed = 1; + SET failed_message = CONCAT('Data insertion failed. Expected row count: ', expected_count, ', Actual row count: ', actual_count); + END IF; + + -- Step 6: Check if the inserted values match the expected values + DECLARE actual_answer_concept INT; + DECLARE actual_answer_drug INT; + + SELECT answer_concept, answer_drug INTO actual_answer_concept, actual_answer_drug + FROM mamba_dim_concept_answer + WHERE concept_answer_id = 1; + + IF actual_answer_concept != 1001 OR actual_answer_drug != 2001 THEN + SET test_failed = 1; + SET failed_message = 'Inserted values do not match expected values for concept_answer_id = 1.'; + END IF; + + -- Step 7: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: Data inserted successfully into mamba_dim_concept_answer via sp_mamba_dim_concept_answer_insert.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_answer_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_answer_insert; + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test.sql new file mode 100644 index 00000000..69944b55 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test.sql @@ -0,0 +1,5 @@ +-- $BEGIN +CALL sp_mamba_dim_concept_datatype_test_create(); +CALL sp_mamba_dim_concept_datatype_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test_create.sql new file mode 100644 index 00000000..e7b56d25 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test_create.sql @@ -0,0 +1,67 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_datatype_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_datatype_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_datatype_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test + DROP TABLE IF EXISTS mamba_dim_concept_datatype; + + -- Step 3: Call the sp_mamba_dim_concept_datatype_create procedure to create the table + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_concept_datatype table via sp_mamba_dim_concept_datatype_create.'; + END; + + -- Call the stored procedure to create the table + CALL sp_mamba_dim_concept_datatype_create(); + END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept_datatype') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_concept_datatype was not created by sp_mamba_dim_concept_datatype_create.'; + END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'concept_datatype_id, name, description, incremental_record'; + DECLARE actual_columns VARCHAR(255); + + SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns + FROM information_schema.columns + WHERE table_name = 'mamba_dim_concept_datatype'; + + -- Check if the actual columns match the expected columns + IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: mamba_dim_concept_datatype table created successfully via sp_mamba_dim_concept_datatype_create with the correct structure.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_datatype_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_datatype_create; + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test_insert.sql new file mode 100644 index 00000000..950fd51b --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_datatype/test/sp_mamba_dim_concept_datatype_test_insert.sql @@ -0,0 +1,59 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_datatype_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_datatype_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_datatype_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing data before running the test + DELETE FROM mamba_dim_concept_datatype; -- Clean up target table + + -- Step 3: Call the sp_mamba_dim_concept_datatype_insert procedure to insert data + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_concept_datatype via sp_mamba_dim_concept_datatype_insert.'; + END; + + -- Call the stored procedure to insert data + CALL sp_mamba_dim_concept_datatype_insert(); + END; + + -- Step 4: Validate if data was inserted into the table + IF (SELECT COUNT(*) FROM mamba_dim_concept_datatype) = 0 THEN + SET test_failed = 1; + SET failed_message = 'No data was inserted into mamba_dim_concept_datatype by sp_mamba_dim_concept_datatype_insert.'; + END IF; + + -- Step 5: Optionally, you can validate specific data inserted, for example: + IF NOT EXISTS (SELECT 1 FROM mamba_dim_concept_datatype WHERE name = 'Numeric' AND description = 'Numeric data type') THEN + SET test_failed = 1; + SET failed_message = 'Expected data not found in mamba_dim_concept_datatype after sp_mamba_dim_concept_datatype_insert.'; + END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: Data inserted successfully into mamba_dim_concept_datatype via sp_mamba_dim_concept_datatype_insert.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_datatype_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_datatype_insert; + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test.sql new file mode 100644 index 00000000..3c41eb0f --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_concept_name_test_create(); +CALL sp_mamba_dim_concept_name_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test_create.sql new file mode 100644 index 00000000..8fb75aca --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test_create.sql @@ -0,0 +1,81 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_name_create +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_name_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_name_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up pre-existing table if it exists + IF (EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept_name' AND table_schema = DATABASE())) THEN + DROP TABLE mamba_dim_concept_name; + END IF; + + -- Step 3: Call the procedure to be tested + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Procedure failed to create the table.'; + END; + + -- Call the procedure to create the table + CALL sp_mamba_dim_concept_name_create(); + END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_concept_name' AND table_schema = DATABASE()) THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_concept_name was not created.'; + END IF; + + -- Step 5: Check column definitions + IF NOT EXISTS (SELECT * FROM information_schema.columns + WHERE table_name = 'mamba_dim_concept_name' AND column_name = 'concept_name_id' AND data_type = 'int') THEN + SET test_failed = 1; + SET failed_message = 'Column concept_name_id is not defined as INT.'; + END IF; + + IF NOT EXISTS (SELECT * FROM information_schema.columns + WHERE table_name = 'mamba_dim_concept_name' AND column_name = 'name' AND data_type = 'varchar' AND character_maximum_length = 255) THEN + SET test_failed = 1; + SET failed_message = 'Column name is not defined as VARCHAR(255).'; + END IF; + + IF NOT EXISTS (SELECT * FROM information_schema.columns + WHERE table_name = 'mamba_dim_concept_name' AND column_name = 'locale' AND data_type = 'varchar' AND character_maximum_length = 50) THEN + SET test_failed = 1; + SET failed_message = 'Column locale is not defined as VARCHAR(50).'; + END IF; + + -- Step 6: Check for existence of indexes + IF NOT EXISTS (SELECT * FROM information_schema.statistics WHERE table_name = 'mamba_dim_concept_name' AND index_name = 'mamba_idx_concept_id') THEN + SET test_failed = 1; + SET failed_message = 'Index mamba_idx_concept_id is missing.'; + END IF; + + -- Step 7: Return result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: sp_mamba_dim_concept_name_create executed successfully.' AS result; + END IF; + + END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_concept_name_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_name_create; + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test_insert.sql new file mode 100644 index 00000000..71d5f194 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_concept_name/test/sp_mamba_dim_concept_name_test_insert.sql @@ -0,0 +1,83 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_name_insert +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_name_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_name_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Setup - Ensure the source table exists and insert test data + TRUNCATE TABLE mamba_source_db.concept_name; + + INSERT INTO mamba_source_db.concept_name (concept_name_id, concept_id, name, locale, locale_preferred, concept_name_type, voided, date_created) + VALUES + (1, 101, 'Test Concept Name 1', 'en', 1, 'FULLY_SPECIFIED', 0, NOW()), -- Valid entry + (2, 102, 'Test Concept Name 2', 'fr', 0, 'FULLY_SPECIFIED', 0, NOW()), -- Valid entry + (3, 103, 'Test Concept Name 3', 'en', 0, 'FULLY_SPECIFIED', 1, NOW()), -- Voided entry + (4, 104, 'Test Concept Name 4', 'es', 0, 'FULLY_SPECIFIED', 0, NOW()); -- Locale not in _mamba_etl_user_settings + + -- Step 3: Insert relevant data into `_mamba_etl_user_settings` for locale filtering + TRUNCATE TABLE _mamba_etl_user_settings; + + INSERT INTO _mamba_etl_user_settings (concepts_locale) + VALUES ('en'), ('fr'); -- Only 'en' and 'fr' should be considered during insert + + -- Step 4: Clear the target table before running the insert procedure + TRUNCATE TABLE mamba_dim_concept_name; + + -- Step 5: Execute the procedure to be tested + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Procedure sp_mamba_dim_concept_name_insert failed.'; + END; + + -- Call the procedure to insert data from mamba_source_db.concept_name into mamba_dim_concept_name + CALL sp_mamba_dim_concept_name_insert(); + END; + + -- Step 6: Validate the data inserted into `mamba_dim_concept_name` + -- Check for the expected rows + IF (SELECT COUNT(*) FROM mamba_dim_concept_name) <> 2 THEN + SET test_failed = 1; + SET failed_message = CONCAT('Expected 2 rows but found ', (SELECT COUNT(*) FROM mamba_dim_concept_name)); + END IF; + + -- Check for expected data + IF NOT EXISTS (SELECT * FROM mamba_dim_concept_name WHERE concept_name_id = 1 AND locale = 'en') THEN + SET test_failed = 1; + SET failed_message = 'Expected row for concept_name_id = 1 with locale = en not found.'; + END IF; + + IF NOT EXISTS (SELECT * FROM mamba_dim_concept_name WHERE concept_name_id = 2 AND locale = 'fr') THEN + SET test_failed = 1; + SET failed_message = 'Expected row for concept_name_id = 2 with locale = fr not found.'; + END IF; + + -- Step 7: Log the test result + IF test_failed = 1 THEN + INSERT INTO _mamba_etl_test_log (test_name, result, message) + VALUES ('test_sp_mamba_dim_concept_name_insert', 'FAILED', failed_message); + ELSE + INSERT INTO _mamba_etl_test_log (test_name, result, message) + VALUES ('test_sp_mamba_dim_concept_name_insert', 'PASSED', 'All expected rows found.'); + END IF; +END // + +DELIMITER ; + +-- Call the unit test +CALL test_sp_mamba_dim_concept_name_insert(); + +-- Optionally, check the log for results +SELECT * FROM _mamba_etl_test_log; + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test.sql new file mode 100644 index 00000000..148b0f7a --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_encounter_test_create(); +CALL sp_mamba_dim_encounter_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test_create.sql new file mode 100644 index 00000000..44e7c3f6 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test_create.sql @@ -0,0 +1,67 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_encounter_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_encounter_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_encounter_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test + DROP TABLE IF EXISTS mamba_dim_encounter; + + -- Step 3: Call the sp_mamba_dim_encounter_create procedure to create the table + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_encounter table via sp_mamba_dim_encounter_create.'; + END; + + -- Call the stored procedure to create the table + CALL sp_mamba_dim_encounter_create(); + END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_encounter') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_encounter was not created by sp_mamba_dim_encounter_create.'; + END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'encounter_id, uuid, encounter_type, encounter_type_uuid, patient_id, visit_id, encounter_datetime, date_created, date_changed, changed_by, date_voided, voided, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + + SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns + FROM information_schema.columns + WHERE table_name = 'mamba_dim_encounter'; + + -- Check if the actual columns match the expected columns + IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + END IF; + + -- Step 6: Return the test result + IF test_failed = 1 THEN + SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; + ELSE + SELECT 'Unit Test Passed: mamba_dim_encounter table created successfully via sp_mamba_dim_encounter_create with the correct structure.' AS result; + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_encounter_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_encounter_create; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test_insert.sql new file mode 100644 index 00000000..fb364d47 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter/test/sp_mamba_dim_encounter_test_insert.sql @@ -0,0 +1,83 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_concept_name_insert +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_concept_name_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_concept_name_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Setup - Ensure the source table exists and insert test data + TRUNCATE TABLE mamba_source_db.concept_name; + + INSERT INTO mamba_source_db.concept_name (concept_name_id, concept_id, name, locale, locale_preferred, concept_name_type, voided, date_created) + VALUES + (1, 101, 'Test Concept Name 1', 'en', 1, 'FULLY_SPECIFIED', 0, NOW()), -- Valid entry + (2, 102, 'Test Concept Name 2', 'fr', 0, 'FULLY_SPECIFIED', 0, NOW()), -- Valid entry + (3, 103, 'Test Concept Name 3', 'en', 0, 'FULLY_SPECIFIED', 1, NOW()), -- Voided entry + (4, 104, 'Test Concept Name 4', 'es', 0, 'FULLY_SPECIFIED', 0, NOW()); -- Locale not in _mamba_etl_user_settings + + -- Step 3: Insert relevant data into `_mamba_etl_user_settings` for locale filtering + TRUNCATE TABLE _mamba_etl_user_settings; + + INSERT INTO _mamba_etl_user_settings (concepts_locale) + VALUES ('en'), ('fr'); -- Only 'en' and 'fr' should be considered during insert + + -- Step 4: Clear the target table before running the insert procedure + TRUNCATE TABLE mamba_dim_concept_name; + + -- Step 5: Execute the procedure to be tested + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Procedure sp_mamba_dim_concept_name_insert failed.'; + END; + + -- Call the procedure to insert data from mamba_source_db.concept_name into mamba_dim_concept_name + CALL sp_mamba_dim_concept_name_insert(); + END; + + -- Step 6: Validate the data inserted into `mamba_dim_concept_name` + -- Check for the expected rows + IF (SELECT COUNT(*) FROM mamba_dim_concept_name) <> 2 THEN + SET test_failed = 1; + SET failed_message = CONCAT('Expected 2 rows but found ', (SELECT COUNT(*) FROM mamba_dim_concept_name)); + END IF; + + -- Check for expected data + IF NOT EXISTS (SELECT * FROM mamba_dim_concept_name WHERE concept_name_id = 1 AND locale = 'en') THEN + SET test_failed = 1; + SET failed_message = 'Expected row for concept_name_id = 1 with locale = en not found.'; + END IF; + + IF NOT EXISTS (SELECT * FROM mamba_dim_concept_name WHERE concept_name_id = 2 AND locale = 'fr') THEN + SET test_failed = 1; + SET failed_message = 'Expected row for concept_name_id = 2 with locale = fr not found.'; + END IF; + + -- Step 7: Log the test result + IF test_failed = 1 THEN + INSERT INTO _mamba_etl_test_log (test_name, result, message) + VALUES ('test_sp_mamba_dim_concept_name_insert', 'FAILED', failed_message); + ELSE + INSERT INTO _mamba_etl_test_log (test_name, result, message) + VALUES ('test_sp_mamba_dim_concept_name_insert', 'PASSED', 'All expected rows found.'); + END IF; +END // + +DELIMITER ; + +-- Call the unit test +CALL test_sp_mamba_dim_concept_name_insert(); + +-- Optionally, check the log for results +SELECT * FROM _mamba_etl_test_log; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test.sql new file mode 100644 index 00000000..026c18cc --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_encounter_type_test_create(); +CALL sp_mamba_dim_encounter_type_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test_create.sql new file mode 100644 index 00000000..119cd07f --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test_create.sql @@ -0,0 +1,68 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_encounter_type_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_encounter_type_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_encounter_type_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_encounter_type; + +-- Step 3: Call the sp_mamba_dim_encounter_type_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_encounter_type table via sp_mamba_dim_encounter_type_create.'; +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_encounter_type_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_encounter_type') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_encounter_type was not created by sp_mamba_dim_encounter_type_create.'; +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'encounter_type_id, name, description, uuid, date_created, date_changed, changed_by, retired, retired_by, date_retired, retire_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_encounter_type'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); +END IF; + + -- Step 6: Return the test result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: mamba_dim_encounter_type table created successfully via sp_mamba_dim_encounter_type_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_encounter_type_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_encounter_type_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test_insert.sql new file mode 100644 index 00000000..517bada1 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_encounter_type/test/sp_mamba_dim_encounter_type_test_insert.sql @@ -0,0 +1,63 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_encounter_type_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_encounter_type_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_encounter_type_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up existing table data +DELETE FROM mamba_dim_encounter_type; + +-- Step 3: Insert test data into the source table +INSERT INTO openmrs.encounter_type (encounter_type_id, name, description, uuid, date_created, retired) +VALUES + (1, 'Consultation', 'Patient consultation encounter', 'uuid-001', NOW(), 0), + (2, 'Surgery', 'Surgical encounter', 'uuid-002', NOW(), 0), + (3, 'Lab Test', 'Laboratory test encounter', 'uuid-003', NOW(), 0); + +-- Step 4: Call the sp_mamba_dim_encounter_type_insert procedure +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Error occurred during sp_mamba_dim_encounter_type_insert execution.'; +END; + + -- Call the stored procedure to insert data +CALL sp_mamba_dim_encounter_type_insert(); +END; + + -- Step 5: Validate the data was inserted correctly into mamba_dim_encounter_type + DECLARE inserted_count INT; +SELECT COUNT(*) INTO inserted_count FROM mamba_dim_encounter_type; + +IF inserted_count != 3 THEN + SET test_failed = 1; + SET failed_message = CONCAT('Expected 3 rows in mamba_dim_encounter_type, but found ', inserted_count); +END IF; + + -- Step 6: Return the test result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: Data inserted successfully into mamba_dim_encounter_type via sp_mamba_dim_encounter_type_insert.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_encounter_type_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_encounter_type_insert; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test.sql new file mode 100644 index 00000000..32dc1b4f --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_location_test_create(); +CALL sp_mamba_dim_location_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test_create.sql new file mode 100644 index 00000000..76506d03 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test_create.sql @@ -0,0 +1,68 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_location_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_location_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_location_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_location; + +-- Step 3: Call the sp_mamba_dim_location_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_location table via sp_mamba_dim_location_create.'; +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_location_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_location') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_location was not created by sp_mamba_dim_location_create.'; +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'location_id, name, description, parent_location_id, uuid, date_created, date_changed, retired, changed_by, retired_by, date_retired, retire_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_location'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: mamba_dim_location table created successfully via sp_mamba_dim_location_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_location_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_location_create; + + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test_insert.sql new file mode 100644 index 00000000..effa9076 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_location/test/sp_mamba_dim_location_test_insert.sql @@ -0,0 +1,66 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_location_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_location_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_location_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up test data before running the test +DELETE FROM mamba_dim_location; + +-- Step 3: Insert test data using sp_mamba_dim_location_insert procedure +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_location via sp_mamba_dim_location_insert.'; +END; + + -- Call the stored procedure to insert data +CALL sp_mamba_dim_location_insert(); +END; + + -- Step 4: Validate that the data has been inserted + IF (SELECT COUNT(*) FROM mamba_dim_location) = 0 THEN + SET test_failed = 1; +SET failed_message = 'No data was inserted into mamba_dim_location by sp_mamba_dim_location_insert.'; +END IF; + + -- Step 5: Validate the content of the inserted data + DECLARE expected_location_id INT DEFAULT 1; + DECLARE actual_location_id INT; + + -- Assume the first location_id should be 1 for the test +SELECT location_id INTO actual_location_id FROM mamba_dim_location LIMIT 1; + +IF actual_location_id != expected_location_id THEN + SET test_failed = 1; + SET failed_message = CONCAT('Incorrect location_id. Expected: ', expected_location_id, ', Found: ', actual_location_id); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: Data inserted successfully into mamba_dim_location via sp_mamba_dim_location_insert.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_location_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_location_insert; + + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test.sql new file mode 100644 index 00000000..0dbb802e --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL ssp_mamba_dim_orders_test_create(); +CALL sp_mamba_dim_orders_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test_create.sql new file mode 100644 index 00000000..ede5e0b1 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test_create.sql @@ -0,0 +1,79 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_orders_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_orders_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_orders_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_orders; + +-- Step 3: Call the sp_mamba_dim_orders_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_orders table via sp_mamba_dim_orders_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_orders_create', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_orders_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_orders') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_orders was not created by sp_mamba_dim_orders_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_orders_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'order_id, uuid, order_type_id, concept_id, patient_id, encounter_id, accession_number, order_number, orderer, instructions, date_activated, auto_expire_date, date_stopped, order_reason, order_reason_non_coded, urgency, previous_order_id, order_action, comment_to_fulfiller, care_setting, scheduled_date, order_group_id, sort_weight, fulfiller_comment, fulfiller_status, date_created, creator, voided, voided_by, date_voided, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_orders'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_orders_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_orders_create', 'PASSED', 'Table mamba_dim_orders created successfully via sp_mamba_dim_orders_create with the correct structure.', NOW()); +SELECT 'Unit Test Passed: mamba_dim_orders table created successfully via sp_mamba_dim_orders_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_orders_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_orders_create; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test_insert.sql new file mode 100644 index 00000000..7208f13f --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_orders/test/sp_mamba_dim_orders_test_insert.sql @@ -0,0 +1,108 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_orders_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_orders_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_orders_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Prepare the test environment + -- Clean up any existing data in mamba_dim_orders +DELETE FROM mamba_dim_orders; + +-- Ensure the table is created before insertion +CALL sp_mamba_dim_orders_create(); + +-- Step 3: Insert sample data into the source table (replace with actual source table name) +INSERT INTO source_orders_table (order_id, uuid, order_type_id, concept_id, patient_id, encounter_id, + accession_number, order_number, orderer, instructions, date_activated, + auto_expire_date, date_stopped, order_reason, order_reason_non_coded, + urgency, previous_order_id, order_action, comment_to_fulfiller, + care_setting, scheduled_date, order_group_id, sort_weight, + fulfiller_comment, fulfiller_status, date_created, creator, + voided, voided_by, date_voided, void_reason) +VALUES + (1, 'UUID-001', 10, 100, 101, 201, 'ACC-001', 'ORD-001', 301, 'Instructions 1', '2024-10-01', + NULL, NULL, NULL, NULL, 'Routine', NULL, 'Order Action 1', NULL, + 401, NULL, NULL, NULL, NULL, 'Fulfiller Status 1', '2024-10-01', 501, + 0, NULL, NULL, NULL), + (2, 'UUID-002', 20, 200, 102, 202, 'ACC-002', 'ORD-002', 302, 'Instructions 2', '2024-10-02', + NULL, NULL, NULL, NULL, 'Urgent', NULL, 'Order Action 2', NULL, + 402, NULL, NULL, NULL, NULL, 'Fulfiller Status 2', '2024-10-02', 502, + 0, NULL, NULL, NULL); + +-- Step 4: Call the sp_mamba_dim_orders_insert procedure to insert data +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_orders via sp_mamba_dim_orders_insert.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_orders_insert', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to insert data +CALL sp_mamba_dim_orders_insert(); +END; + + -- Step 5: Validate the data insertion + DECLARE expected_count INT DEFAULT 2; + DECLARE actual_count INT; + +SELECT COUNT(*) INTO actual_count FROM mamba_dim_orders; + +-- Check if the actual count matches the expected count +IF actual_count != expected_count THEN + SET test_failed = 1; + SET failed_message = CONCAT('Data insertion failed. Expected: ', expected_count, ' Found: ', actual_count); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_orders_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Validate the inserted data + DECLARE check_order_id INT DEFAULT 1; + DECLARE expected_urgency VARCHAR(50) DEFAULT 'Routine'; + + DECLARE actual_urgency VARCHAR(50); +SELECT urgency INTO actual_urgency +FROM mamba_dim_orders +WHERE order_id = check_order_id; + +IF actual_urgency != expected_urgency THEN + SET test_failed = 1; + SET failed_message = CONCAT('Data validation failed for order_id ', check_order_id, '. Expected urgency: ', expected_urgency, ', Found: ', actual_urgency); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_orders_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 7: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_orders_insert', 'PASSED', 'Data inserted successfully into mamba_dim_orders via sp_mamba_dim_orders_insert.', NOW()); +SELECT 'Unit Test Passed: Data inserted successfully into mamba_dim_orders via sp_mamba_dim_orders_insert.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_orders_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_orders_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test.sql new file mode 100644 index 00000000..d59b1174 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_patient_identifier_test_create(); +CALL sp_mamba_dim_patient_identifier_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test_create.sql new file mode 100644 index 00000000..fa03957c --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test_create.sql @@ -0,0 +1,80 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_patient_identifier_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_patient_identifier_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_patient_identifier; + +-- Step 3: Call the sp_mamba_dim_patient_identifier_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_patient_identifier table via sp_mamba_dim_patient_identifier_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_create', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_patient_identifier_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_patient_identifier') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_patient_identifier was not created by sp_mamba_dim_patient_identifier_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'patient_identifier_id, patient_id, identifier, identifier_type, preferred, location_id, patient_program_id, uuid, date_created, date_changed, date_voided, changed_by, voided, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_patient_identifier'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_patient_identifier_create', 'PASSED', 'Table mamba_dim_patient_identifier created successfully via sp_mamba_dim_patient_identifier_create with the correct structure.', NOW()); +SELECT 'Unit Test Passed: mamba_dim_patient_identifier table created successfully via sp_mamba_dim_patient_identifier_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_patient_identifier_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test_insert.sql new file mode 100644 index 00000000..1d3c0ede --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier/test/sp_mamba_dim_patient_identifier_test_insert.sql @@ -0,0 +1,77 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_patient_identifier_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_patient_identifier_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing data before running the test +DELETE FROM mamba_dim_patient_identifier; + +-- Step 3: Call the sp_mamba_dim_patient_identifier_insert procedure +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_patient_identifier table via sp_mamba_dim_patient_identifier_insert.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_insert', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to insert test data +CALL sp_mamba_dim_patient_identifier_insert(); +END; + + -- Step 4: Validate the insertion of data + IF NOT EXISTS (SELECT * FROM mamba_dim_patient_identifier WHERE patient_identifier_id = 1) THEN + SET test_failed = 1; + SET failed_message = 'Data was not inserted into mamba_dim_patient_identifier table.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Check if the data inserted matches the expected values + DECLARE actual_count INT; +SELECT COUNT(*) INTO actual_count +FROM mamba_dim_patient_identifier +WHERE patient_identifier_id = 1; + +IF actual_count != 1 THEN + SET test_failed = 1; + SET failed_message = CONCAT('Expected 1 record but found ', actual_count); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_patient_identifier_insert', 'PASSED', 'Data inserted successfully into mamba_dim_patient_identifier table.', NOW()); +SELECT 'Unit Test Passed: Data inserted successfully into mamba_dim_patient_identifier table.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_patient_identifier_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test.sql new file mode 100644 index 00000000..f603e93e --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_patient_identifier_type_test_create(); +CALL sp_mamba_dim_patient_identifier_type_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test_create.sql new file mode 100644 index 00000000..fc2e66fc --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test_create.sql @@ -0,0 +1,80 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_patient_identifier_type_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_type_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_patient_identifier_type_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_patient_identifier_type; + +-- Step 3: Call the sp_mamba_dim_patient_identifier_type_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_patient_identifier_type table via sp_mamba_dim_patient_identifier_type_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_type_create', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_patient_identifier_type_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_patient_identifier_type') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_patient_identifier_type was not created by sp_mamba_dim_patient_identifier_type_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_type_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'patient_identifier_type_id, name, description, uuid, date_created, date_changed, date_retired, retired, retire_reason, retired_by, changed_by, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_patient_identifier_type'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_type_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_patient_identifier_type_create', 'PASSED', 'mamba_dim_patient_identifier_type table created successfully with the correct structure.', NOW()); +SELECT 'Unit Test Passed: mamba_dim_patient_identifier_type table created successfully with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_patient_identifier_type_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_type_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test_insert.sql new file mode 100644 index 00000000..51cb3b96 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_patient_identifier_type/test/sp_mamba_dim_patient_identifier_type_test_insert.sql @@ -0,0 +1,77 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_patient_identifier_type_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_type_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_patient_identifier_type_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing data before running the test +DELETE FROM mamba_dim_patient_identifier_type; + +-- Step 3: Call the sp_mamba_dim_patient_identifier_type_insert procedure to insert data +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert records into mamba_dim_patient_identifier_type table via sp_mamba_dim_patient_identifier_type_insert.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_type_insert', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to insert data +CALL sp_mamba_dim_patient_identifier_type_insert(); +END; + + -- Step 4: Validate that data was inserted successfully + IF (SELECT COUNT(*) FROM mamba_dim_patient_identifier_type) = 0 THEN + SET test_failed = 1; +SET failed_message = 'No records were inserted into mamba_dim_patient_identifier_type by sp_mamba_dim_patient_identifier_type_insert.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_type_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the inserted data + DECLARE expected_count INT DEFAULT 3; + DECLARE actual_count INT; + +SELECT COUNT(*) INTO actual_count FROM mamba_dim_patient_identifier_type; + +IF actual_count != expected_count THEN + SET test_failed = 1; + SET failed_message = CONCAT('Expected ', expected_count, ' records, found ', actual_count, '.'); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_patient_identifier_type_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_patient_identifier_type_insert', 'PASSED', 'Records inserted successfully into mamba_dim_patient_identifier_type.', NOW()); +SELECT 'Unit Test Passed: Records inserted successfully into mamba_dim_patient_identifier_type.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_patient_identifier_type_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_patient_identifier_type_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test.sql new file mode 100644 index 00000000..a05b719e --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_person_test_create(); +CALL sp_mamba_dim_person_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test_create.sql new file mode 100644 index 00000000..d3f5b8bd --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test_create.sql @@ -0,0 +1,80 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_person; + +-- Step 3: Call the sp_mamba_dim_person_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_person table via sp_mamba_dim_person_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_create', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_person_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_person') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_person was not created by sp_mamba_dim_person_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'person_id, birthdate, birthdate_estimated, age, dead, death_date, deathdate_estimated, gender, person_name_short, person_name_long, uuid, date_created, date_changed, changed_by, date_voided, voided, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_person'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_person_create', 'PASSED', 'mamba_dim_person table created successfully with the correct structure.', NOW()); +SELECT 'Unit Test Passed: mamba_dim_person table created successfully via sp_mamba_dim_person_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test_insert.sql new file mode 100644 index 00000000..7eb1dce2 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person/test/sp_mamba_dim_person_test_insert.sql @@ -0,0 +1,75 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing data before running the test +DELETE FROM mamba_dim_person; + +-- Step 3: Call the sp_mamba_dim_person_insert procedure to insert a record +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert into mamba_dim_person table via sp_mamba_dim_person_insert.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_insert', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to insert the record +CALL sp_mamba_dim_person_insert(); +END; + + -- Step 4: Validate that the record was inserted + IF (SELECT COUNT(*) FROM mamba_dim_person) = 0 THEN + SET test_failed = 1; +SET failed_message = 'No records were inserted into mamba_dim_person.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the inserted data + DECLARE actual_record_count INT; +SELECT COUNT(*) INTO actual_record_count FROM mamba_dim_person WHERE person_id = 1; + +IF actual_record_count != 1 THEN + SET test_failed = 1; + SET failed_message = 'Inserted record not found in mamba_dim_person.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_person_insert', 'PASSED', 'Record inserted successfully into mamba_dim_person.', NOW()); +SELECT 'Unit Test Passed: Record inserted successfully into mamba_dim_person.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test.sql new file mode 100644 index 00000000..04009d3c --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_person_address_test_create(); +CALL sp_mamba_dim_person_address_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test_create.sql new file mode 100644 index 00000000..157084ea --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test_create.sql @@ -0,0 +1,80 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_address_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_address_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_address_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_person_address; + +-- Step 3: Call the sp_mamba_dim_person_address_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_person_address table via sp_mamba_dim_person_address_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_address_create', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_person_address_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_person_address') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_person_address was not created by sp_mamba_dim_person_address_create.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_address_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'person_address_id, person_id, preferred, address1, address2, address3, address4, address5, address6, address7, address8, address9, address10, address11, address12, address13, address14, address15, city_village, county_district, state_province, postal_code, country, latitude, longitude, date_created, date_changed, date_voided, changed_by, voided, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_person_address'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_address_create', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_person_address_create', 'PASSED', 'mamba_dim_person_address table created successfully with the correct structure.', NOW()); +SELECT 'Unit Test Passed: mamba_dim_person_address table created successfully with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_address_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_address_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test_insert.sql new file mode 100644 index 00000000..7b1301c4 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_address/test/sp_mamba_dim_person_address_test_insert.sql @@ -0,0 +1,77 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_address_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_address_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_address_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing records before running the test +DELETE FROM mamba_dim_person_address; + +-- Step 3: Call the sp_mamba_dim_person_address_insert procedure to insert a test record +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert record into mamba_dim_person_address via sp_mamba_dim_person_address_insert.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_address_insert', 'FAILED', failed_message, NOW()); +END; + + -- Call the stored procedure to insert a record +CALL sp_mamba_dim_person_address_insert(); +END; + + -- Step 4: Validate the insertion of the record + IF (SELECT COUNT(*) FROM mamba_dim_person_address) = 0 THEN + SET test_failed = 1; +SET failed_message = 'No records found in mamba_dim_person_address after insertion.'; + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_address_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 5: Validate the inserted record + DECLARE expected_person_id INT DEFAULT 123; + DECLARE actual_person_id INT; + +SELECT person_id INTO actual_person_id FROM mamba_dim_person_address WHERE person_address_id = 1; + +IF actual_person_id != expected_person_id THEN + SET test_failed = 1; + SET failed_message = CONCAT('Expected person_id: ', expected_person_id, ', but found: ', actual_person_id); + -- Log the failure message into _mamba_etl_test_log +INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) +VALUES ('test_sp_mamba_dim_person_address_insert', 'FAILED', failed_message, NOW()); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE + -- Log the success message into _mamba_etl_test_log + INSERT INTO _mamba_etl_test_log (test_name, status, message, created_at) + VALUES ('test_sp_mamba_dim_person_address_insert', 'PASSED', 'Record inserted successfully into mamba_dim_person_address.', NOW()); +SELECT 'Unit Test Passed: Record inserted successfully into mamba_dim_person_address.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_address_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_address_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test.sql new file mode 100644 index 00000000..1f46125b --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_person_attribute_test_create(); +CALL sp_mamba_dim_person_attribute_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test_create.sql new file mode 100644 index 00000000..94cf7e0b --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test_create.sql @@ -0,0 +1,67 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_attribute_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_attribute_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_person_attribute; + +-- Step 3: Call the sp_mamba_dim_person_attribute_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_person_attribute table via sp_mamba_dim_person_attribute_create.'; +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_person_attribute_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_person_attribute') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_person_attribute was not created by sp_mamba_dim_person_attribute_create.'; +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'person_attribute_id, person_attribute_type_id, person_id, uuid, value, voided, date_created, date_changed, date_voided, changed_by, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_person_attribute'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: mamba_dim_person_attribute table created successfully via sp_mamba_dim_person_attribute_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_attribute_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_create; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test_insert.sql new file mode 100644 index 00000000..f94d3159 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute/test/sp_mamba_dim_person_attribute_test_insert.sql @@ -0,0 +1,53 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_attribute_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_attribute_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing records before running the test +DELETE FROM mamba_dim_person_attribute; + +-- Step 3: Call the sp_mamba_dim_person_attribute_insert procedure to insert a record +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert record into mamba_dim_person_attribute via sp_mamba_dim_person_attribute_insert.'; +END; + + -- Call the stored procedure to insert the record +CALL sp_mamba_dim_person_attribute_insert(); +END; + + -- Step 4: Validate the insertion of the record + IF NOT EXISTS (SELECT * FROM mamba_dim_person_attribute WHERE person_attribute_id = 1) THEN + SET test_failed = 1; + SET failed_message = 'Record was not inserted into mamba_dim_person_attribute.'; +END IF; + + -- Step 5: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: Record inserted successfully into mamba_dim_person_attribute.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_attribute_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_insert; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test.sql new file mode 100644 index 00000000..07d2b00f --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_person_attribute_type_test_create(); +CALL sp_mamba_dim_person_attribute_type_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test_create.sql new file mode 100644 index 00000000..f82299f1 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test_create.sql @@ -0,0 +1,53 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_attribute_type_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_type_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_attribute_type_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_person_attribute_type; + +-- Step 3: Call the sp_mamba_dim_person_attribute_type_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_person_attribute_type table via sp_mamba_dim_person_attribute_type_create.'; +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_person_attribute_type_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_person_attribute_type') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_person_attribute_type was not created by sp_mamba_dim_person_attribute_type_create.'; +END IF; + + -- Step 5: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: mamba_dim_person_attribute_type table created successfully via sp_mamba_dim_person_attribute_type_create.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_attribute_type_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_type_create; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test_insert.sql new file mode 100644 index 00000000..8cea7386 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_attribute_type/test/sp_mamba_dim_person_attribute_type_test_insert.sql @@ -0,0 +1,78 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_attribute_type_insert procedure (without parameters) +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_type_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_attribute_type_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing data +DELETE FROM mamba_dim_person_attribute_type; + +-- Step 3: Insert a test record using sp_mamba_dim_person_attribute_type_insert procedure +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data via sp_mamba_dim_person_attribute_type_insert.'; +END; + + -- Call the stored procedure to insert a test record without passing parameters +CALL sp_mamba_dim_person_attribute_type_insert(); +END; + + -- Step 4: Validate the insert operation + IF NOT EXISTS (SELECT * FROM mamba_dim_person_attribute_type WHERE uuid IS NOT NULL ORDER BY person_attribute_type_id DESC LIMIT 1 ) THEN + SET test_failed = 1; + SET failed_message = 'Record was not inserted into mamba_dim_person_attribute_type.'; + END IF; + + -- Step 5: Validate specific field values + DECLARE expected_name VARCHAR(50) DEFAULT 'Test Attribute Type'; + DECLARE actual_name VARCHAR(50); + +SELECT name INTO actual_name +FROM mamba_dim_person_attribute_type +WHERE uuid = 'test-uuid-123'; + +IF actual_name != expected_name THEN + SET test_failed = 1; + SET failed_message = 'Record insert did not match expected values.'; +END IF; + + -- Step 6: Log results to the test log table + IF test_failed = 1 THEN + INSERT INTO _mamba_etl_test_log (test_description, test_result) + VALUES ('Unit Test: sp_mamba_dim_person_attribute_type_insert', CONCAT('Failed: ', failed_message)); +ELSE + INSERT INTO _mamba_etl_test_log (test_description, test_result) + VALUES ('Unit Test: sp_mamba_dim_person_attribute_type_insert', 'Passed'); +END IF; + + -- Step 7: Return result of the unit test + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: sp_mamba_dim_person_attribute_type_insert worked as expected.' AS result; +END IF; + + +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_attribute_type_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_attribute_type_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test.sql new file mode 100644 index 00000000..9b7fbd85 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_person_name_test_create(); +CALL sp_mamba_dim_person_name_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test_create.sql new file mode 100644 index 00000000..d653ef11 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test_create.sql @@ -0,0 +1,72 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_name_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_name_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_name_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_person_name; + +-- Step 3: Call the sp_mamba_dim_person_name_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_person_name table via sp_mamba_dim_person_name_create.'; +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_person_name_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_person_name') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_person_name was not created by sp_mamba_dim_person_name_create.'; +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'person_name_id, person_id, preferred, given_name, family_name, middle_name, honorific_prefix, honorific_suffix, uuid, date_created, date_changed, changed_by, date_voided, voided, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_person_name'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); +END IF; + + -- Step 6: Log the test result +INSERT INTO mamba_etl_test_log (test_name, log_message) +VALUES ('test_sp_mamba_dim_person_name_create', IF(test_failed = 1, CONCAT('Unit Test Failed: ', failed_message), 'Unit Test Passed: mamba_dim_person_name table created successfully via sp_mamba_dim_person_name_create with the correct structure.')); + +-- Step 7: Return result +IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: mamba_dim_person_name table created successfully via sp_mamba_dim_person_name_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_name_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_name_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test_insert.sql new file mode 100644 index 00000000..e6806153 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_person_name/test/sp_mamba_dim_person_name_test_insert.sql @@ -0,0 +1,69 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_person_name_insert procedure (with logging) +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_name_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_person_name_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + DECLARE test_name VARCHAR(255) DEFAULT 'test_sp_mamba_dim_person_name_insert'; + + -- Step 2: Clean up any existing data in the mamba_dim_person_name table before running the test +DELETE FROM mamba_dim_person_name; + +-- Step 3: Call the sp_mamba_dim_person_name_insert procedure to insert data +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert data into mamba_dim_person_name table via sp_mamba_dim_person_name_insert.'; +END; + + -- Call the stored procedure to insert sample data +CALL sp_mamba_dim_person_name_insert(); +END; + + -- Step 4: Validate the data insertion + IF NOT EXISTS (SELECT * FROM mamba_dim_person_name WHERE person_name_id = 1) THEN + SET test_failed = 1; + SET failed_message = 'Record with person_name_id = 1 was not inserted by sp_mamba_dim_person_name_insert.'; +END IF; + + -- Step 5: Validate the inserted data + DECLARE expected_full_name VARCHAR(255) DEFAULT 'John Paul Doe'; + DECLARE actual_full_name VARCHAR(255); + +SELECT full_name INTO actual_full_name FROM mamba_dim_person_name WHERE person_name_id = 1; + +-- Check if the actual full_name matches the expected full_name +IF actual_full_name != expected_full_name THEN + SET test_failed = 1; + SET failed_message = CONCAT('Inserted data mismatch. Expected: ', expected_full_name, ', Found: ', actual_full_name); +END IF; + + -- Step 6: Log the result + IF test_failed = 1 THEN + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES (test_name, CONCAT('Unit Test Failed: ', failed_message)); +ELSE + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES (test_name, 'Unit Test Passed: Data inserted successfully via sp_mamba_dim_person_name_insert with correct values.'); +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_person_name_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_person_name_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test.sql new file mode 100644 index 00000000..350fdde0 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_relationship_test_create(); +CALL sp_mamba_dim_relationship_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test_create.sql new file mode 100644 index 00000000..5e5eae87 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test_create.sql @@ -0,0 +1,68 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_relationship_create Procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_relationship_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_relationship_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing table before running the test +DROP TABLE IF EXISTS mamba_dim_relationship; + +-- Step 3: Call the sp_mamba_dim_relationship_create procedure to create the table +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_relationship table via sp_mamba_dim_relationship_create.'; +END; + + -- Call the stored procedure to create the table +CALL sp_mamba_dim_relationship_create(); +END; + + -- Step 4: Validate the creation of the table + IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'mamba_dim_relationship') THEN + SET test_failed = 1; + SET failed_message = 'Table mamba_dim_relationship was not created by sp_mamba_dim_relationship_create.'; +END IF; + + -- Step 5: Validate the structure of the created table + DECLARE expected_columns VARCHAR(255) DEFAULT 'relationship_id, person_a, relationship, person_b, start_date, end_date, creator, uuid, date_created, date_changed, changed_by, date_voided, voided, voided_by, void_reason, incremental_record'; + DECLARE actual_columns VARCHAR(255); + +SELECT GROUP_CONCAT(COLUMN_NAME ORDER BY ORDINAL_POSITION) INTO actual_columns +FROM information_schema.columns +WHERE table_name = 'mamba_dim_relationship'; + +-- Check if the actual columns match the expected columns +IF actual_columns != expected_columns THEN + SET test_failed = 1; + SET failed_message = CONCAT('Table structure does not match. Expected: ', expected_columns, ' Found: ', actual_columns); +END IF; + + -- Step 6: Return result + IF test_failed = 1 THEN +SELECT CONCAT('Unit Test Failed: ', failed_message) AS result; +ELSE +SELECT 'Unit Test Passed: mamba_dim_relationship table created successfully via sp_mamba_dim_relationship_create with the correct structure.' AS result; +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_relationship_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_relationship_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test_insert.sql new file mode 100644 index 00000000..68ddd6b3 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_relationship/test/sp_mamba_dim_relationship_test_insert.sql @@ -0,0 +1,55 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_relationship_insert procedure without parameters +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_relationship_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_relationship_insert() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Clean up any existing records in the mamba_dim_relationship table +DELETE FROM mamba_dim_relationship WHERE relationship_id = 1; + +-- Step 3: Call the sp_mamba_dim_relationship_insert procedure to insert a test record +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION +BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to insert record into mamba_dim_relationship.'; +END; + + -- Call the stored procedure without parameters +CALL sp_mamba_dim_relationship_insert(); +END; + + -- Step 4: Validate that the record was inserted successfully + IF NOT EXISTS (SELECT * FROM mamba_dim_relationship WHERE relationship_id = 1) THEN + SET test_failed = 1; + SET failed_message = 'Record not found in mamba_dim_relationship after insert.'; +END IF; + + -- Step 5: Log the result + IF test_failed = 1 THEN + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES ('test_sp_mamba_dim_relationship_insert', CONCAT('Unit Test Failed: ', failed_message)); +ELSE + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES ('test_sp_mamba_dim_relationship_insert', 'Unit Test Passed: Record inserted successfully.'); +END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_relationship_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_relationship_insert; + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test.sql new file mode 100644 index 00000000..38091913 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test.sql @@ -0,0 +1,6 @@ +-- $BEGIN + +CALL sp_mamba_dim_user_test_create(); +CALL sp_mamba_dim_user_test_insert(); + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test_create.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test_create.sql new file mode 100644 index 00000000..779ebb17 --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test_create.sql @@ -0,0 +1,57 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_user_create procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_user_create; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_user_create() +BEGIN + -- Step 1: Variables for test results + DECLARE failed_message VARCHAR(255) DEFAULT ''; + DECLARE test_failed INT DEFAULT 0; + + -- Step 2: Drop the table if it already exists to ensure a clean state + DROP TABLE IF EXISTS mamba_dim_user; + + -- Step 3: Call the sp_mamba_dim_user_create procedure + BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + SET test_failed = 1; + SET failed_message = 'Failed to create mamba_dim_user table.'; + END; + + -- Call the stored procedure to create the user table + CALL sp_mamba_dim_user_create(); + END; + + -- Step 4: Validate that the table was created successfully + IF NOT EXISTS (SELECT * FROM information_schema.tables + WHERE table_name = 'mamba_dim_user') THEN + SET test_failed = 1; + SET failed_message = 'mamba_dim_user table not found after creation.'; + END IF; + + -- Step 5: Log the result + IF test_failed = 1 THEN + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES ('test_sp_mamba_dim_user_create', CONCAT('Unit Test Failed: ', failed_message)); + ELSE + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES ('test_sp_mamba_dim_user_create', 'Unit Test Passed: mamba_dim_user table created successfully.'); + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_user_create(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_user_create; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test_insert.sql b/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test_insert.sql new file mode 100644 index 00000000..2216023c --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/dimensions/dim_user/test/sp_mamba_dim_user_test_insert.sql @@ -0,0 +1,43 @@ +-- $BEGIN +-- ------------------------------------------------------------------------------------- +-- Unit Test for sp_mamba_dim_user_insert procedure +-- ------------------------------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_user_insert; + +DELIMITER // + +CREATE PROCEDURE test_sp_mamba_dim_user_insert() +BEGIN + DECLARE test_failed INT DEFAULT 0; + DECLARE failed_message VARCHAR(255) DEFAULT ''; + + -- Step 1: Call the stored procedure to insert a user + CALL sp_mamba_dim_user_insert(); + + -- Step 2: Check if the user was inserted successfully + IF NOT EXISTS (SELECT * FROM mamba_dim_user WHERE user_id = LAST_INSERT_ID()) THEN + SET test_failed = 1; + SET failed_message = 'User insertion failed.'; + END IF; + + -- Step 3: Log the result into mamba_etl_test_log + IF test_failed = 1 THEN + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES ('test_sp_mamba_dim_user_insert', CONCAT('Unit Test Failed: ', failed_message)); + ELSE + INSERT INTO mamba_etl_test_log (test_name, log_message) + VALUES ('test_sp_mamba_dim_user_insert', 'Unit Test Passed: User inserted successfully.'); + END IF; +END // + +DELIMITER ; + +-- Run the unit test +CALL test_sp_mamba_dim_user_insert(); + +-- Clean up after the test +DROP PROCEDURE IF EXISTS test_sp_mamba_dim_user_insert; + + +-- $END diff --git a/api/src/main/resources/_core/database/mysql/xf_system/etl_error/sp_mamba_elt_test_log.sql b/api/src/main/resources/_core/database/mysql/xf_system/etl_error/sp_mamba_elt_test_log.sql new file mode 100644 index 00000000..87df68cc --- /dev/null +++ b/api/src/main/resources/_core/database/mysql/xf_system/etl_error/sp_mamba_elt_test_log.sql @@ -0,0 +1,11 @@ +-- $BEGIN +CREATE TABLE IF NOT EXISTS mamba_etl_test_log +( + log_id INT AUTO_INCREMENT PRIMARY KEY, + test_name VARCHAR(255) NOT NULL, + log_message TEXT NOT NULL, + log_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) +CHARSET = UTF8MB4; + +-- $END \ No newline at end of file diff --git a/api/src/main/resources/_core/database/mysql/xf_system/etl_obs_group/sp_mamba_obs_group_insert.sql b/api/src/main/resources/_core/database/mysql/xf_system/etl_obs_group/sp_mamba_obs_group_insert.sql index 78007066..3733e5b0 100644 --- a/api/src/main/resources/_core/database/mysql/xf_system/etl_obs_group/sp_mamba_obs_group_insert.sql +++ b/api/src/main/resources/_core/database/mysql/xf_system/etl_obs_group/sp_mamba_obs_group_insert.sql @@ -1,35 +1,42 @@ -- $BEGIN +DROP PROCEDURE IF EXISTS sp_mamba_obs_group_insert; -CREATE TEMPORARY TABLE mamba_temp_obs_group_ids -( - obs_group_id INT NOT NULL, - row_num INT NOT NULL, +DELIMITER // +CREATE PROCEDURE sp_mamba_obs_group_insert() +BEGIN + CREATE TEMPORARY TABLE mamba_temp_obs_group_ids + ( + obs_group_id INT NOT NULL, + row_num INT NOT NULL, - INDEX mamba_idx_obs_group_id (obs_group_id), - INDEX mamba_idx_visit_id (row_num) -) - CHARSET = UTF8MB4; + INDEX mamba_idx_obs_group_id (obs_group_id), + INDEX mamba_idx_visit_id (row_num) + ) + CHARSET = UTF8MB4; -INSERT INTO mamba_temp_obs_group_ids -SELECT obs_group_id, - COUNT(*) AS row_num -FROM mamba_z_encounter_obs o -WHERE obs_group_id IS NOT NULL -GROUP BY obs_group_id, person_id, encounter_id; + INSERT INTO mamba_temp_obs_group_ids + SELECT obs_group_id, + COUNT(*) AS row_num + FROM mamba_z_encounter_obs o + WHERE obs_group_id IS NOT NULL + GROUP BY obs_group_id, person_id, encounter_id; -INSERT INTO mamba_obs_group (obs_group_concept_id, - obs_group_concept_name, - obs_id) -SELECT DISTINCT o.obs_question_concept_id, - LEFT(c.auto_table_column_name, 12) AS name, - o.obs_id -FROM mamba_temp_obs_group_ids t - INNER JOIN mamba_z_encounter_obs o - ON t.obs_group_id = o.obs_group_id - INNER JOIN mamba_dim_concept c - ON o.obs_question_concept_id = c.concept_id -WHERE t.row_num > 1; + INSERT INTO mamba_obs_group (obs_group_concept_id, + obs_group_concept_name, + obs_id) + SELECT DISTINCT o.obs_question_concept_id, + LEFT(c.auto_table_column_name, 12) AS name, + o.obs_id + FROM mamba_temp_obs_group_ids t + INNER JOIN mamba_z_encounter_obs o + ON t.obs_group_id = o.obs_group_id + INNER JOIN mamba_dim_concept c + ON o.obs_question_concept_id = c.concept_id + WHERE t.row_num > 1; -DROP TEMPORARY TABLE mamba_temp_obs_group_ids; + DROP TEMPORARY TABLE mamba_temp_obs_group_ids; +END // + +DELIMITER -- $END \ No newline at end of file