1
2
3 import static org.junit.Assert.assertTrue;
4
5 import java.util.Date;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 import org.junit.Test;
11 import org.springframework.beans.factory.annotation.Autowired;
12
13 import com.ieasy360.sop.api.models.hq.constants.Constants;
14 import com.ieasy360.sop.api.models.hq.forms.BaseCanbieViewForm;
15 import com.ieasy360.sop.hq.api.model.BaseCanbie;
16
17 public class BaseCanbieDAOTest extends AbstractDaoTest<BaseCanbie>{
18     @Autowired
19     public BaseCanbieDAO canbieDao;
20
21     @Override
22     public void setUp() throws Exception {
23         setDao(canbieDao);
24         super.setUp();
25     }
26
27     // *****************************************************************
28         // testFindList
29         // 正常情况
30         @Test
31         public void testFindList_Valid() {
32             BaseCanbieViewForm canbieform = new BaseCanbieViewForm();
33             canbieform.setGuid("100");
34             canbieform.setGroupId("002");
35             canbieform.setOrgId("999");
36             canbieform.setCanbieNo("2");
37             canbieform.setCanbieName("wc");
38             canbieform.setStatus(1);
39             List<BaseCanbie> results = canbieDao.findList(canbieform);
40             assertTrue("查询失败",null!=results && results.size() > 0);
41             for(BaseCanbie canbie : results){
42                 assertTrue("ID不一致", "100".equals(canbie.getGuid()));
43                 assertTrue("集团ID不一致", "002".equals(canbie.getGroupId()));
44                 assertTrue("门店ID不一致", "999".equals(canbie.getOrgId()));
45                 assertTrue("统一餐别不一致", "2".equals(canbie.getCanbieNo()));
46                 assertTrue("餐别名称不一致", "wc".equals(canbie.getCanbieName()));
47                 assertTrue("状态不一致", 1==canbie.getStatus());
48                 assertTrue("删除状态不一致", !canbie.isDeleted());
49             }
50         }
51
52         // testFindList
53         // 正常情况
54         @Test
55         public void testFindNowCanbie_Valid() {
56             BaseCanbieViewForm canbieform = new BaseCanbieViewForm();
57             canbieform.setGroupId("002");
58             canbieform.setOrgId("999");
59
60             Date date=new Date();
61
62             BaseCanbie result = canbieDao.findNowCanbie(canbieform,date);
63             assertTrue("查询失败",null!=result);
64
65             assertTrue("集团ID不一致", "002".equals(result.getGroupId()));
66             assertTrue("门店ID不一致", "999".equals(result.getOrgId()));
67             assertTrue("删除状态不一致", !result.isDeleted());
68         }
69
70         // *****************************************************************
71         // testCreate
72         // 正常情况
73         @Override
74         public void testCreate() {
75             Date date=new Date();
76             BaseCanbie canbie = new BaseCanbie();
77             canbie.setCanbieNo("1");
78             canbie.setCanbieName("test");
79             canbie.setStartTime(36000);
80             canbie.setEatTime(36000);
81             canbie.setEndTime(57599);
82             canbie.setStatus(0);
83             canbie.setSystemVersion("test");
84             canbie.setCpId("test");
85             canbie.setOrgId("999");
86             canbie.setSourceId("test");
87             canbie.setFormatStartTime("10:00:00");
88             canbie.setFormatEatTime("10:00:00");
89             canbie.setFormatEndTime("15:59:59");
90             canbie.setMemo_1("test");
91             canbie.setMemo_2("test");
92             canbie.setMemo_3("test");
93             canbie.setGroupId("002");
94             canbie.setGroupIdType(Constants.GROUP_TYPE_CUSTOMER);
95             canbie.setAddGroupId("002");
96             canbie.setAddGroupIdType(Constants.GROUP_TYPE_CUSTOMER);
97             canbie.setAddUserId("ycb");
98             canbie.setAddUser("ycb");
99             canbie.setAddTime(date);
100             canbie.setModUserId("ycb");
101             canbie.setModUser("ycb");
102             canbie.setModTime(date);
103             canbie.setDeleted(true);
104
105             Map<String, Object> assertMaps = new HashMap<String, Object>();
106             assertMaps.put("canbieNo","1");
107             assertMaps.put("canbieName","test");
108             assertMaps.put("startTime",36000);
109             assertMaps.put("eatTime",36000);
110             assertMaps.put("endTime",57599);
111             assertMaps.put("status",0);
112             assertMaps.put("systemVersion","test");
113             assertMaps.put("cpId","test");
114             assertMaps.put("orgId","999");
115             assertMaps.put("sourceId","test");
116             assertMaps.put("formatStartTime","10:00:00");
117             assertMaps.put("formatEatTime","10:00:00");
118             assertMaps.put("formatEndTime","15:59:59");
119             assertMaps.put("memo_1","test");
120             assertMaps.put("memo_2","test");
121             assertMaps.put("memo_3","test");
122             assertMaps.put("groupId","002");
123             assertMaps.put("groupIdType",Constants.GROUP_TYPE_CUSTOMER);
124             assertMaps.put("addGroupId","002");
125             assertMaps.put("addGroupIdType",Constants.GROUP_TYPE_CUSTOMER);
126             assertMaps.put("addUserId","ycb");
127             assertMaps.put("addUser","ycb");
128             assertMaps.put("addTime",date);
129             assertMaps.put("modUserId","ycb");
130             assertMaps.put("modUser","ycb");
131             assertMaps.put("modTime",date);
132
133             createAndAssertValues(canbie, assertMaps);
134             assertTrue("删除状态不一致", canbie.isDeleted());
135         }
136
137
138         // *****************************************************************
139         // testUpdate
140         // 正常情况下
141         @Override
142         public void testUpdate() {
143             BaseCanbieViewForm canbieform=new BaseCanbieViewForm();
144             canbieform.setGroupId("002");
145             canbieform.setGuid("100");
146             List<BaseCanbie> canbies =canbieDao.findList(canbieform);
147             BaseCanbie canbie = canbies.get(0);
148             canbie.setCanbieNo("3");
149             canbie.setCanbieName("test");
150             canbie.setStartTime(57600);
151             canbie.setEatTime(57600);
152             canbie.setEndTime(68399);
153             canbie.setStatus(0);
154             canbie.setSystemVersion("test");
155             canbie.setCpId("test");
156             canbie.setOrgId("999");
157             canbie.setSourceId("test");
158             canbie.setFormatStartTime("16:00:00");
159             canbie.setFormatEatTime("16:00:00");
160             canbie.setFormatEndTime("18:59:59");
161             canbie.setMemo_1("test");
162             canbie.setMemo_2("test");
163             canbie.setMemo_3("test");
164             canbie.setDeleted(true);
165
166             Map<String, Object> assertMaps = new HashMap<String, Object>();
167             assertMaps.put("guid","100");
168             assertMaps.put("canbieNo","3");
169             assertMaps.put("canbieName","test");
170             assertMaps.put("startTime",57600);
171             assertMaps.put("eatTime",57600);
172             assertMaps.put("endTime",68399);
173             assertMaps.put("status",0);
174             assertMaps.put("systemVersion","test");
175             assertMaps.put("cpId","test");
176             assertMaps.put("orgId","999");
177             assertMaps.put("sourceId","test");
178             assertMaps.put("formatStartTime","16:00:00");
179             assertMaps.put("formatEatTime","16:00:00");
180             assertMaps.put("formatEndTime","18:59:59");
181             assertMaps.put("memo_1","test");
182             assertMaps.put("memo_2","test");
183             assertMaps.put("memo_3","test");
184             assertMaps.put("groupId","002");
185             updateAndAssertValues(canbie, assertMaps);
186             assertTrue("删除状态不一致", canbie.isDeleted());
187         }
188
189         // *****************************************************************
190         // testDelete
191         // 正常情况下
192         @Override
193         public void testDelete() {
194             BaseCanbieViewForm canbieform=new BaseCanbieViewForm();
195             canbieform.setGroupId("002");
196             canbieform.setGuid("200");
197             List<BaseCanbie> canbies =canbieDao.findList(canbieform);
198             BaseCanbie canbie = canbies.get(0);
199             canbie.setDeleted(true);
200
201             canbie = canbieDao.update(canbie);
202             assertTrue("集团ID不一致", "002".equals(canbie.getGroupId()));
203             assertTrue("ID不一致", "200".equals(canbie.getGuid()));
204             assertTrue("删除状态不一致", canbie.isDeleted());
205         }
206 }