forked from xiaowei1118/java_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsellerTest.java
More file actions
158 lines (139 loc) · 4.59 KB
/
sellerTest.java
File metadata and controls
158 lines (139 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.changyu.test;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.changyu.foryou.model.Sellers;
import com.changyu.foryou.service.SellerService;
import com.changyu.foryou.tools.Constants;
import com.changyu.foryou.tools.Md5;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring.xml", "classpath:spring-mybatis.xml" })
public class sellerTest {
private static final Logger LOGGER = Logger
.getLogger(sellerTest.class);
private SellerService sellerService;
public SellerService getSellerService() {
return sellerService;
}
@Autowired
public void setSellerService(SellerService sellerService) {
this.sellerService = sellerService;
}
/**
* 商家登录
* @param campusAdmin
* @param password
* */
@Test
public void toLogin() {
// case1
// String campusAdmin="18860902711";
// String password="123456";
// case2
// String campusAdmin="18860902711";
// String password="1236";
// case3
String campusAdmin="18860902722";
String password="123456";
Map<String, Object> map = new HashMap<String, Object>();
if (campusAdmin != null && password != null
&& !campusAdmin.trim().equals("")
&& !password.trim().equals("")) {
Sellers sellers = sellerService.selectByCampusAdmin(campusAdmin);
if (sellers != null) {
//if (sellers.getPassword().equals(Md5.GetMD5Code(password))) {
if (sellers.getPassword().equals(password)) {
map.put(Constants.STATUS, Constants.SUCCESS);
map.put(Constants.MESSAGE, "登陆成功");
map.put("type", sellers.getType());
Date date = new Date();
sellerService.updateLastLoginTime(date, campusAdmin);
} else {
map.put(Constants.STATUS, Constants.FAILURE);
map.put(Constants.MESSAGE, "账号或密码错误,请检查后输入");
}
} else {
map.put(Constants.STATUS, Constants.FAILURE);
map.put(Constants.MESSAGE, "账号或密码错误,请检查后输入");
}
}
LOGGER.debug("+++++++++++==================="+JSON.toJSONString(map)+"_____________________________________________________");
return ;
}
/**
* 根据商家id查找商家数据
* */
@Test
public void getSellerById()
{
// String campusAdmin="18860902711";
// case2
String campusAdmin="18860902712";
Map<String, Object> map = new HashMap<String, Object>();
Sellers sellers = sellerService.selectByCampusAdmin(campusAdmin);
map.put("seller",sellers);
LOGGER.debug("+++++++++++==================="+JSON.toJSONString(map)+"_____________________________________________________");
return ;
}
/**
* 商家注册
* @param campusAdmin
* @param password
* @param campusId
* @return
*/
@Test
public void registerIn()
{
// case1.2
// String campusAdmin="18860902573";
// String password="123456";
// Integer campusId=1;
// case3
// String campusAdmin="18860902574";
// String password=" ";
// Integer campusId=1;
// case4
String campusAdmin=" ";
String password="123456";
Integer campusId=1;
Map<String, Object> map = new HashMap<String, Object>();
try {
if (!campusAdmin.equals("") && !password.equals(""))
{
String passwordMd5 = Md5.GetMD5Code(password);
Sellers seller = new Sellers();
seller.setCampusAdmin(campusAdmin);
seller.setPassword(passwordMd5);
seller.setCampusId(campusId);
sellerService.addASeller(seller);
map.put(Constants.STATUS, Constants.SUCCESS);
map.put(Constants.MESSAGE, "注册成功");
}
else
{
map.put(Constants.STATUS, Constants.FAILURE);
map.put(Constants.MESSAGE, "注册失败2");
}
}
catch (Exception e) {
e.printStackTrace();
map.put(Constants.STATUS, Constants.FAILURE);
map.put(Constants.MESSAGE, "注册失败");
}
LOGGER.debug("+++++++++++==================="+JSON.toJSONString(map)+"_____________________________________________________");
return ;
}
}