Showing
4 changed files
with
36 additions
and
3 deletions
No preview for this file type
1 | git pull | 1 | git pull |
2 | -git add --all src/* | 2 | +#git add --all src/* |
3 | git add --all lib/* | 3 | git add --all lib/* |
4 | git add push.sh | 4 | git add push.sh |
5 | git add pom.xml | 5 | git add pom.xml |
6 | -git commit -m "Add admin info test" | 6 | +git commit -m "Can read local report" |
7 | git push origin master | 7 | git push origin master |
8 | git status | 8 | git status |
9 | git pull | 9 | git pull |
@@ -4,6 +4,10 @@ package com.xkl.upsoft; | @@ -4,6 +4,10 @@ package com.xkl.upsoft; | ||
4 | import org.json.JSONObject; | 4 | import org.json.JSONObject; |
5 | import org.junit.Test; | 5 | import org.junit.Test; |
6 | 6 | ||
7 | +import java.io.BufferedReader; | ||
8 | +import java.io.File; | ||
9 | +import java.io.FileInputStream; | ||
10 | +import java.io.InputStreamReader; | ||
7 | import java.text.DecimalFormat; | 11 | import java.text.DecimalFormat; |
8 | 12 | ||
9 | /** | 13 | /** |
@@ -21,6 +25,31 @@ public class Data { | @@ -21,6 +25,31 @@ public class Data { | ||
21 | data.generateJsonFormatReport(); | 25 | data.generateJsonFormatReport(); |
22 | } | 26 | } |
23 | 27 | ||
28 | + public static String readTxtFile(String filePath) { | ||
29 | + String line = ""; | ||
30 | + try { | ||
31 | + String encoding = "UTF-8"; | ||
32 | + File file = new File(filePath); | ||
33 | + if (file.isFile() && file.exists()) { //判断文件是否存在 | ||
34 | + InputStreamReader read = new InputStreamReader( | ||
35 | + new FileInputStream(file), encoding);//考虑到编码格式 | ||
36 | + BufferedReader bufferedReader = new BufferedReader(read); | ||
37 | + String lineTxt = null; | ||
38 | + while ((lineTxt = bufferedReader.readLine()) != null && !lineTxt.equals("")) { | ||
39 | + line = lineTxt; | ||
40 | + break; | ||
41 | + } | ||
42 | + read.close(); | ||
43 | + } else { | ||
44 | + System.out.println("找不到指定的文件"); | ||
45 | + } | ||
46 | + } catch (Exception e) { | ||
47 | + System.out.println("读取文件内容出错"); | ||
48 | + e.printStackTrace(); | ||
49 | + } | ||
50 | + return line; | ||
51 | + } | ||
52 | + | ||
24 | @Test | 53 | @Test |
25 | public void generateJsonFormatReport() { | 54 | public void generateJsonFormatReport() { |
26 | JSONObject report = new JSONObject(); | 55 | JSONObject report = new JSONObject(); |
@@ -36,7 +36,11 @@ public class ReportTest { | @@ -36,7 +36,11 @@ public class ReportTest { | ||
36 | public void testAddReport() { | 36 | public void testAddReport() { |
37 | String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD); | 37 | String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD); |
38 | Map<String, String> params = new HashMap<String, String>(); | 38 | Map<String, String> params = new HashMap<String, String>(); |
39 | - params.put("json_report", Data.AMP_REPORT); | 39 | + // 程序自动生成json报告。 |
40 | +// String report =Data.AMP_REPORT; | ||
41 | + // 从本地加载json报告。 | ||
42 | + String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt"); | ||
43 | + params.put("json_report", report); | ||
40 | String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token); | 44 | String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token); |
41 | System.out.println("add report success:" + response); | 45 | System.out.println("add report success:" + response); |
42 | } | 46 | } |
-
Please register or login to post a comment