Bugfree外挂开发
作者:网络转载 发布时间:[ 2014/9/5 14:46:20 ] 推荐标签:软件测试 测试管理工具
public void addBug(int product_id, BugInfo bugInfo, int productmodule_id) {
if (sessionInfo == null) {
return;
}
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "addbug");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
params.put("product_id", Integer.toString(bugInfo.getProduct_id()));
params.put("product_name", bugInfo.getProduct_name());
params.put("productmodule_id", Integer.toString(productmodule_id));
params.put("module_name", bugInfo.getModule_name());
params.put("title", bugInfo.getTitle());
params.put("priority", Integer.toString(bugInfo.getPriority()));
params.put("severity", Integer.toString(bugInfo.getSeverity()));
params.put("assign_to_name", bugInfo.getAssign_to_name());
params.put("BugType", bugInfo.getBugType());
//params.put("created_by", "1169");
//params.put("created_by_name", "haha");
params.put("bug_status", "Active");
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_WEEK, 7); // 目前的??加7天
//System.out.println(df.format(c.getTime()));
//params.put("mail_to", "u738bu5947,u4e5du91ce");
params.put("repeat_step", bugInfo.getRepeat_step());
params.put("Creater", "金永华");
params.put("Downgrade", "u5426");
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return;
}
System.out.println("[addBug] jsonResult: " + jsonResult);
return;
}
public void updateBugStatus(int id, String bug_status) {
if (sessionInfo == null) {
return;
}
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "updatebug");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
params.put("id", Integer.toString(id));
params.put("bug_status", bug_status);
params.put("severity", "4");
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return;
}
System.out.println("[updateBugStatus] jsonResult: " + jsonResult);
}
public Map<String, String> findModules(int product_id) {
Map<String,String> moduleName2OwnerMap = new HashMap<String, String>();
if (sessionInfo == null) {
return moduleName2OwnerMap;
}
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "findmodules");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
params.put("product_id", Integer.toString(product_id));
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return moduleName2OwnerMap;
}
System.out.println("[findModules] jsonResult: " + jsonResult);
JsonParser.parseModuleList(jsonResult, moduleName2OwnerMap);
return moduleName2OwnerMap;
}
private static final String QUERY_TEMPLATE = "<?xml version="1.0" encoding="UTF-8"?>" +
"<query table="Bug" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://bugfree/query.xsd">" +
"<fields logic="OR">" +
"<field name="title" operator="LIKE" value="TITLE"/>" +
"</fields>" +
"</query>";
public String queryByTitle(int product_id, String title) {
String query = QUERY_TEMPLATE.replaceAll("TITLE", title);
if (sessionInfo == null) {
return "";
}
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "query");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
params.put("product_id", Integer.toString(product_id));
params.put("query", query);
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return "";
}
return jsonResult;
}
public boolean hasNotClosed(String jsonResult) {
if (jsonResult.equals("")) {
return false;
}
if (jsonResult.contains(""bug_status":"Active"")) {
return true;
}
return false;
}
public boolean hasClosed(String jsonResult) {
if (jsonResult.equals("")) {
return false;
}
if (jsonResult.contains(""bug_status":"Closed"")) {
return true;
}
if (jsonResult.contains(""bug_status":"Resolved"")) {
return true;
}
return false;
}
public boolean hasRejected(String jsonResult) {
if (jsonResult.equals("")) {
return false;
}
if (jsonResult.contains(""solution":"Reject"")) {
return true;
}
if (jsonResult.contains(""solution":"Won't Fix"")) {
return true;
}
// By Design
if (jsonResult.contains(""solution":"By Design"")) {
return true;
}
return false;
}
public InputStream doPost(String urlStr, Map<String, String> params) throws IOException {
StringBuilder sb = new StringBuilder();
for(Map.Entry<String, String> param : params.entrySet()) {
sb.append(param.getKey()).append("=").append(param.getValue()).append("&");
}
int len = sb.length();
if (len > 0) {
sb.deleteCharAt(len - 1);
}
String args = sb.toString();
//System.out.println("args: " + args);
return doPost(urlStr, args);
}
public InputStream doPost(String urlStr, String args) throws IOException {
URL url = null;
try {
url = new URL(urlStr);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
//String myCookie = "GerritAccount=aSecfaQr028r8-6yxggWFA1QQc0YQFz5";
if (sessionId != null) {
System.out.println("sessionId: " + sessionId);
connection.setRequestProperty("Cookie", sessionId);
}
//connection.setRequestProperty("Connection", "Keep-Alive");
/**
* 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。
* 通过把URLConnection设为输出,你可以把数据向你个Web页传送。下面是如何做:
*/
connection.setDoOutput(true);
//connection.setRequestMethod("POST");
/**
* 后,为了得到OutputStream,简单起见,把它约束在Writer并且放入POST信息中,例如: ...
*/
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
out.write(args); //向页面传递数据。post的关键所在!
// remember to clean up
out.flush();
out.close();
return connection.getInputStream();
}
private static String getResult(InputStream is) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(
is));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
}
return sb.toString();
}
}
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11热门文章
常见的移动App Bug??崩溃的测试用例设计如何用Jmeter做压力测试QC使用说明APP压力测试入门教程移动app测试中的主要问题jenkins+testng+ant+webdriver持续集成测试使用JMeter进行HTTP负载测试Selenium 2.0 WebDriver 使用指南