Junit小例(2)
程序员文章站
2022-04-29 19:00:00
...
(1) 针对一个dao中insert方法写用例:
public void insertLoginLogInfo(Map<?, ?> loginLogInfo)
throws ApplicationException
{
try
{
mDaoManager.insert("insertLoginInfo", loginLogInfo);
}
catch (DataAccessException e)
{
e.printStackTrace();
throw new ApplicationException(
"--insertLoginInfo---向SUP_USER_LOGIN_LOG表中插入数据出错", e);
}
}
@Test
public void testInsertLoginLogInfo() throws ApplicationException {
Map<String, Object> map = new HashMap<String,Object>();
map.put("USERID", "p002341276");
map.put("LOGIN_IP", "10.10.25.211");
map.put("ACCOUNT_TYPE", "superm_45");
ILoginLogDTO ap2uDTO = new LoginLogDTO(map);
poApplyDao.insertLoginLogInfo(ap2uDTO);
Map<String, Object> result = jdbcTemplate.queryForMap(
"select USERID,LOGIN_IP,ACCOUNT_TYPE,(to_char(LOGINTIME,'YYYY-MM-DD')) LOGINTIME from SUP_USER_LOGIN_LOG where USERID = 'p002341276'");
Assert.assertNotNull(result);
Assert.assertEquals(ap2uDTO.getUserID(), result.get("USERID"));
Assert.assertEquals(ap2uDTO.getLogin_IP(), result.get("LOGIN_IP"));
Assert.assertEquals(ap2uDTO.getAccount_Type(), result.get("ACCOUNT_TYPE"));
}
(2)针对dao中delete中写用例
@Transactional
public int deleteSoftUpdateInfoByID(String aGuid)
{
return daoManager.delete("deleteSoftUpdateInfoByID", aGuid);
}
@Test
public void testDeleteSoftUpdateInfoByID()
{
ISoftUpdateInfo info = new SoftUpdateInfoMap();
String guid = UUID.randomUUID().toString().toUpperCase();
info.setGuid(guid);
info.setValid(true);
info.setSoftName("testName");
info.setSeedStream("testSeedStream");
service.insertSoftUpdateInfo(info);
int rows = service.deleteSoftUpdateInfoByID(guid);
assertEquals(1, rows);
}
[code="java"][/code]
上一篇: 关于页面502的一次排查,页面502排查
下一篇: php导入模块文件分享