/*
 * 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.properties;

import integration.anyframe.services.AbstractTest;
import anyframe.core.properties.IPropertiesService;

/**
 * PropertiesService가 제공하는 기능을 테스트하기 위한 샘플 테스트 코드
 */
public class PropertiesServiceTest extends AbstractTest {
	/**
	 * 테스트 수행을 위한 main
	 */
	public static void main(String[] args) throws Exception {

		PropertiesServiceTest propertiesTest = new PropertiesServiceTest();

		// 1. initialize context
		propertiesTest.setup();
		// 2. test
		propertiesTest.testPropertiesService();
		// 3. close context
		propertiesTest.teardown();

		System.out.println("Successful!!!!!!");
	}

	/**
	 * PropertiesService의 getString, getDouble을 통해 String, double 타입의 데이터 값을
	 * 얻어오는 테스트
	 */
	public void testPropertiesService() throws Exception {

		IPropertiesService propertiesService = (IPropertiesService) context
				.getBean("propertiesService");
		// 1. property element로 정의된 "AAAA"를 얻는다.
		if (propertiesService.getString("AAAA") == null)
			throw new Exception("fail to getString of propertiesService");
		// 2. properties에 정의되어있는 number.double의 값을 가지고 온다.
		if (!new Double(propertiesService.getDouble("number.double"))
				.equals(new Double(1234)))
			;
	}

	protected String[] getConfigLocations() {
		// TODO Auto-generated method stub
		return new String[] { "classpath*:/common/applicationContext-*.xml",
				"classpath*:/services/properties/applicationContext-*.xml"};
	}
}

