package in.co.sunrays.proj1.dao.test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import in.co.sunrays.proj1.dao.StudentDAOInt; import in.co.sunrays.proj1.dto.StudentDTO; import java.sql.Timestamp; import java.util.Date; import java.util.Iterator; import java.util.List; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; /** * Student DAO Test class * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class StudentDAOTestCase { /** * Get the instance of StudentDAO class */ XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource( "applicationContext.xml")); StudentDAOInt dao = (StudentDAOInt) beanFactory.getBean("studentDAO"); /** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { System.out.println("Test setUpBeforeClass is called"); } /** * @throws java.lang.Exception */ @AfterClass public static void tearDownAfterClass() throws Exception { System.out.println("Test tearDownAfterClass is called"); } /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { System.out.println("Test setUp is called"); } /** * @throws java.lang.Exception */ @After public void tearDown() throws Exception { System.out.println("Test tearDown is called"); } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#add(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Test public void testAdd() throws Exception { StudentDTO dto = new StudentDTO(); dto.setFirstName("Rahul"); dto.setLastName("Sahu"); dto.setDob(new Date("1995/04/16")); dto.setMobileNo("9999988888"); dto.setEmail("rahul.sahu@sunrays.co.in"); dto.setCollegeId(1); dto.setCollegeName("SVITS"); dto.setCreatedBy("Admin"); dto.setModifiedBy("Admin"); dto.setCreatedDatetime(new Timestamp(new Date().getTime())); dto.setModifiedDatetime(new Timestamp(new Date().getTime())); long pk = dao.add(dto); dto = dao.findByPK(pk); assertNotNull("Error : Test Add Fail", dto); System.out.println("Success : Test Add Success"); } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#update(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Ignore public void testUpdate() throws Exception { StudentDTO dto = dao.findByPK(1l); dto.setFirstName("Alok"); dto.setLastName("Mishra"); dao.update(dto); StudentDTO updatedDTO = dao.findByPK(1l); assertEquals("Error : Test Update Fail", dto.getValue(), updatedDTO.getValue()); System.out.println("Success : Test Update Success"); } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#delete(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Ignore public void testDelete() throws Exception { StudentDTO dto = new StudentDTO(); dto.setId(2l); dao.delete(dto); dto = dao.findByPK(dto.getId()); assertNull("Error : Delete Test Fail", dto); System.out.println("Success : Test Delete Success"); } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#findByEmail(java.lang.String)} * . * * @throws Exception */ @Ignore public void testFindByEmail() throws Exception { StudentDTO dto = dao.findByEmail("rahul.sahu@sunrays.co.in"); assertNotNull("Error : Test Get By Email Fail", dto); System.out.println(dto.getValue()); } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#findByPK(long)}. * * @throws Exception */ @Ignore public void testFindByPK() throws Exception { StudentDTO dto = dao.findByPK(1l); assertNotNull("Error : Test Get By Id Fail", dto); System.out.println(dto.getId()); System.out.println(dto.getFirstName()); System.out.println(dto.getLastName()); System.out.println(dto.getDob()); System.out.println(dto.getMobileNo()); System.out.println(dto.getEmail()); System.out.println(dto.getCreatedBy()); System.out.println(dto.getCreatedDatetime()); } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#search(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Ignore public void testSearchStudentDTO() throws Exception { StudentDTO dto = new StudentDTO(); dto.setFirstName("R"); List list = dao.search(dto); assertTrue("Error : Test Search Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { dto = (StudentDTO) it.next(); System.out.println(dto.getValue()); } } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#search(in.co.sunrays.proj1.dto.StudentDTO, int, int)} * . * * @throws Exception */ @Ignore public void testSearchStudentDTOIntInt() throws Exception { StudentDTO dto = new StudentDTO(); dto.setFirstName("R"); List list = dao.search(dto, 1, 5); assertTrue(" Error : Test Search Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { dto = (StudentDTO) it.next(); System.out.println(dto.getValue()); } } /** * Test method for {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#list()}. * * @throws Exception */ @Ignore public void testList() throws Exception { List list = dao.list(); assertTrue("Error : Test List Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { StudentDTO dto = (StudentDTO) it.next(); System.out.println(dto.getValue()); } } /** * Test method for * {@link in.co.sunrays.proj1.dao.StudentDAOHibImpl#list(int, int)}. * * @throws Exception */ @Ignore public void testListIntInt() throws Exception { List list = dao.list(1, 5); assertTrue("Error : Test List Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { StudentDTO dto = (StudentDTO) it.next(); System.out.println(dto.getValue()); } } } |