Source Code‎ > ‎src‎ > ‎in.co.sunrays.proj1‎ > ‎dao‎ > ‎test‎ > ‎

CollegeDAOTestCase.java

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.CollegeDAOInt;
import in.co.sunrays.proj1.dto.CollegeDTO;
 
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;
 
/**
 * College DAO Test class
 * 
 * @author SUNRAYS Technologies
 * @version 1.0
 * @Copyright (c) SUNRAYS Technologies
 */
public class CollegeDAOTestCase {
 
    /**
     * Get the instance of CollegeDAO class
     */
    XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
            "applicationContext.xml"));
    CollegeDAOInt dao = (CollegeDAOInt) beanFactory.getBean("collegeDAO");
 
    /**
     * @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.CollegeDAOHibImpl#add(in.co.sunrays.proj1.dto.CollegeDTO)}
     * .
     * 
     * @throws Exception
     */
    @Test
    public void testAdd() throws Exception {
        CollegeDTO dto = new CollegeDTO();
        dto.setName("SVITS");
        dto.setPhoneNo("9999988888");
        dto.setAddress("Sanver Road");
        dto.setCity("Indore");
        dto.setState("Madhya Pradesh");
        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.CollegeDAOHibImpl#update(in.co.sunrays.proj1.dto.CollegeDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testUpdate() throws Exception {
        CollegeDTO dto = dao.findByPK(1l);
        dto.setName("Truba");
        dto.setAddress("Khandwa Road");
        dao.update(dto);
 
        CollegeDTO 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.CollegeDAOHibImpl#delete(in.co.sunrays.proj1.dto.CollegeDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testDelete() throws Exception {
        CollegeDTO dto = new CollegeDTO();
        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.CollegeDAOHibImpl#findByName(java.lang.String)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testFindByName() throws Exception {
        CollegeDTO dto = dao.findByName("SVITS");
 
        assertNotNull("Error : Test Get By Name Fail", dto);
 
        System.out.println(dto.getValue());
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.dao.CollegeDAOHibImpl#findByPK(long)}.
     * 
     * @throws Exception
     */
    @Ignore
    public void testFindByPK() throws Exception {
        CollegeDTO dto = dao.findByPK(1l);
 
        assertNotNull("Error : Test Get By Id Fail", dto);
 
        System.out.println(dto.getId());
        System.out.println(dto.getName());
        System.out.println(dto.getAddress());
        System.out.println(dto.getPhoneNo());
        System.out.println(dto.getCity());
        System.out.println(dto.getState());
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.dao.CollegeDAOHibImpl#search(in.co.sunrays.proj1.dto.CollegeDTO, int, int)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testSearchCollegeDTOIntInt() throws Exception {
        CollegeDTO dto = new CollegeDTO();
        dto.setName("S");
 
        List list = dao.search(dto, 1, 5);
 
        assertTrue(" Error : Test Search Fail", list.size() > 0);
 
        Iterator it = list.iterator();
        while (it.hasNext()) {
            dto = (CollegeDTO) it.next();
            System.out.println(dto.getValue());
        }
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.dao.CollegeDAOHibImpl#search(in.co.sunrays.proj1.dto.CollegeDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testSearchCollegeDTO() throws Exception {
        CollegeDTO dto = new CollegeDTO();
        dto.setName("S");
 
        List list = dao.search(dto);
 
        assertTrue("Error : Test Search Fail", list.size() > 0);
 
        Iterator it = list.iterator();
        while (it.hasNext()) {
            dto = (CollegeDTO) it.next();
            System.out.println(dto.getValue());
        }
    }
 
    /**
     * Test method for {@link in.co.sunrays.proj1.dao.CollegeDAOHibImpl#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()) {
            CollegeDTO dto = (CollegeDTO) it.next();
            System.out.println(dto.getValue());
        }
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.dao.CollegeDAOHibImpl#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()) {
            CollegeDTO dto = (CollegeDTO) it.next();
            System.out.println(dto.getValue());
        }
    }
 
}
Comments