package flex.spring.samples.industry;

import java.util.List;

import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

public class IbatisIndustryDAOTests extends AbstractDependencyInjectionSpringContextTests{

	private IIndustryDAO dao;
	
	public void testFindById() {
		Industry Industry = dao.findById(1);
		assertNotNull(Industry);
		assertEquals(1, Industry.getId());
	}
	
	public void testFindAll() {
		List<Industry> companies = dao.findAll();
		assertEquals(6, companies.size());
	}
	
	public void testFindByName() {
		List<Industry> companies = dao.findByName("Government");
		assertEquals(1, companies.size());
		assertEquals("Government", companies.get(0).getName());
	}
	
	public void testUpdate() {
		Industry industry = dao.findById(1);
		assertNotNull(industry);
		String oldName = industry.getName();
		industry.setName("Geekery");
		assertTrue(dao.update(industry));
		industry = dao.findById(1);
		assertEquals("Geekery",industry.getName());
		industry.setName(oldName);
		assertTrue(dao.update(industry));
	}
	
	public void testRemoveAndInsert() {
		Industry industry = dao.findByName("Education").get(0);
		int originalId = industry.getId();
		assertNotNull(industry);
		assertTrue(dao.remove(industry));
		industry.setId(-1);
		industry = dao.create(industry);
		assertNotNull(industry);
		assertEquals(originalId+1, industry.getId());
	}
	
	@Override
	protected String[] getConfigLocations() {
		return new String[] {"classpath:flex/spring/samples/industry/my-industry-dao-test-context.xml"};
	}



	public IIndustryDAO getDao() {
		return dao;
	}



	public void setDao(IIndustryDAO dao) {
		this.dao = dao;
	}
	
	
}
