Package com.luxoft.dnepr.courses.regular.unit17.model

Examples of com.luxoft.dnepr.courses.regular.unit17.model.Redis


        if (id == null) {
            id = EntityStorageUtils.getNextToMaxId(storage, clazz);
            e.setId(id);
        }
        if (get(id) != null) {
            throw new UserAlreadyExist(id);
        }
        return (E) storage.save(e);
    }
View Full Code Here


        if (e == null) {
            throw new IllegalArgumentException("Argument 'e' can't be a null reference!");
        }
        Integer id = e.getId();
        if (id == null) {
            throw new UserNotFound(id);
        }
        if (get(id) == null) {
            throw new UserNotFound(id);
        }
        return (E) storage.update(e);
    }
View Full Code Here

    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

    }

    @Test
    public void redisDaoTest() {
        //Create 2 redis
        Redis redis1 = new Redis(35);
        Redis redis2 = new Redis(70);
        //Save redis in database
        redis1 = redisDao.save(redis1);
        redis2 = redisDao.save(redis2);
        //Get it from database
        Redis get1 = redisDao.get(redis1.getId());
        Redis get2 = redisDao.get(redis2.getId());
        //Assert redis
        Assert.assertEquals(redis1, get1);
        Assert.assertEquals(redis2, get2);
        //Change salary of employee1
        redis1.setWeight(100);
        redisDao.update(redis1);
        //Check update state
        Redis updated = redisDao.get(redis1.getId());
        Assert.assertEquals(100, updated.getWeight());
    }
View Full Code Here

    }

    @Test
    public void testSave() {

        Redis redis1 = new Redis(50);
        Redis redis2 = new Redis(100);
        Redis redis4 = new Redis(200);
        Redis redis5 = null;
        redis4.setId(4L);
        try {
            redis1 = RedisDAO.save(redis1);
            redis2 = RedisDAO.save(redis2);
            redis4 = RedisDAO.save(redis4);
            redis5 = RedisDAO.save(redis5);
        } catch (UserAlreadyExist e) {
            fail();
        }

        assertEquals(50, redis1.getWeight());
        assertEquals(100, redis2.getWeight());
        assertEquals(200, redis4.getWeight());
        assertEquals(new Long(1), redis1.getId());
        assertEquals(new Long(2), redis2.getId());
        assertEquals(new Long(4), redis4.getId());

        Redis redis11 = RedisDAO.get(1L);
        Redis redis12 = RedisDAO.get(2L);
        Redis redis14 = RedisDAO.get(4L);
        assertEquals(50, redis11.getWeight());
        assertEquals(100, redis12.getWeight());
        assertEquals(200, redis14.getWeight());
        assertEquals(new Long(1), redis11.getId());
        assertEquals(new Long(2), redis12.getId());
        assertEquals(new Long(4), redis14.getId());
        assertTrue(redis5 == null);

        Redis redis3 = new Redis(75);
        redis3.setId(2L);

        try {
            RedisDAO.save(redis3);
            fail();
        } catch (UserAlreadyExist e) {
View Full Code Here

    }

    @Test
    public void testUpdate() {

        Redis redis1 = new Redis(50);
        Redis redis2 = new Redis(100);
        redis2.setId(1L);
        RedisDAO.save(redis1);
        Redis redis3 = RedisDAO.update(redis2);

        assertEquals(new Long(1), redis3.getId());
        assertEquals(100, redis3.getWeight());

        Redis redis4 = new Redis(200);
        try {
            RedisDAO.update(redis4);
            fail();
        } catch (UserNotFound e) {
            assertEquals("null not found!", e.getMessage());
        }

        Redis redis5 = new Redis(201);
        redis5.setId(5L);
        try {
            RedisDAO.update(redis5);
            fail();
        } catch (UserNotFound e) {
            assertEquals("5 not found!", e.getMessage());
View Full Code Here

        RedisDAO.delete(1L);
    }

    @Test
    public void testGet() {
        Redis redis1 = new Redis(50);
        Redis redis2 = new Redis(100);
        RedisDAO.save(redis1);
        RedisDAO.save(redis2);

        Redis redis3 = RedisDAO.get(0);
        assertTrue(redis3 == null);

        Redis redis4 = RedisDAO.get(1);
        assertEquals(new Long(1), redis4.getId());
        assertEquals(50, redis4.getWeight());

        Redis redis5 = RedisDAO.get(2);
        assertEquals(new Long(2), redis5.getId());
        assertEquals(100, redis5.getWeight());

        Redis redis6 = RedisDAO.get(3);
        assertTrue(redis6 == null);

        RedisDAO.delete(1);
        RedisDAO.delete(2);
    }
View Full Code Here

        RedisDAO.delete(2);
    }

    @Test
    public void testRemove() {
        Redis redis1 = new Redis(50);
        RedisDAO.save(redis1);

        assertFalse(RedisDAO.delete(0));
        assertTrue(RedisDAO.delete(1));
        assertFalse(RedisDAO.delete(2));
View Full Code Here

TOP

Related Classes of com.luxoft.dnepr.courses.regular.unit17.model.Redis

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.