/**
 * Class: userVoiceUtil_Test
 * Author: Patrick Brinksma - Technical Architect at Salesforce.com
 * Purpose: Test class for userVoiceUtil class
 * Log:
 * 26 Mar 2014	Patrick Brinksma	Created
 */
@isTest
private class userVoiceUtil_Test{

    // Main method to test userVoiceUtil class
    static TestMethod void testUserVoiceUtil() {
        
        // Get admin user of this org
        User tstUser = [
                        select
                                Id,
            					FirstName,
            					LastName,
                                UserName,
                                Email,
                                LanguageLocaleKey
                        from
                                User
                        where
                                Profile.Name = 'System Administrator' and
                                isActive = true
                                limit 1
                    	];
        
        // Run util using admin user
        System.runAs( tstUser ) {
            
            Test.startTest();
            
            String expires = System.now().addHours(1).formatGmt( 'yyyy-MM-dd HH:mm:ss' );
        	String encData = userVoiceUtil.createSSOToken(tstUser.LanguageLocaleKey, 'userGuid', 'deny', true, false, new List<Integer>{10001}, new List<Integer>{10002,10003});
            
            Test.stopTest();
            
            String decData = userVoiceUtil.decrypt( encData );
            
            Map<String, Object> mapOfStringToObject = ( Map<String, Object> )JSON.deserializeUntyped( decData );
            
            System.assertEquals( 'deny', ( String )mapOfStringToObject.get( 'admin' ) );
			System.assertEquals( new List<Object>{ 10001 }, ( List<Object> )mapOfStringToObject.get( 'allow_forums' ) );
            System.assertEquals( false, ( Boolean )mapOfStringToObject.get( 'comment_updates' ) );
            System.assertEquals( new List<Object>{ 10002, 10003 }, ( List<Object> )mapOfStringToObject.get( 'deny_forums' ) );
            String displayName = '';
            if ( tstUser.FirstName != null ) {
                displayName = tstUser.FirstName + ' ';
            }
            System.assertEquals( displayName + tstUser.LastName, ( String )mapOfStringToObject.get( 'display_name' ) );
            System.assertEquals( tstUser.Email, ( String )mapOfStringToObject.get( 'email' ) );
            System.assertEquals( expires, ( String )mapOfStringToObject.get( 'expires' ) );
            System.assertEquals( 'userGuid', ( String )mapOfStringToObject.get( 'guid' ) );
            System.assertEquals( tstUser.LanguageLocaleKey, ( String )mapOfStringToObject.get( 'locale' ) );
            System.assertEquals( true, ( Boolean )mapOfStringToObject.get( 'updates' ) );
        }
        
    }
    
}