Delimiter //
/**
 * Test of LOADER_REFDATA_NORMALIZE_MAP_ID_ENT_REF
 * @test
 */
Drop Procedure If Exists TEST_LOADER_REFDATA_NORMALIZE_MAP_ID_ENT_REF//
Create Procedure TEST_LOADER_REFDATA_NORMALIZE_MAP_ID_ENT_REF(
)
Begin

    -- initial dataset
    CALL LOADER_REFDATA_CLEAN();

    CALL LOADER_REFDATA_PUSH(1, 'ENTITIES_REF_SEQUENCE = 1', 1, NULL);
    CALL LOADER_REFDATA_PUSH(2, 'ENTITIES_REF_SEQUENCE = 50 ', 2, NULL);

    -- Business tables
    Call LOADER_TEST_MOCK_INFO_PUSH('ID_ENTITIES', 1);

    call LOADER_TEST_MOCK_BUSINESS_CLEAN('ENTITIES_REF_TYPES');
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF_TYPES', 
            'ID_ENTITIES_REF_TYPES = 1
            , ENTITIES_REF_TYPES_MAX_SEQ = 20
            , ENTITIES_REF_TYPES_CODE = ''ACCOUNTS''
            '
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF_TYPES', 
            'ID_ENTITIES_REF_TYPES = 2
            , ENTITIES_REF_TYPES_MAX_SEQ = 20
            , ENTITIES_REF_TYPES_CODE = ''FOO''
            '
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF', 
            'ID_ENTITIES_REF = 1
            , ENTITIES_ID_ENTITIES = 1
            , ENT_REF_TYPE_ID_ENT_REF_TYPES = 1
            , ENTITIES_REF_SEQUENCE = 1
            '
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF', 
            'ID_ENTITIES_REF = 2
            , ENTITIES_ID_ENTITIES = 1
            , ENT_REF_TYPE_ID_ENT_REF_TYPES = 1
            , ENTITIES_REF_SEQUENCE = 2
            '
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF', 
            'ID_ENTITIES_REF = 3
            , ENTITIES_ID_ENTITIES = 1
            , ENT_REF_TYPE_ID_ENT_REF_TYPES = 2
            , ENTITIES_REF_SEQUENCE = 1
            '
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF', 
            'ID_ENTITIES_REF = 4
            , ENTITIES_ID_ENTITIES = 1
            , ENT_REF_TYPE_ID_ENT_REF_TYPES = 2
            , ENTITIES_REF_SEQUENCE = 2
            '
    );
    
    -- Tested procedure
    Call LOADER_REFDATA_NORMALIZE_MAP_ID_ENT_REF(1);

    -- Assertions
    Call utAssert_eq('get ref type id'
        , 1
        , (Select ENTITIES_REF_ID_ENTITIES_REF From LOADER_REFDATA  Where ID_LOADER_REFDATA  = 1)
    );
    

    -- Clean
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ENTITIES_REF_TYPES');
    Call LOADER_REFDATA_CLEAN();
    Call LOADER_TEST_MOCK_INFO_CLEAN();
    

End//
Delimiter ;