/**
 * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
 *
 * This file is part of fiware-cosmos (FI-WARE project).
 *
 * fiware-cosmos is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
 * General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * fiware-cosmos is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along with fiware-cosmos. If not, see
 * http://www.gnu.org/licenses/.
 *
 * For those usages not covered by the GNU Affero General Public License please contact with iot_support at tid dot es
 */
package com.telefonica.iot.cosmos.hive.authprovider;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 *
 * @author frb
 */
public class OAuth2CacheTest {
    
    /**
     * Tests OAuth2Cache.isCached, it must return true when user and token exist.
     */
    @Test
    public void testIsCachedUserAndTokenOK() {
        System.out.println("Testing OAuth2Cache.isCached, it must return true when user and token exist");
        String user = "user";
        String token = "token";
        OAuth2Cache cache = new OAuth2Cache("");
        cache.addToCache(user, token);
        
        if (cache.isCached(user, token)) {
            assertTrue(true);
        } else {
            assertTrue(false);
        } // if else
    } // testIsCachedUserAndTokenOK
    
    /**
     * Tests OAuth2Cache.isCached, it must return false when user exist, but token does not exist.
     */
    @Test
    public void testIsCachedUserOKTokenNotOK() {
        System.out.println("Testing OAuth2Cache.isCached, it must return false when user exist, "
                + "but token does not exist");
        String user = "user";
        String token1 = "token1";
        String token2 = "token2";
        OAuth2Cache cache = new OAuth2Cache("");
        cache.addToCache(user, token1);
        
        if (cache.isCached(user, token2)) {
            assertTrue(false);
        } else {
            assertTrue(true);
        } // if else
    } // testIsCachedUserOKTokenNotOK
    
    /**
     * Tests OAuth2Cache.isCached, it must return false when both user and token do not exist.
     */
    @Test
    public void testIsCachedUserAndTokenNotOK() {
        System.out.println("Testing OAuth2Cache.isCached, it must return false when both user and token do not exist");
        String user = "user";
        String token = "token";
        OAuth2Cache cache = new OAuth2Cache("");
        
        if (cache.isCached(user, token)) {
            assertTrue(false);
        } else {
            assertTrue(true);
        } // if else
    } // testIsCachedUserAndTokenNotOK
    
} // OAuth2CacheTest

@@ -2991,16 +2991,1641 @@
 OK%0A    %0A
+    /**%0A     * Tests OAuth2Cache.addToCache, a (user, token) pair must be added when not existing.%0A     */%0A    @Test%0A    public void testAddToCacheWhenNotExisting() %7B%0A        System.out.println(%22Testing OAuth2Cache.addToCache, a (user, token) pair must be added when not existing%22);%0A        String user = %22user%22;%0A        String token = %22token%22;%0A        OAuth2Cache cache = new OAuth2Cache(%22%22);%0A        %0A        if (cache.isCached(user, token)) %7B%0A            assertTrue(false);%0A        %7D else %7B%0A            cache.addToCache(user, token);%0A%0A            if (cache.isCached(user, token)) %7B%0A                assertTrue(true);%0A            %7D else %7B%0A                assertTrue(false);%0A            %7D // if else%0A        %7D // if else%0A    %7D // testAddToCacheWhenNotExisting%0A    %0A    /**%0A     * Tests OAuth2Cache.addToCache, a (user, token) pair must be added when the user already exists (token update).%0A     */%0A    @Test%0A    public void testAddToCacheWhenUserExists() %7B%0A        System.out.println(%22Testing OAuth2Cache.addToCache, a (user, token) pair must be added when the user already %22%0A                + %22exists (token update)%22);%0A        String user = %22user%22;%0A        String token1 = %22token1%22;%0A        String token2 = %22token2%22;%0A        OAuth2Cache cache = new OAuth2Cache(%22%22);%0A        cache.addToCache(user, token1);%0A        cache.addToCache(user, token2);%0A        %0A        if (cache.isCached(user, token1)) %7B%0A            assertTrue(false);%0A        %7D else if (cache.isCached(user, token2)) %7B%0A            assertTrue(true);%0A        %7D else %7B%0A            assertTrue(false);%0A        %7D // if else%0A    %7D // testAddToCacheWhenNotExisting%0A    %0A
 %7D // OAu

Add more tests