package test.org.seasar.hibernate.dao.impl;

import java.util.List;

import org.seasar.extension.dataset.DataSet;
import org.seasar.extension.unit.S2TestCase;

import examples.hibernate.dao.EmployeeAutoDao;
import examples.hibernate.entity.Employee;

public class EmployeeDaoTest extends S2TestCase {

	private EmployeeAutoDao employeeDao_;
	/**
	 * Constructor for S2SessionFactoryImplTest.
	 * @param arg0
	 */
	public EmployeeDaoTest(String arg0) {
		super(arg0);
	}

	public static void main(String[] args) {
		junit.textui.TestRunner.run(EmployeeDaoTest.class);
	}

	/*
	 * @see TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();

		include("examples/hibernate/client/EmployeeAutoDao.dicon");
	}

	/*
	 * @see TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testGetAllUserListTx() {
		List ret = employeeDao_.getAllEmployee();
		assertNotNull("1", employeeDao_.getAllEmployee() );
		DataSet expected = readXls("EMP.xls");
		assertEquals("2",expected,  ret);

	}

	public void testGetUserTx() {
		assertEquals(3, employeeDao_.getEmployeeByJobDeptno(null, (short)10 ).size() );
	}


	public void testSaveTx(){

		Employee emp = new Employee();
		emp.setEmpno( 100010);
		emp.setEname("test");
		emp.setDeptno((short)10);
					
		employeeDao_.save( emp ) ;
		Employee emp2 = employeeDao_.getEmployeeByEmpNo( (long)100010 ) ;
		assertEquals("test",emp2.getEname() );
	}

	public void testDeleteTx() {
		Employee emp = new Employee();
		emp.setEmpno( 100010);
		emp.setEname("test");
		emp.setDeptno((short)10);
					
		employeeDao_.save( emp ) ;
		
		Employee empTmp = employeeDao_.getEmployeeByEmpNo( (long)100010 ) ;
		employeeDao_.delete( empTmp );
		
		assertNull( "1",employeeDao_.getEmployeeByEmpNo( (long)100010 ) ) ;
	}

	public void testGetEmployeeList() {
		List ret = employeeDao_.getEmployeeList( 8,4 ) ;
		assertEquals("1",4,ret.size() );
		
		DataSet expected = readXls("EMP_GetEmployeeList.xls");
		assertEquals("2",expected,  ret);
	}
	
	public void testGetEmployeeCount() {
		int ret = employeeDao_.getEmployeeCount() ;
		assertEquals(13,ret );
	}

	public void testGetEmployeeNameById() {
		String ret = employeeDao_.getEmployeeNameById(new Long(7369) ) ;
		assertEquals("SMITH",ret );
	}
	
	public void testGetEmployeeByJob() {
		List ret = employeeDao_.getEmployeeByJob("MANAGER");
		DataSet expected = readXls("EMP_MANAGER.xls");
		assertEquals("1",expected,  ret);
	}
	
	public void testGetSQLEmployeeNameById() {
		String ret = employeeDao_.getSQLEmployeeNameById(new Long(7369) ) ;
		assertEquals("SMITH",ret );
	}

	public void testGetSQLEmployeeIdByName() {
		Long ret = employeeDao_.getSQLEmployeeIdByName("SMITH") ;
		assertEquals(new Long(7369),ret );
	}

	public void testGetAllEmployee() {
		List ret = employeeDao_.getAllEmployee() ;
		assertEquals(13,ret.size() );
	}
	
	
	
}