Package org.jrest4guice.sample.struts2.model

Examples of org.jrest4guice.sample.struts2.model.Employee


    private IDao<Redis> redisDao = new RedisDaoImpl(storage);

    @Test
    public void employeeDaoTest() {
        //Create 2 employees
        Employee employee1 = new Employee(350);
        Employee employee2 = new Employee(700);
        //Save employees in database
        employee1 = employeeDao.save(employee1);
        employee2 = employeeDao.save(employee2);
        //Get it from database
        Employee get1 = employeeDao.get(employee1.getId());
        Employee get2 = employeeDao.get(employee2.getId());
        //Assert employees
        Assert.assertEquals(employee1, get1);
        Assert.assertEquals(employee2, get2);
        //Change salary of employee1
        employee1.setSalary(1000);
        employeeDao.update(employee1);
        //Check update state
        Employee updated = employeeDao.get(employee1.getId());
        Assert.assertEquals(1000, updated.getSalary());
        //Delete changed employee
        boolean success = employeeDao.delete(updated);
        Assert.assertTrue(success);
        Employee mustBeDeleted = employeeDao.get(updated.getId());
        Assert.assertNull(mustBeDeleted);
    }
View Full Code Here


        EntityStorage.getEntities().put(5L, createEmployee(5L, 5));
    }

    @Test
    public void saveBasicTest() throws UserAlreadyExist {
        Employee emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(6), emp.getId());

        emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(7), emp.getId());

        emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(8), emp.getId());
    }
View Full Code Here

        Assert.assertEquals(new Long(8), emp.getId());
    }

    @Test
    public void saveComplicatedTest() throws UserAlreadyExist {
        Employee emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(6), emp.getId());

        EntityStorage.getEntities().remove(1L);

        emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(7), emp.getId());

        EntityStorage.getEntities().remove(2L);
        EntityStorage.getEntities().remove(3L);

        emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(8), emp.getId());

        EntityStorage.getEntities().remove(7L);
        EntityStorage.getEntities().remove(8L);

        emp = createEmployee(null, 1);
        emp = dao.save(emp);
        Assert.assertEquals(new Long(7), emp.getId());
    }
View Full Code Here

        Assert.assertEquals(new Long(7), emp.getId());
    }

    @Test(expected = UserAlreadyExist.class)
    public void saveAlreadyExistsTest() throws UserAlreadyExist {
        Employee emp = createEmployee(1L, 1);
        dao.save(emp);
    }
View Full Code Here

        dao.save(emp);
    }

    @Test(expected = UserAlreadyExist.class)
    public void saveAlreadyExists2Test() throws UserAlreadyExist {
        Employee emp = createEmployee(5L, 1);
        dao.save(emp);
    }
View Full Code Here

        dao.save(emp);
    }

    @Test
    public void updateOkTest() throws UserNotFound {
        Employee emp = createEmployee(1L, 10);
        emp = dao.update(emp);
        Assert.assertEquals(new Long(1), emp.getId());
        Assert.assertEquals(10, emp.getSalary());
        emp = (Employee) EntityStorage.getEntities().get(1L);
        Assert.assertEquals(new Long(1), emp.getId());
        Assert.assertEquals(10, emp.getSalary());
    }
View Full Code Here

        Assert.assertEquals(10, emp.getSalary());
    }

    @Test(expected = UserNotFound.class)
    public void updateFail1Test() throws UserNotFound {
        Employee emp = createEmployee(null, 10);
        emp = dao.update(emp);
    }
View Full Code Here

        emp = dao.update(emp);
    }

    @Test(expected = UserNotFound.class)
    public void updateFail2Test() throws UserNotFound {
        Employee emp = createEmployee(6L, 10);
        emp = dao.update(emp);
    }
View Full Code Here

        emp = dao.update(emp);
    }

    @Test
    public void getTest() {
        Employee emp = dao.get(3);
        Assert.assertEquals(new Long(3), emp.getId());
        Assert.assertEquals(3, emp.getSalary());

        emp = dao.get(10);
        Assert.assertNull(emp);
    }
View Full Code Here

        Assert.assertFalse(dao.delete(1L));
        Assert.assertFalse(dao.delete(2L));
    }

    private static Employee createEmployee(Long id, int weight) {
        Employee emp = new Employee();
        emp.setId(id);
        emp.setSalary(weight);
        return emp;
    }
View Full Code Here

TOP

Related Classes of org.jrest4guice.sample.struts2.model.Employee

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.