Authored by fangyeqing

ADD

package com.xkl;
import org.json.JSONObject;
import org.junit.Test;
import java.util.HashMap;
... ... @@ -11,9 +12,13 @@ import java.util.Map;
public class OpenIdTest {
private static final String URL_OPEN_ID = Constants.URL_PREFIX + "/openId";
private static final String URL_LOGIN = Constants.URL_PREFIX + "/openId/login";
private static final String URL_COMPARE = Constants.URL_PREFIX + "/report/compare";
@Test
public void testBind(){
bindWithOpenIdAndUser();
}
public static String bindWithOpenIdAndUser(){
Map<String,String> params = new HashMap<String, String>();
params.put("username","user1");
params.put("password",EncodeTools.encode("MD5","pass1"));
... ... @@ -24,7 +29,7 @@ public class OpenIdTest {
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_OPEN_ID,"POST",params);
System.out.println(response);
return response;
}
@Test
... ... @@ -44,14 +49,36 @@ public class OpenIdTest {
@Test
public void testLogin(){
System.out.println(bindWithOpenIdAndLoginAndGetToken("abcdefghijklmnopqrstuvwxyz123456","0"));
}
public static String bindWithOpenIdAndLoginAndGetToken(String openId, String openIdType){
bindWithOpenIdAndUser();
Map<String,String> params = new HashMap<String, String>();
params.put("openId","abcdefghijklmnopqrstuvwxyz123456");
params.put("openIdType","0");
params.put("openId",openId);
params.put("openIdType",openIdType);
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_LOGIN,"POST",params);
System.out.println("response:"+ response);
JSONObject jsonObject = new JSONObject(response);
JSONObject content = jsonObject.getJSONObject("content");
return content.getString("userId") + "_" + content.getString("token");
}
@Test
public void testCompare(){
String token = bindWithOpenIdAndLoginAndGetToken("abcdefghijklmnopqrstuvwxyz123456","0");
Map<String,String> params = new HashMap<String, String>();
params.put("report_id","1");
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMapWithToken(URL_COMPARE,"POST",params,token);
System.out.println(response);
}
}
... ...
... ... @@ -15,6 +15,7 @@ import static com.xkl.TokenTest.loginAndGetToken;
public class ReportTest {
private static final String URL_REPORT_LIST = Constants.URL_PREFIX + "/report/list";
private static final String URL_REPORT_DETAIL = Constants.URL_PREFIX + "/report/detail";
private static final String URL_REPORT_SCORE = Constants.URL_PREFIX + "/report/score";
private static final String URL_ITEM_INFO = Constants.URL_PREFIX + "/report/itemInfo";
private static final String URL_ITEM_GRAPH = Constants.URL_PREFIX + "/report/itemGraph";
private static String token;
... ... @@ -46,10 +47,35 @@ public class ReportTest {
}
@Test
public void testScore(){
Map<String,String> params = new HashMap<String, String>();
params.put("report_id","1");
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_REPORT_SCORE,"GET",params);
System.out.println(response);
}
@Test
public void testItemInfo(){
Map<String,String> params = new HashMap<String, String>();
params.put("itemId","10");
params.put("status","0");
params.put("isPureHtml","false");
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMapWithToken(URL_ITEM_INFO,"GET",params,token);
System.out.println(response);
}
@Test
public void testItemInfoPureHtml(){
Map<String,String> params = new HashMap<String, String>();
params.put("itemId","10");
params.put("status","1");
params.put("isPureHtml","true");
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
... ...