How can I write the j unit test cases for the method within the method? please, help me out to resolve this issue. Here "CreatePreparedStatement" is the method within the create device history method .
@Override
@Transactional
public DeviceHistory createDeviceHistory(DeviceHistory dh) {
Timestamp currentTime = CommonRoutines.getUTCTimestamp();
dh.setCreatedAt(currentTime);
dh.setUpdatedAt(currentTime);
dh.setActive(1);
GeneratedKeyHolder holder = new GeneratedKeyHolder();
int rowCount = provJDBCTemplateRepository.executeUpdate(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement statement = con.prepareStatement(DeviceQueries.INSERT_INTO_DMS_DEVICE_HISTORIES,
new String[] { "LOG_ID" });
statement.setString(1, dh.getTransactionId());
statement.setObject(2, dh.getDeviceGroupId());
statement.setString(3, dh.getEventType());
statement.setString(4, dh.getMessageCode());
statement.setString(5, dh.getMessageTextEnUS());
statement.setObject(6, dh.getSmartAccountId());
statement.setObject(7, dh.getVirtualAccountId());
statement.setString(8, dh.getTenantId());
statement.setObject(9, dh.getDeviceDetailId());
statement.setString(10, dh.getSeverity());
statement.setObject(11, dh.getHasAPICEMLog());
statement.setObject(12, dh.getParentLogId());
statement.setObject(13, dh.getActive());
statement.setString(14, dh.getCreatedBy());
statement.setTimestamp(15, dh.getCreatedAt());
statement.setString(16, dh.getUpdatedBy());
statement.setTimestamp(17, dh.getUpdatedAt());
return statement;
}
}, holder);
LOGGER.debug("Rows Updated createDeviceAlerts- ", rowCount);
dh.setLogId(Long.valueOf(holder.getKey().toString()));
return dh;
}