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.MarksheetDAOInt; import in.co.sunrays.proj1.dto.MarksheetDTO; 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; /** * Marksheet DAO Test class * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class MarksheetDAOTestCase { /** * Get the instance of MarksheetDAO class */ XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource( "applicationContext.xml")); MarksheetDAOInt dao = (MarksheetDAOInt) beanFactory.getBean("marksheetDAO"); /** * @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.MarksheetDAOHibImpl#add(in.co.sunrays.proj1.dto.MarksheetDTO)} * . * * @throws Exception */ @Test public void testAdd() throws Exception { MarksheetDTO dto = new MarksheetDTO(); dto.setRollNo("101"); dto.setStudentId(1); dto.setName("Rahul Sahu"); dto.setPhysics(99); dto.setChemistry(99); dto.setMaths(99); 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.MarksheetDAOHibImpl#update(in.co.sunrays.proj1.dto.MarksheetDTO)} * . * * @throws Exception */ @Ignore public void testUpdate() throws Exception { MarksheetDTO dto = dao.findByPK(1l); dto.setName("Alok Mishra"); dao.update(dto); MarksheetDTO updatedDTO = dao.findByPK(1l); assertEquals("Error : Test Update Fail", dto.getName(), updatedDTO.getName()); System.out.println("Success : Test Update Success"); } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#delete(in.co.sunrays.proj1.dto.MarksheetDTO)} * . * * @throws Exception */ @Ignore public void testDelete() throws Exception { MarksheetDTO dto = new MarksheetDTO(); 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.MarksheetDAOHibImpl#findByRollNo(java.lang.String)} * . * * @throws Exception */ @Ignore public void testFindByRollNo() throws Exception { MarksheetDTO dto = dao.findByRollNo("101"); assertNotNull("Error : Test Get By Roll No Fail", dto); System.out.println(dto.getName()); } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#findByPK(long)}. * * @throws Exception */ @Ignore public void testFindByPK() throws Exception { MarksheetDTO dto = dao.findByPK(1l); assertNotNull("Error : Test Get By Id Fail", dto); System.out.println(dto.getId()); System.out.println(dto.getRollNo()); System.out.println(dto.getName()); System.out.println(dto.getPhysics()); System.out.println(dto.getChemistry()); System.out.println(dto.getMaths()); System.out.println(dto.getCreatedBy()); System.out.println(dto.getCreatedDatetime()); } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#search(in.co.sunrays.proj1.dto.MarksheetDTO)} * . * * @throws Exception */ @Ignore public void testSearchMarksheetDTO() throws Exception { MarksheetDTO dto = new MarksheetDTO(); dto.setName("R"); List list = dao.search(dto); assertTrue("Error : Test Search Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { dto = (MarksheetDTO) it.next(); System.out.println(dto.getName()); } } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#search(in.co.sunrays.proj1.dto.MarksheetDTO, int, int)} * . * * @throws Exception */ @Ignore public void testSearchMarksheetDTOIntInt() throws Exception { MarksheetDTO dto = new MarksheetDTO(); dto.setName("R"); List list = dao.search(dto, 1, 5); assertTrue(" Error : Test Search Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { dto = (MarksheetDTO) it.next(); System.out.println(dto.getName()); } } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#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()) { MarksheetDTO dto = (MarksheetDTO) it.next(); System.out.println(dto.getName()); } } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#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()) { MarksheetDTO dto = (MarksheetDTO) it.next(); System.out.println(dto.getName()); } } /** * Test method for * {@link in.co.sunrays.proj1.dao.MarksheetDAOHibImpl#getMeritList(int, int)} * . * * @throws Exception */ @Ignore public void testgetMeritListIntInt() throws Exception { List list = dao.getMeritList(1, 5); assertTrue("Error : Test List Fail", list.size() > 0); Iterator it = list.iterator(); while (it.hasNext()) { MarksheetDTO dto = (MarksheetDTO) it.next(); System.out.println(dto.getName()); } } } |