ReportTest.java
1.85 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
package com.xkl.uspih;
import com.xkl.Constants;
import com.xkl.EncodeTools;
import com.xkl.HttpTools;
import org.json.JSONObject;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* 报告上传与删除接口测试。
* zhaoyue
* 2017-1-14
*/
public class ReportTest {
private static final String URL_REPORT = Constants.URL_PREFIX + "/uspih/report";
private static final String URL_LOGIN = Constants.URL_PREFIX + "/uspih/account";
public static String loginAndGetToken(String user, String pass) {
Map<String, String> params = new HashMap<String, String>();
params.put("account", user);
params.put("password", EncodeTools.encode("MD5", pass));
params.put("t", HttpTools.getNow());
String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
System.out.println("login success:" + response);
JSONObject jsonObject = new JSONObject(response);
JSONObject content = jsonObject.getJSONObject("content");
return content.getString("userId") + "_" + content.getString("token");
}
@Test
public void testAddReport() {
String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
Map<String, String> params = new HashMap<String, String>();
params.put("json_report", Data.AMP_REPORT);
String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token);
System.out.println("add report success:" + response);
}
@Test
public void testDelReport() {
String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
Map<String, String> params = new HashMap<String, String>();
params.put("report_id", "85");
String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token);
System.out.println("delete report:" + response);
}
}