Spring Boot @DataJpaTest with simple @Repository stereotype
1. DAO implementation with JdbcTemplate
public class UspNeighboursDAOImpl implements UspNeighboursDAO {
private JdbcTemplate jdbcTemplate;
final String SELECT_QUERY = "select * from usp_neighbours where usp_id = ?";
public List<Map<String, Object>> getNeighboursByUspId(int uspId) {
return jdbcTemplate.queryForList(SELECT_QUERY, uspId);
}
}
// DAO Interface
public interface UspNeighboursDAO {
List<Map<String, Object>> getNeighboursByUspId(int uspId);
}
2. Testing
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class ApplicationTests {
@Autowired
private UspNeighboursDAO uspNeighboursDAO;
@Test
public void testNeighbours1() {
List<?> resList = uspNeighboursDAO.getNeighboursByUspId(2);
assertEquals(resList.size(), 2);
}
}