package org.abin.lee.file;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class QueryCustomerManagerTestCase extends TestCase {
private static final String jsonServerUrl = "http://10.10.10.10:1010/portal/mobile/";
static DefaultHttpClient client = new DefaultHttpClient();
public static String sendReq(String method, String jsonReq)
throws ClientProtocolException, IOException {
HttpPost post = new HttpPost(jsonServerUrl + method);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("json", jsonReq));
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
String entityStr = EntityUtils.toString(entity);
return entityStr;
}
/**
* 查询产品客户经理接口
*/
public void testQueryCustomerManager() throws ClientProtocolException,
IOException {
String jsonReq = "{" + "RequestID:'11111',"+ "ProductID:'SC9904348'," + "timestamp:'20120416121200',"
+ "Hashcode:'1324546asdfgfhr65432wsdfgt654eds'" + "}";
String resStr = this.sendReq("query-customer-manager-json!queryCustomerManager.action", jsonReq);
System.out.println(resStr);
assertNotNull(resStr);
// JSONObject json = JSONObject.fromObject(resStr);
// assertNotNull(json.get("requestID"));
}
}