/*
 * 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 anyframe.core.hibernate.spring;

import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

import anyframe.common.util.DateUtil;
import anyframe.sample.model.bidirection.Movie;
import anyframe.sample.service.movie.MovieService;

/**
 * TestCase Name : HibernateSpringIntegrationTest<br>
 * <br>
 * [Description] : Hibernate과 Spring을 연계하여 특정 객체를 DB에 등록/수정/삭제/조회해 본다.<br>
 * [Main Flow]
 * <ul>
 * <li>#-1 Positive Case : Hibernate과 Spring Framework을 연계한 MovieService를 통해
 * 단건의 Movie 정보를 등록,수정,삭제,조회하여 본다.</li>
 * </ul>
 * 
 * @author SoYon Lim
 */
public class HibernateSpringIntegrationTest extends
		AbstractDependencyInjectionSpringContextTests {
	private MovieService movieService;

	protected String[] getConfigLocations() {
		return new String[] { "classpath*:/anyframe/core/hibernate/spring/context-*.xml" };
	}

	public void setMovieService(MovieService movieService) {
		this.movieService = movieService;
	}

	/**
	 * [Flow #-1] Positive Case : Hibernate과 Spring Framework을 연계한 MovieService를
	 * 통해 단건의 Movie 정보를 등록,수정,삭제,조회하여 본다.
	 * 
	 * @throws Exception
	 *             throws exception which is from MovieService
	 */
	public void testMovieService() throws Exception {
		Movie movie = new Movie();
		movie.setMovieId("MV-00001");
		movie.setDirector("Jaeyong Gwak");
		movie.setReleaseDate(DateUtil.string2Date("2001-07-27", "yyyy-MM-dd"));
		movie.setTitle("My Sassy Girl");
		movieService.createMovie(movie);

		Movie result = movieService.findMovie("MV-00001");
		assertNotNull("fail to add a new movie.", result);

		movie.setDirector("Update Jaeyong Gwak");
		movieService.updateMovie(movie);

		result = movieService.findMovie("MV-00001");
		assertEquals("fail to update a new movie.", "Update Jaeyong Gwak",
				result.getDirector());

		movieService.removeMovie(movie);
		result = movieService.findMovie("MV-00001");
		assertNull("fail to remove a movie.", result);
	}
}

