Mockin MapRow and SimpleJDBC call

170 views
Skip to first unread message

Uday Shankar

unread,
Sep 15, 2020, 11:19:23 AM9/15/20
to moc...@googlegroups.com
Hi Team,

Can you please help me with a code snippet to mock below code. I am not able to mock lines shown in bold.Also my jdbc mock connection is failing.

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("AnyProcedureName")
.returningResultSet("getUser", new RowMapper<abcprofile>() {

@Override
public abcprofile mapRow(ResultSet rs, int rowNum) throws SQLException {
return new abcprofile(rs.getString("xyz"), rs.getString("strFirstName"),
rs.getString("strLastName"), rs.getString("strPhone"), rs.getString("strEmail")
));
}
}).withReturnValue();

Map<String, Object> outputMap = jdbcCall.execute(new MapSqlParameterSource().addValue("UserID", cdsid));
List<abcprofile> dbResults = null;

try {
dbResults = (List<abcprofile>) outputMap.get("getUser");
if (dbResults.isEmpty()) {
logger.debug("Calling getUser: Inside DB Call - User Not Found in DB");
return null;
}
} catch (Exception e) {
return null;
// if (Integer.parseInt(outputMap.get("RETURN_VALUE").toString()) == -1) {
// throw new ResourceNotFoundException("User not found");
// }
}
return dbResults.get(0);

Regards
udayS nakar
Reply all
Reply to author
Forward
0 new messages