Package net.usefulbits.model

Examples of net.usefulbits.model.Person


    @Test
    public void testSave() {
        createAndSavePerson("David", 28);
        assertEquals(1, countRowsInTable("person"));

        Person david = getSinglePerson();
        assertEquals("Name not saved correctly", "David", david.getName());
        assertEquals("Age not saved correctly", 28, david.getAge());
    }
View Full Code Here


    }

    @Test
    public void testGetById() {
        createAndSavePerson("David", 28);
        Person david = fPersonDao.getById(0);
        assertEquals(david.getName(), "David");
        assertEquals(david.getAge(), 28);
    }
View Full Code Here

    }

    @Test
    public void testDelete() {
        createAndSavePerson("David", 28);
        Person david = fPersonDao.getById(0);
        fPersonDao.delete(david);
        fPersonDao.getEntityManager().flush();
        assertEquals("Deleting person failed.", 0, countRowsInTable("person"));
    }
View Full Code Here

    }

    @Test
    public void testUpdate() {
        createAndSavePerson("David", 28);
        Person person = fPersonDao.getById(0);
        assertEquals("The Person didn't get saved.", 1, countRowsInTable("person"));

        person.setName("Jane");
        person.setAge(21);
        fPersonDao.update(person);
        fPersonDao.getEntityManager().flush();

        Person jane = getSinglePerson();
        assertEquals(1, countRowsInTable("person"));
        assertEquals("The name didn't get changed", "Jane", jane.getName());
        assertEquals("The Age didn't get changed", 21, jane.getAge());
    }
View Full Code Here

        return jdbcTemplate.queryForObject(
                "select * from person where id = ?", new PersonRowMapper(), 0);
    }

    private void createAndSavePerson(String name, int age) {
        Person person = new Person();
        person.setName(name);
        person.setAge(age);

        fPersonDao.save(person);

        // Must flush the person to the database before trying to find it
        fPersonDao.getEntityManager().flush();
View Full Code Here

        fPersonDao.getEntityManager().flush();
    }

    private static class PersonRowMapper implements ParameterizedRowMapper<Person> {
        public Person mapRow(ResultSet rs, int rowNum) throws SQLException {
            Person result = new Person();
            result.setName(rs.getString("name"));
            result.setAge(rs.getInt("age"));
            return result;
        }
View Full Code Here

TOP

Related Classes of net.usefulbits.model.Person

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.