一个Java Dao测试用例

 import static org.junit.Assert.assertTrue;

 import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import com.ieasy360.sop.api.models.hq.constants.Constants;
import com.ieasy360.sop.api.models.hq.forms.BaseCanbieViewForm;
import com.ieasy360.sop.hq.api.model.BaseCanbie; public class BaseCanbieDAOTest extends AbstractDaoTest<BaseCanbie>{
@Autowired
public BaseCanbieDAO canbieDao; @Override
public void setUp() throws Exception {
setDao(canbieDao);
super.setUp();
} // *****************************************************************
// testFindList
// 正常情况
@Test
public void testFindList_Valid() {
BaseCanbieViewForm canbieform = new BaseCanbieViewForm();
canbieform.setGuid("100");
canbieform.setGroupId("002");
canbieform.setOrgId("999");
canbieform.setCanbieNo("2");
canbieform.setCanbieName("wc");
canbieform.setStatus(1);
List<BaseCanbie> results = canbieDao.findList(canbieform);
assertTrue("查询失败",null!=results && results.size() > 0);
for(BaseCanbie canbie : results){
assertTrue("ID不一致", "100".equals(canbie.getGuid()));
assertTrue("集团ID不一致", "002".equals(canbie.getGroupId()));
assertTrue("门店ID不一致", "999".equals(canbie.getOrgId()));
assertTrue("统一餐别不一致", "2".equals(canbie.getCanbieNo()));
assertTrue("餐别名称不一致", "wc".equals(canbie.getCanbieName()));
assertTrue("状态不一致", 1==canbie.getStatus());
assertTrue("删除状态不一致", !canbie.isDeleted());
}
} // testFindList
// 正常情况
@Test
public void testFindNowCanbie_Valid() {
BaseCanbieViewForm canbieform = new BaseCanbieViewForm();
canbieform.setGroupId("002");
canbieform.setOrgId("999"); Date date=new Date(); BaseCanbie result = canbieDao.findNowCanbie(canbieform,date);
assertTrue("查询失败",null!=result); assertTrue("集团ID不一致", "002".equals(result.getGroupId()));
assertTrue("门店ID不一致", "999".equals(result.getOrgId()));
assertTrue("删除状态不一致", !result.isDeleted());
} // *****************************************************************
// testCreate
// 正常情况
@Override
public void testCreate() {
Date date=new Date();
BaseCanbie canbie = new BaseCanbie();
canbie.setCanbieNo("1");
canbie.setCanbieName("test");
canbie.setStartTime(36000);
canbie.setEatTime(36000);
canbie.setEndTime(57599);
canbie.setStatus(0);
canbie.setSystemVersion("test");
canbie.setCpId("test");
canbie.setOrgId("999");
canbie.setSourceId("test");
canbie.setFormatStartTime("10:00:00");
canbie.setFormatEatTime("10:00:00");
canbie.setFormatEndTime("15:59:59");
canbie.setMemo_1("test");
canbie.setMemo_2("test");
canbie.setMemo_3("test");
canbie.setGroupId("002");
canbie.setGroupIdType(Constants.GROUP_TYPE_CUSTOMER);
canbie.setAddGroupId("002");
canbie.setAddGroupIdType(Constants.GROUP_TYPE_CUSTOMER);
canbie.setAddUserId("ycb");
canbie.setAddUser("ycb");
canbie.setAddTime(date);
canbie.setModUserId("ycb");
canbie.setModUser("ycb");
canbie.setModTime(date);
canbie.setDeleted(true); Map<String, Object> assertMaps = new HashMap<String, Object>();
assertMaps.put("canbieNo","1");
assertMaps.put("canbieName","test");
assertMaps.put("startTime",36000);
assertMaps.put("eatTime",36000);
assertMaps.put("endTime",57599);
assertMaps.put("status",0);
assertMaps.put("systemVersion","test");
assertMaps.put("cpId","test");
assertMaps.put("orgId","999");
assertMaps.put("sourceId","test");
assertMaps.put("formatStartTime","10:00:00");
assertMaps.put("formatEatTime","10:00:00");
assertMaps.put("formatEndTime","15:59:59");
assertMaps.put("memo_1","test");
assertMaps.put("memo_2","test");
assertMaps.put("memo_3","test");
assertMaps.put("groupId","002");
assertMaps.put("groupIdType",Constants.GROUP_TYPE_CUSTOMER);
assertMaps.put("addGroupId","002");
assertMaps.put("addGroupIdType",Constants.GROUP_TYPE_CUSTOMER);
assertMaps.put("addUserId","ycb");
assertMaps.put("addUser","ycb");
assertMaps.put("addTime",date);
assertMaps.put("modUserId","ycb");
assertMaps.put("modUser","ycb");
assertMaps.put("modTime",date); createAndAssertValues(canbie, assertMaps);
assertTrue("删除状态不一致", canbie.isDeleted());
} // *****************************************************************
// testUpdate
// 正常情况下
@Override
public void testUpdate() {
BaseCanbieViewForm canbieform=new BaseCanbieViewForm();
canbieform.setGroupId("002");
canbieform.setGuid("100");
List<BaseCanbie> canbies =canbieDao.findList(canbieform);
BaseCanbie canbie = canbies.get(0);
canbie.setCanbieNo("3");
canbie.setCanbieName("test");
canbie.setStartTime(57600);
canbie.setEatTime(57600);
canbie.setEndTime(68399);
canbie.setStatus(0);
canbie.setSystemVersion("test");
canbie.setCpId("test");
canbie.setOrgId("999");
canbie.setSourceId("test");
canbie.setFormatStartTime("16:00:00");
canbie.setFormatEatTime("16:00:00");
canbie.setFormatEndTime("18:59:59");
canbie.setMemo_1("test");
canbie.setMemo_2("test");
canbie.setMemo_3("test");
canbie.setDeleted(true); Map<String, Object> assertMaps = new HashMap<String, Object>();
assertMaps.put("guid","100");
assertMaps.put("canbieNo","3");
assertMaps.put("canbieName","test");
assertMaps.put("startTime",57600);
assertMaps.put("eatTime",57600);
assertMaps.put("endTime",68399);
assertMaps.put("status",0);
assertMaps.put("systemVersion","test");
assertMaps.put("cpId","test");
assertMaps.put("orgId","999");
assertMaps.put("sourceId","test");
assertMaps.put("formatStartTime","16:00:00");
assertMaps.put("formatEatTime","16:00:00");
assertMaps.put("formatEndTime","18:59:59");
assertMaps.put("memo_1","test");
assertMaps.put("memo_2","test");
assertMaps.put("memo_3","test");
assertMaps.put("groupId","002");
updateAndAssertValues(canbie, assertMaps);
assertTrue("删除状态不一致", canbie.isDeleted());
} // *****************************************************************
// testDelete
// 正常情况下
@Override
public void testDelete() {
BaseCanbieViewForm canbieform=new BaseCanbieViewForm();
canbieform.setGroupId("002");
canbieform.setGuid("200");
List<BaseCanbie> canbies =canbieDao.findList(canbieform);
BaseCanbie canbie = canbies.get(0);
canbie.setDeleted(true); canbie = canbieDao.update(canbie);
assertTrue("集团ID不一致", "002".equals(canbie.getGroupId()));
assertTrue("ID不一致", "200".equals(canbie.getGuid()));
assertTrue("删除状态不一致", canbie.isDeleted());
}
}
上一篇:linux用户和组 之 用户管理


下一篇:cocos2d-x游戏开发(十五)游戏加载动画loading界面