Delimiter //
/**
 * Test of LOADER_SUMMARIES_NORMALIZE_MAP_ACCOUNTS
 * @test
 */
Drop Procedure If Exists TEST_LOADER_SUMMARIES_NORMALIZE_MAP_DF_SUMM_CODE//
Create Procedure TEST_LOADER_SUMMARIES_NORMALIZE_MAP_DF_SUMM_CODE(
)
Begin

    -- initial dataset
    CALL LOADER_SUMMARIES_CLEAN();

    CALL LOADER_SUMMARIES_PUSH(1, 'DF_SUMMARIES_CODE = ''CODE1'' ', 1, NULL);
    CALL LOADER_SUMMARIES_PUSH(2, 'DF_SUMMARIES_CODE = ''NOTHING'' ', 2, NULL);

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


    call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_SUMMARIES');
    
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_SUMMARIES', 
            'ID_DF_SUMMARIES = 1
			, ADMIN_ID_ADMIN = 1
			, DF_PRIORITY_ID_DF_PRIORITY = 1
			, DF_SUMMARIES_CODE = ''CODE1''
			, DF_SUMMARIES_DISPLAY_SEQ = 1
			, DF_SUMMARIES_BACKGROUND_COLOR = ''FFFFFF''
			, DF_SUMMARIES_FONT_COLOR = ''000000''
			, DF_SUMMARIES_TYPE = 1
			, DF_SUMMARIES_CATEGORY_CODE = ''CODE1''
			, DF_SUMMARIES_END_TREATMENT = 0
			, DF_SUMMARIES_INTERNAL = 0 '
		);
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_SUMMARIES', 
            'ID_DF_SUMMARIES = 2
			, ADMIN_ID_ADMIN = 1
			, DF_PRIORITY_ID_DF_PRIORITY = 1
			, DF_SUMMARIES_CODE = ''CODE2''
			, DF_SUMMARIES_DISPLAY_SEQ = 1
			, DF_SUMMARIES_BACKGROUND_COLOR = ''FF0000''
			, DF_SUMMARIES_FONT_COLOR = ''00FF00''
			, DF_SUMMARIES_TYPE = 1
			, DF_SUMMARIES_CATEGORY_CODE = ''CODE2''
			, DF_SUMMARIES_END_TREATMENT = 0
			, DF_SUMMARIES_INTERNAL = 0 '
		);

    -- Tested procedure
    Call LOADER_SUMMARIES_NORMALIZE_MAP_DF_SUMM_CODE(1);

    -- Assertions
    Call utAssert_eq('During load summaries, when a valid summary code is provided, row receives its id'
        , 1
        , (Select DF_SUMMARIES_ID_DF_SUMMR From LOADER_SUMMARIES Where ID_LOADER_SUMMARIES = 1)
    );
    Call utAssert_eq('During load summaries, When an invalid summary code is provided, row receive no id'
        , Null
        , (Select DF_SUMMARIES_ID_DF_SUMMR From LOADER_SUMMARIES Where ID_LOADER_SUMMARIES = 2)
    );

-- Assertions
    CALL utAssert_eq('data with empty invalid summary ref are flagged' 
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2) 
    );
    CALL utAssert_eq('data with not valid summary ref are not flagged' 
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1) 
    );






    -- Clean
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_SUMMARIES');
    Call LOADER_TEST_MOCK_INFO_CLEAN();
    Call LOADER_SUMMARIES_CLEAN();

End//
Delimiter ;