Authored by fangyeqing

ADD

1 package com.xkl; 1 package com.xkl;
2 2
  3 +import org.json.JSONObject;
3 import org.junit.Test; 4 import org.junit.Test;
4 5
5 import java.util.HashMap; 6 import java.util.HashMap;
@@ -11,9 +12,13 @@ import java.util.Map; @@ -11,9 +12,13 @@ import java.util.Map;
11 public class OpenIdTest { 12 public class OpenIdTest {
12 private static final String URL_OPEN_ID = Constants.URL_PREFIX + "/openId"; 13 private static final String URL_OPEN_ID = Constants.URL_PREFIX + "/openId";
13 private static final String URL_LOGIN = Constants.URL_PREFIX + "/openId/login"; 14 private static final String URL_LOGIN = Constants.URL_PREFIX + "/openId/login";
14 - 15 + private static final String URL_COMPARE = Constants.URL_PREFIX + "/report/compare";
15 @Test 16 @Test
16 public void testBind(){ 17 public void testBind(){
  18 + bindWithOpenIdAndUser();
  19 + }
  20 +
  21 + public static String bindWithOpenIdAndUser(){
17 Map<String,String> params = new HashMap<String, String>(); 22 Map<String,String> params = new HashMap<String, String>();
18 params.put("username","user1"); 23 params.put("username","user1");
19 params.put("password",EncodeTools.encode("MD5","pass1")); 24 params.put("password",EncodeTools.encode("MD5","pass1"));
@@ -24,7 +29,7 @@ public class OpenIdTest { @@ -24,7 +29,7 @@ public class OpenIdTest {
24 params.put("type","1"); 29 params.put("type","1");
25 params.put("sign",HttpTools.getSign(params)); 30 params.put("sign",HttpTools.getSign(params));
26 String response = HttpTools.requestByMap(URL_OPEN_ID,"POST",params); 31 String response = HttpTools.requestByMap(URL_OPEN_ID,"POST",params);
27 - System.out.println(response); 32 + return response;
28 } 33 }
29 34
30 @Test 35 @Test
@@ -44,14 +49,36 @@ public class OpenIdTest { @@ -44,14 +49,36 @@ public class OpenIdTest {
44 49
45 @Test 50 @Test
46 public void testLogin(){ 51 public void testLogin(){
  52 + System.out.println(bindWithOpenIdAndLoginAndGetToken("abcdefghijklmnopqrstuvwxyz123456","0"));
  53 + }
  54 +
  55 + public static String bindWithOpenIdAndLoginAndGetToken(String openId, String openIdType){
  56 + bindWithOpenIdAndUser();
47 Map<String,String> params = new HashMap<String, String>(); 57 Map<String,String> params = new HashMap<String, String>();
48 - params.put("openId","abcdefghijklmnopqrstuvwxyz123456");  
49 - params.put("openIdType","0"); 58 + params.put("openId",openId);
  59 + params.put("openIdType",openIdType);
50 60
51 params.put("t",HttpTools.getNow()); 61 params.put("t",HttpTools.getNow());
52 params.put("type","1"); 62 params.put("type","1");
53 params.put("sign",HttpTools.getSign(params)); 63 params.put("sign",HttpTools.getSign(params));
54 String response = HttpTools.requestByMap(URL_LOGIN,"POST",params); 64 String response = HttpTools.requestByMap(URL_LOGIN,"POST",params);
  65 +
  66 + System.out.println("response:"+ response);
  67 + JSONObject jsonObject = new JSONObject(response);
  68 + JSONObject content = jsonObject.getJSONObject("content");
  69 + return content.getString("userId") + "_" + content.getString("token");
  70 + }
  71 +
  72 + @Test
  73 + public void testCompare(){
  74 + String token = bindWithOpenIdAndLoginAndGetToken("abcdefghijklmnopqrstuvwxyz123456","0");
  75 + Map<String,String> params = new HashMap<String, String>();
  76 + params.put("report_id","1");
  77 +
  78 + params.put("t",HttpTools.getNow());
  79 + params.put("type","1");
  80 + params.put("sign",HttpTools.getSign(params));
  81 + String response = HttpTools.requestByMapWithToken(URL_COMPARE,"POST",params,token);
55 System.out.println(response); 82 System.out.println(response);
56 } 83 }
57 } 84 }
@@ -15,6 +15,7 @@ import static com.xkl.TokenTest.loginAndGetToken; @@ -15,6 +15,7 @@ import static com.xkl.TokenTest.loginAndGetToken;
15 public class ReportTest { 15 public class ReportTest {
16 private static final String URL_REPORT_LIST = Constants.URL_PREFIX + "/report/list"; 16 private static final String URL_REPORT_LIST = Constants.URL_PREFIX + "/report/list";
17 private static final String URL_REPORT_DETAIL = Constants.URL_PREFIX + "/report/detail"; 17 private static final String URL_REPORT_DETAIL = Constants.URL_PREFIX + "/report/detail";
  18 + private static final String URL_REPORT_SCORE = Constants.URL_PREFIX + "/report/score";
18 private static final String URL_ITEM_INFO = Constants.URL_PREFIX + "/report/itemInfo"; 19 private static final String URL_ITEM_INFO = Constants.URL_PREFIX + "/report/itemInfo";
19 private static final String URL_ITEM_GRAPH = Constants.URL_PREFIX + "/report/itemGraph"; 20 private static final String URL_ITEM_GRAPH = Constants.URL_PREFIX + "/report/itemGraph";
20 private static String token; 21 private static String token;
@@ -46,10 +47,35 @@ public class ReportTest { @@ -46,10 +47,35 @@ public class ReportTest {
46 } 47 }
47 48
48 @Test 49 @Test
  50 + public void testScore(){
  51 + Map<String,String> params = new HashMap<String, String>();
  52 + params.put("report_id","1");
  53 + params.put("t",HttpTools.getNow());
  54 + params.put("type","1");
  55 + params.put("sign",HttpTools.getSign(params));
  56 + String response = HttpTools.requestByMap(URL_REPORT_SCORE,"GET",params);
  57 + System.out.println(response);
  58 + }
  59 +
  60 + @Test
49 public void testItemInfo(){ 61 public void testItemInfo(){
50 Map<String,String> params = new HashMap<String, String>(); 62 Map<String,String> params = new HashMap<String, String>();
51 params.put("itemId","10"); 63 params.put("itemId","10");
52 params.put("status","0"); 64 params.put("status","0");
  65 + params.put("isPureHtml","false");
  66 + params.put("t",HttpTools.getNow());
  67 + params.put("type","1");
  68 + params.put("sign",HttpTools.getSign(params));
  69 + String response = HttpTools.requestByMapWithToken(URL_ITEM_INFO,"GET",params,token);
  70 + System.out.println(response);
  71 + }
  72 +
  73 + @Test
  74 + public void testItemInfoPureHtml(){
  75 + Map<String,String> params = new HashMap<String, String>();
  76 + params.put("itemId","10");
  77 + params.put("status","1");
  78 + params.put("isPureHtml","true");
53 params.put("t",HttpTools.getNow()); 79 params.put("t",HttpTools.getNow());
54 params.put("type","1"); 80 params.put("type","1");
55 params.put("sign",HttpTools.getSign(params)); 81 params.put("sign",HttpTools.getSign(params));