Delimiter //
/**
 * Test of LOADER_CREDITLIMIT_NORMALIZE_MAP_CREATE_OR_UPDATE()
 * @test
 */
Drop Procedure If Exists TEST_LOADER_CREDITLIMIT_NORMALIZE_MAP_CREATE_OR_UPDATE//
Create Procedure TEST_LOADER_CREDITLIMIT_NORMALIZE_MAP_CREATE_OR_UPDATE(
)
Begin

    -- initial dataset
    Call LOADER_CREDITLIMIT_CLEAN();

    Call LOADER_CREDITLIMIT_PUSH(1, 'ACCOUNTS_ID_ACCOUNTS = 1, CREDIT_LIMIT_AMOUNT = 66011.0 ', 1, NULL); -- Pass
    Call LOADER_CREDITLIMIT_PUSH(2, 'ACCOUNTS_ID_ACCOUNTS = 1, CREDIT_LIMIT_AMOUNT = 66011.0, CREDIT_LIMIT_VAL_DATE = ''2014-12-10'' ', 2, NULL); -- Histo
    Call LOADER_CREDITLIMIT_PUSH(3, 'ACCOUNTS_ID_ACCOUNTS = 1, CREDIT_LIMIT_AMOUNT = 54622.0 ', 3, NULL); -- New

    -- Business tables
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('CREDIT_LIMIT');
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('CREDIT_LIMIT', 
        'ID_CREDIT_LIMIT = 1
        , ACCOUNTS_ID_ACCOUNTS = 1
        , CREDIT_LIMIT_AMOUNT = 42042.0
        , CREDIT_LIMIT_VAL_DATE = ''2015-01-01'''
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('CREDIT_LIMIT', 
        'ID_CREDIT_LIMIT = 2
        , ACCOUNTS_ID_ACCOUNTS = 1
        , CREDIT_LIMIT_AMOUNT = 24024.0
        , CREDIT_LIMIT_VAL_DATE = ''2015-02-01'''
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('CREDIT_LIMIT', 
        'ID_CREDIT_LIMIT = 3
        , ACCOUNTS_ID_ACCOUNTS = 1
        , CREDIT_LIMIT_AMOUNT = 66011.0'
    );

    -- Tested procedure
    Call LOADER_CREDITLIMIT_NORMALIZE_MAP_CREATE_OR_UPDATE(1);

    -- Assertions
    Call utAssert_eq('When the amount is the same as the active one, no creation is mapped'
        , Null
        , (Select ID_CREDIT_LIMIT_NEW From LOADER_CREDITLIMIT Where ID_LOADER_CREDITLIMIT = 1)
    );
    Call utAssert_eq('When the amount is the same as the active one, no update is mapped'
        , Null
        , (Select ID_CREDIT_LIMIT From LOADER_CREDITLIMIT Where ID_LOADER_CREDITLIMIT = 1)
    );
    Call utAssert_eq('When the validity date has passed, creation is mapped'
        , 1
        , (Select ID_CREDIT_LIMIT_NEW From LOADER_CREDITLIMIT Where ID_LOADER_CREDITLIMIT = 2)
    );
    Call utAssert_eq('When the validity date has passed, no update is mapped'
        , Null
        , (Select ID_CREDIT_LIMIT From LOADER_CREDITLIMIT Where ID_LOADER_CREDITLIMIT = 2)
    );
    Call utAssert_eq('When the amount is different from the active one, creation is mapped'
        , 2
        , (Select ID_CREDIT_LIMIT_NEW From LOADER_CREDITLIMIT Where ID_LOADER_CREDITLIMIT = 3)
    );
    Call utAssert_eq('When the amount is different from the active one, update is mapped'
        , 3
        , (Select ID_CREDIT_LIMIT From LOADER_CREDITLIMIT Where ID_LOADER_CREDITLIMIT = 3)
    );

    -- Clean
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('CREDIT_LIMIT');
    Call LOADER_CREDITLIMIT_CLEAN();

End//
Delimiter ;