Delimiter //
/**	
 * Test of "Checksthe $col$ length"
 * 
 * @tested LOADER_CHECK_FIELD_LENGTH()
 */
Drop Procedure if exists TEST_LOADER_CHECK_FIELD_LENGTH//
Create Procedure TEST_LOADER_CHECK_FIELD_LENGTH()
Begin

    -- Initial dataset
    Call LOADER_TEST_MOCK_STATUS_CLEAN();
    
    Drop Temporary Table If Exists TABLE_TEST_LOADER_CHECK_FIELD_LENGTH ;
    Create Temporary Table TABLE_TEST_LOADER_CHECK_FIELD_LENGTH (
        LOADER_STATUS_ID_LOADER_STATUS int not null primary key, 
        CODE varchar(20) null, 
        LIBELLE varchar(50)
    );

    Call LOADER_TEST_MOCK_STATUS_PUSH(1, Null);
    Call LOADER_TEST_MOCK_STATUS_PUSH(2, Null);
    Call LOADER_TEST_MOCK_STATUS_PUSH(3, Null);
    Call LOADER_TEST_MOCK_STATUS_PUSH(4, Null);

	Insert Into TABLE_TEST_LOADER_CHECK_FIELD_LENGTH(LOADER_STATUS_ID_LOADER_STATUS, CODE, LIBELLE) 
	Values 
		(1, 'A', 'BCD'),
		(2, '', 'EFG'),
		(3, null, 'HIJ'),
		(4, 'KLMNOPQRSTUBW', 'XYZ')
	;

    -- Procedure test
    CALL LOADER_CHECK_FIELD_LENGTH (
            'TABLE_TEST_LOADER_CHECK_FIELD_LENGTH'
            , 'CODE'
            , 1
            , 5
            , 'BATCH_NUM'
            , 1
            , 'ERR_CNT'
            , 'ERR_MSG'
            , null
            , null
		);

    -- Assertions
    CALL utAssert_eq('Table with too long content are flagged'
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 3)
    );

    CALL utAssert_eq('Contacts with a too short content are flagged'
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2)
    );

    CALL utAssert_eq('Contacts with a correct content len are not flagged' 
        , 0
        , (SELECT Coalesce(LOADER_STATUS_ERRCOUNT, 0) FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1) 
    );
    
    -- clean
    Drop Temporary Table TABLE_TEST_LOADER_CHECK_FIELD_LENGTH;
    Call LOADER_TEST_MOCK_STATUS_CLEAN();

End //
Delimiter ;