Delimiter //
/**
 * Test of LOADER_BALANCECONTROL_NORMALIZE_CHECK_ACCOUNT_EXISTS
 * @test
 */
Drop Procedure If Exists TEST_LOADER_BALANCECONTROL_NORMALIZE_CHECK_GIVEN_BALANCE//
Create Procedure TEST_LOADER_BALANCECONTROL_NORMALIZE_CHECK_GIVEN_BALANCE()
Begin

    -- Context
    call LOADER_TEST_MOCK_BALANCECONTROL_CLEAN();
    call LOADER_TEST_MOCK_BALANCECONTROL_PUSH(1, 'ID_ACCOUNTS = 1, BALANCE = 100', 1, Null);
    call LOADER_TEST_MOCK_BALANCECONTROL_PUSH(2, 'ID_ACCOUNTS = 2, BALANCE = null', 2, Null);

    -- Business tables
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('FI_ANA', 'ACCOUNTS_ID_ACCOUNTS = 1, FI_ANA_OUTSTANDING = 100');
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('FI_ANA', 'ACCOUNTS_ID_ACCOUNTS = 2, FI_ANA_OUTSTANDING = 200');
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('FI_ANA', 'ACCOUNTS_ID_ACCOUNTS = 3, FI_ANA_OUTSTANDING = 0');

    -- Tested procedure
    Call LOADER_BALANCECONTROL_NORMALIZE_CHECK_GIVEN_BALANCE(1);


    -- Assertions
    Call utAssert_eq('When an account have a non empty balance, and when this balance equals the given balance for this account, row doesn"t receive any error'
        , 0
        , (Select Count(*) From LOADER_BALANCECONTROL_ACCOUNTS_STATUS Where ACCOUNTS_ID_ACCOUNTS = 1)
    );
    Call utAssert_eq('When an account have a non empty balance, and when no balance is provided for this account, row receives an error'
        , 1
        , (Select LOADER_STATUS_ERRCOUNT From LOADER_STATUS Where ID_LOADER_STATUS = 2)
    );
    Call utAssert_eq('When an account have an empty balance, and when no balance is provided for this account, row doesn''t receive any error'
        , 0
        , (Select Count(*) From LOADER_BALANCECONTROL_ACCOUNTS_STATUS Where ACCOUNTS_ID_ACCOUNTS = 3)
    );

    -- Clean
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('FI_ANA');
    Call LOADER_TEST_MOCK_INFO_CLEAN();
    Call LOADER_TEST_MOCK_BALANCECONTROL_CLEAN();

End//
Delimiter ;