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

UserServiceTestCase.java

package in.co.sunrays.proj1.service.test;
 
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import in.co.sunrays.proj1.dto.UserDTO;
import in.co.sunrays.proj1.service.UserServiceInt;
 
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;
 
/**
 * User Service Test class
 * 
 * @author SUNRAYS Technologies
 * @version 1.0
 * @Copyright (c) SUNRAYS Technologies
 */
public class UserServiceTestCase {
 
    /**
     * Get the instance of UserService Class
     */
    XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
            "applicationContext.xml"));
    UserServiceInt service = (UserServiceInt) beanFactory
            .getBean("userService");
 
    /**
     * @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.UserServiceSpringImpl#add(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Test
    public void testAdd() throws Exception {
        UserDTO dto = new UserDTO();
        dto.setFirstName("Rahul");
        dto.setLastName("Sahu");
        dto.setLogin("rahul.sahu@sunrays.co.in");
        dto.setPassword("pass1234");
        dto.setMobileNo("9988776655");
        dto.setRoleId(1l);
        dto.setUnSuccessfulLogin(0);
        dto.setLastLogin(new Timestamp(new Date().getTime()));
        dto.setGender("Male");
        dto.setDob(new Date());
        dto.setLock(UserDTO.INACTIVE);
        dto.setRegisteredIP("192.168.1.16");
        dto.setLastLoginIP("192.168.1.4");
        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("Suucess : Test Add Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#registerUser(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testRegisterUser() throws Exception {
        UserDTO dto = new UserDTO();
        dto.setFirstName("Rahul");
        dto.setLastName("Sahu");
        dto.setLogin("rahul.sahu@sunrays.co.in");
        dto.setPassword("pass1234");
        dto.setRoleId(1l);
        dto.setUnSuccessfulLogin(0);
        dto.setLastLogin(new Timestamp(new Date().getTime()));
        dto.setGender("Male");
        dto.setDob(new Date());
        dto.setLock(dto.INACTIVE);
        dto.setRegisteredIP("192.168.1.16");
        dto.setLastLoginIP("192.168.1.4");
        dto.setCreatedBy("Admin");
        dto.setModifiedBy("Admin");
        dto.setCreatedDatetime(new Timestamp(new Date().getTime()));
        dto.setModifiedDatetime(new Timestamp(new Date().getTime()));
 
        long pk = service.registerUser(dto);
        dto = service.findByPK(pk);
 
        assertNotNull("Error : Test Add Fail", dto);
 
        System.out.println("Suucess : Test Add Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#update(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testUpdate() throws Exception {
        UserDTO dto = service.findByPK(2l);
        dto.setFirstName("Alok");
        dto.setLastName("Mishra");
        service.update(dto);
 
        UserDTO updatedDTO = service.findByPK(1l);
 
        assertNotSame("Error : Test Update Fail", dto, updatedDTO);
 
        System.out.println("Suucess : Test Update Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#delete(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testDelete() throws Exception {
        UserDTO dto = new UserDTO();
        dto.setId(2l);
 
        service.delete(dto);
 
        dto = service.findByPK(dto.getId());
        assertNull("Error : Test Delete Fail", dto);
 
        System.out.println("Suucess : Test Delete Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#findByLogin(java.lang.String)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testFindByLogin() throws Exception {
        UserDTO dto = service.findByLogin("rahul.sahu@sunrays.co.in");
 
        assertNotNull("Error : Test Get By Id Fail", dto);
 
        System.out.println(dto.getFirstName());
        System.out.println(dto.getLastName());
        System.out.println(dto.getLastLogin());
        System.out.println(dto.getRoleId());
        System.out.println(dto.getGender());
        System.out.println(dto.getPassword());
        System.out.println(dto.getCreatedBy());
        System.out.println(dto.getRegisteredIP());
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#findByPK(long)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testFindByPK() throws Exception {
        UserDTO dto = service.findByPK(1l);
 
        assertNotNull("Error : Test Get By Id Fail", dto);
 
        System.out.println(dto.getFirstName());
        System.out.println(dto.getLastName());
        System.out.println(dto.getLastLogin());
        System.out.println(dto.getRoleId());
        System.out.println(dto.getGender());
        System.out.println(dto.getPassword());
        System.out.println(dto.getCreatedBy());
        System.out.println(dto.getRegisteredIP());
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#search(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testSearchUserDTO() throws Exception {
        UserDTO dto = new UserDTO();
        dto.setFirstName("R");
 
        List userList = service.search(dto);
        assertTrue("Error : Test Search Fail", userList.size() > 0);
 
        Iterator it = userList.iterator();
        while (it.hasNext()) {
            dto = (UserDTO) it.next();
            System.out.println(dto.getFirstName());
            System.out.println(dto.getLastName());
        }
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#search(in.co.sunrays.proj1.dto.UserDTO,int,int)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testSearchUserDTOIntInt() throws Exception {
        UserDTO dto = new UserDTO();
        dto.setFirstName("R");
 
        List userList = service.search(dto, 1, 5);
        assertTrue("Error : Test Search Fail", userList.size() > 0);
 
        Iterator it = userList.iterator();
        while (it.hasNext()) {
            dto = (UserDTO) it.next();
            System.out.println(dto.getFirstName());
            System.out.println(dto.getLastName());
        }
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#list()} .
     * 
     * @throws Exception
     */
    @Ignore
    public void testList() throws Exception {
        List userList = service.list();
        assertTrue("Error : Test Search Fail", userList.size() > 0);
 
        Iterator it = userList.iterator();
        while (it.hasNext()) {
            UserDTO dto = (UserDTO) it.next();
            System.out.println(dto.getFirstName());
            System.out.println(dto.getLastName());
        }
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#list(int ,int)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testListIntInt() throws Exception {
        List userList = service.list(1, 5);
        assertTrue("Error : Test Search Fail", userList.size() > 0);
 
        Iterator it = userList.iterator();
        while (it.hasNext()) {
            UserDTO dto = (UserDTO) it.next();
            System.out.println(dto.getFirstName());
            System.out.println(dto.getLastName());
        }
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#authenticate(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testAuthenticate() throws Exception {
        UserDTO dto = new UserDTO();
        dto.setLogin("rahul.sahu@sunrays.co.in");
        dto.setPassword("pass1234");
        dto.setLastLoginIP("192.168.1.16");
 
        UserDTO dtoExist = service.authenticate(dto);
 
        assertNotNull("Error : Test Authenticate Fail", dto);
 
        System.out.println(dtoExist.getFirstName());
        System.out.println(dtoExist.getLastName());
        System.out.println(dtoExist.getLastLogin());
        System.out.println(dtoExist.getRoleId());
        System.out.println(dtoExist.getGender());
        System.out.println(dtoExist.getPassword());
        System.out.println(dtoExist.getCreatedBy());
        System.out.println(dtoExist.getRegisteredIP());
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#changePassword(int,java.lang.String,java.lang.String)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testChangePassword() throws Exception {
        boolean b = service.changePassword(1l, "pass1234", "pass5678");
 
        assertTrue("Error : Test Change Password Fail", b);
 
        System.out.println("Suucess : Test Change Password Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#forgetPassword(java.lang.String)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testForgetPassword() throws Exception {
        boolean b = service.forgetPassword("rahul.sahu@sunrays.co.in");
 
        assertTrue("Error : Test Forget Password Fail", b);
 
        System.out.println("Suucess : Test Forget Password Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#lock(java.lang.String)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testLock() throws Exception {
        boolean b = service.lock("rahul.sahu@sunrays.co.in");
 
        assertTrue("Error : Test Lock Fail", b);
 
        System.out.println("Suucess : Test Lock Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#resetPassword(java.lang.String)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testResetPassword() throws Exception {
        boolean b = service.resetPassword("rahul.sahu@sunrays.co.in");
 
        assertTrue("Error : Test Lock Fail", b);
 
        System.out.println("Suucess : Test Reset Password Success");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#getRoles(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testGetRoles() throws Exception {
        fail("Not yet implemented");
    }
 
    /**
     * Test method for
     * {@link in.co.sunrays.proj1.service.UserServiceSpringImpl#updateAccess(in.co.sunrays.proj1.dto.UserDTO)}
     * .
     * 
     * @throws Exception
     */
    @Ignore
    public void testUpdateAccess() throws Exception {
        fail("Not yet implemented");
    }
 
}
Comments