@Test public void testMappingNullValue() throws Exception { BeanPropertyRowMapper<Person> mapper = new BeanPropertyRowMapper<>(Person.class); Mock mock = new Mock(MockType.TWO); thrown.expect(TypeMismatchException.class); mock.getJdbcTemplate() .query("select name, null as age, birth_date, balance from people", mapper); }
@Test public void testMappingWithUnpopulatedFieldsNotAccepted() throws Exception { Mock mock = new Mock(); thrown.expect(InvalidDataAccessApiUsageException.class); mock.getJdbcTemplate() .query( "select name, age, birth_date, balance from people", new BeanPropertyRowMapper<>(ExtendedPerson.class, true)); }
@Test public void testMappingWithNoUnpopulatedFieldsFound() throws Exception { Mock mock = new Mock(); List<ConcretePerson> result = mock.getJdbcTemplate() .query( "select name, age, birth_date, balance from people", new BeanPropertyRowMapper<>(ConcretePerson.class, true)); assertEquals(1, result.size()); verifyConcretePerson(result.get(0)); mock.verifyClosed(); }
@Test public void testStaticQueryWithRowMapper() throws Exception { Mock mock = new Mock(); List<Person> result = mock.getJdbcTemplate() .query( "select name, age, birth_date, balance from people", new BeanPropertyRowMapper<>(Person.class)); assertEquals(1, result.size()); verifyPerson(result.get(0)); mock.verifyClosed(); }
@Test public void testQueryWithSpaceInColumnName() throws Exception { Mock mock = new Mock(MockType.THREE); List<SpacePerson> result = mock.getJdbcTemplate() .query( "select last_name as \"Last Name\", age, birth_date, balance from people", new BeanPropertyRowMapper<>(SpacePerson.class)); assertEquals(1, result.size()); verifySpacePerson(result.get(0)); mock.verifyClosed(); }
@Test public void testMappingWithUnpopulatedFieldsNotChecked() throws Exception { Mock mock = new Mock(); List<ExtendedPerson> result = mock.getJdbcTemplate() .query( "select name, age, birth_date, balance from people", new BeanPropertyRowMapper<>(ExtendedPerson.class)); assertEquals(1, result.size()); ExtendedPerson bean = result.get(0); verifyConcretePerson(bean); mock.verifyClosed(); }