Delimiter //
/**
 * test for LOADER_ENTRIES_MAP_POSITIVE_AMOUNTS()
 * 
 * @author Jean-François
 */
Drop Procedure If Exists TEST_LOADER_ENTRIES_MAP_POSITIVE_AMOUNTS//
Create Procedure TEST_LOADER_ENTRIES_MAP_POSITIVE_AMOUNTS()
Begin


    -- table
    Call LOADER_TEST_MOCK_ENTRIES_CLEAN();
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(1, Concat('CREDIT = 400 ')           , 1, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(2, Concat('CREDIT = -500 ')          , 2, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(3, Concat('DEBIT = 400 ')            , 3, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(4, Concat('DEBIT = -500 ')           , 4, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(5, Concat('ENT_CREDIT = 400 ')       , 5, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(6, Concat('ENT_CREDIT = -500 ')      , 6, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(7, Concat('ENT_DEBIT= 400 ')         , 7, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(8, Concat('ENT_DEBIT = -500 ')       , 8, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(9, Concat('ADMIN_CREDIT = 400 ')     , 9, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(10, Concat('ADMIN_CREDIT = -500 ')   , 10, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(11, Concat('ADMIN_DEBIT = 400 ')     , 11, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(12, Concat('ADMIN_DEBIT = -500 ' )   , 12, Null);


    -- tested procedure
    Call LOADER_ENTRIES_MAP_POSITIVE_AMOUNTS(1);


    -- assertions about positives amounts
    Call utAssert_eq('Positives credits are imported'
        , 400
        , (Select Cast(ENTRIES_CREDIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 1)
    );
    Call utAssert_eq('Positives debits are imported'
        , 400
        , (Select Cast(ENTRIES_DEBIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 3)
    );
    Call utAssert_eq('Positives credits in entity''s currency are imported'
        , 400
        , (Select Cast(ENTRIES_ENT_CREDIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 5)
    );
    Call utAssert_eq('Positives debits in entity''s currency are imported'
        , 400
        , (Select Cast(ENTRIES_ENT_DEBIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 7)
    );
    Call utAssert_eq('Positives credits in admin''s currency are imported'
        , 400
        , (Select Cast(ENTRIES_ADMIN_CREDIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 9)
    );
    Call utAssert_eq('Positives debits in admin''s currency are imported'
        , 400
        , (Select Cast(ENTRIES_ADMIN_DEBIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 11)
    );

    -- assertions about negatives amounts
    Call utAssert_eq('Negatives credits aren''t imported'
        , Null
        , (Select Cast(ENTRIES_CREDIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 2)
    );
    Call utAssert_eq('Negatives debits aren''t imported'
        , Null
        , (Select Cast(ENTRIES_DEBIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 4)
    );
    Call utAssert_eq('Negatives credits in entity''s currency aren''t imported'
        , Null
        , (Select Cast(ENTRIES_ENT_CREDIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 6)
    );
    Call utAssert_eq('Negatives debits in entity''s currency aren''t imported'
        , Null
        , (Select Cast(ENTRIES_ENT_DEBIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 8)
    );
    Call utAssert_eq('Negatives credits in admin''s currency aren''t imported'
        , Null
        , (Select Cast(ENTRIES_ADMIN_CREDIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 10)
    );
    Call utAssert_eq('Negatives debits in admin''s currency aren''t imported'
        , Null
        , (Select Cast(ENTRIES_ADMIN_DEBIT as Unsigned Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 12)
    );


    -- cleans
    Call LOADER_TEST_MOCK_ENTRIES_CLEAN();

    

End//
Delimiter ;