package in.co.sunrays.proj1.service.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.dto.StudentDTO; import in.co.sunrays.proj1.service.StudentServiceInt; 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 Service Test class * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class StudentServiceTestCase { /** * Get the instance of StudentService Class */ XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource( "applicationContext.xml")); StudentServiceInt service = (StudentServiceInt) beanFactory .getBean("studentService"); /** * @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.service.StudentServiceSpringImpl#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.setCreatedBy("Admin"); dto.setModifiedBy("Admin"); dto.setCreatedDatetime(new Timestamp(new Date().getTime())); dto.setModifiedDatetime(new Timestamp(new Date().getTime())); long pk = service.add(dto); dto = service.findByPK(pk); assertNotNull("Error : Test Add Fail", dto); System.out.println("Success : Test Add Success"); } /** * Test method for * {@link in.co.sunrays.proj1.service.StudentServiceSpringImpl#update(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Ignore public void testUpdate() throws Exception { StudentDTO dto = service.findByPK(2l); dto.setFirstName("Alok"); dto.setLastName("Mishra"); service.update(dto); StudentDTO updatedDTO = service.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.service.StudentServiceSpringImpl#delete(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Ignore public void testDelete() throws Exception { StudentDTO dto = new StudentDTO(); dto.setId(2l); service.delete(dto); dto = service.findByPK(dto.getId()); assertNull("Error : Delete Test Fail", dto); System.out.println("Success : Test Delete Success"); } /** * Test method for * {@link in.co.sunrays.proj1.service.StudentServiceSpringImpl#findByPK(int)} * . * * @throws Exception */ @Ignore public void testFindByPK() throws Exception { StudentDTO dto = service.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.service.StudentServiceSpringImpl#findByEmail(java.lang.String)} * . * * @throws Exception */ @Ignore public void testFindByEmail() throws Exception { StudentDTO dto = service.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.service.StudentServiceSpringImpl#search(in.co.sunrays.proj1.dto.StudentDTO)} * . * * @throws Exception */ @Ignore public void testSearchStudentDTO() throws Exception { StudentDTO dto = new StudentDTO(); dto.setFirstName("R"); List list = service.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.service.StudentServiceSpringImpl#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 = service.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.service.StudentServiceSpringImpl#list()}. * * @throws Exception */ @Ignore public void testList() throws Exception { List list = service.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.service.StudentServiceSpringImpl#list(int, int)} * . * * @throws Exception */ @Ignore public void testListIntInt() throws Exception { List list = service.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()); } } } |