/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package integration.anyframe.services.logging;

import integration.anyframe.services.AbstractTest;
import integration.anyframe.services.logging.sample.LoggingSampleService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * LoggingService가 제공하는 기능을 테스트하기 위한 샘플 테스트 코드
 */
public class LoggingServiceTest extends AbstractTest {
	/**
	 * 테스트 수행을 위한 main
	 */
	public static void main(String[] args) throws Exception {
		LoggingServiceTest loggingservice = new LoggingServiceTest();

		// 1. initialize context
		loggingservice.setup();
		// 2. test
		loggingservice.testLogging();
		// 3. test sample logging servicet
		loggingservice.testSampleLogging();
		// 4. close context
		loggingservice.teardown();

		System.out.println("Successful!!!!!");
	}

	/**
	 * SERVER_ROOT/common/conf/log4j.xml 파일 설정에 따라 Logger명이
	 * integration.systemier.services.logging.LoggingServiceTest인 Logger를 찾고, 해당
	 * Logger를 통해 로그 메시지를 남겨보고 해당 Logger의 레벨이 DEBUG 가능한지 체크해보는 테스트
	 */
	public void testLogging() throws Exception {
		Log logger = LogFactory.getLog(LoggingServiceTest.class);
		logger.debug("Sample DEBUG Message.");
		logger.info("Sample Info Message.");
		logger.warn("Sample Warning Message.");
		logger.error("Sample Error Message.");
		logger.fatal("Sample Fatal Message.");
		if (!logger.isDebugEnabled())
			throw new Exception("fail to get Logger");
	}

	/**
	 * SampleLoggingService를 이용하여 로그 메시지를 남겨보는 테스트
	 * @throws Exception
	 */
	public void testSampleLogging() throws Exception {
		LoggingSampleService sample = (LoggingSampleService) context
				.getBean(LoggingSampleService.ROLE);
		sample.greet();
	}
	protected String[] getConfigLocations() {
		// TODO Auto-generated method stub
		return new String[]{"classpath*:/common/applicationContext-*.xml","classpath*:/applications/loggingsample/applicationContext-*.xml"};
	}
}

