package integration.anyframe.services.cache;

import integration.anyframe.services.AbstractTest;
import anyframe.core.cache.ICacheService;

/**
 * DefaultCacheService가 제공하는 기능을 테스트하기 위한 샘플 테스트 코드
 */
public class CacheServiceTest extends AbstractTest {
	/**
	 * 테스트 수행을 위한 main
	 */
	public static void main(String[] args) throws Exception {
		CacheServiceTest cacheTest = new CacheServiceTest();

		// 1. initialize context
		cacheTest.setup();
		// 2. test
		cacheTest.testGetFromCache();
		// 3. close context
		cacheTest.teardown();
		
		System.out.println("Successful!!!!!!");
	}

	/**
	 * DefaultCacheService를 통해 'KEY-1'을 key로 하여 'VALUE-1'을 특정 Cache에 저장한 후, 해당
	 * Cache로부터 'KEY-1'의 값을 추출해 보는 테스트
	 */
	public void testGetFromCache() throws Exception {
		ICacheService cacheService = (ICacheService) context
				.getBean("cacheService");
		// 1. Put a content in cache.
		cacheService.putInCache("KEY-1", "VALUE-1");
		// 2. Get that item from Cache.
		Object value = cacheService.getFromCache("KEY-1");
		// 3. assert
		boolean checked = ((String) value).equals("VALUE-1");
		if (!checked) throw new Exception("fail to get from cache.");
	}

	@Override
	protected String[] getConfigLocations() {
		// TODO Auto-generated method stub
		return new String[]{"classpath*:/common/applicationContext-*.xml","classpath*:/services/cache/applicationContext-*.xml"};
	}
}

