alter postTrainingGameInstanceResultToBDWeb

This commit is contained in:
LiLi 2017-04-14 09:48:19 +08:00
parent a48c3fd732
commit 89c487ee4b
8 changed files with 286 additions and 22 deletions

4
.gitignore vendored
View File

@ -6,4 +6,6 @@ target/
.project
.classpath
.settings/
*.log
*.log
*bin/
*target/

View File

@ -38,4 +38,10 @@ public class TrustieApi {
HttpHelper.sendPost(appConfig.getTrustieUrl(), map);
}
public void commitResultToTrustie(String jsonTestDetails){
HttpHelper.sendPost(appConfig.getTrustieUrl(), jsonTestDetails);
}
}

View File

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.educoder.jenkins.api.TrustieApi;
import com.educoder.jenkins.model.Case;
import com.educoder.jenkins.model.TestInfo;
import com.educoder.jenkins.utils.Base64Helper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -21,7 +23,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -99,7 +103,7 @@ public class PipeLineController extends BaseController {
}
// postResultToBDWeb(String status, String compileResult, String out, String in, String expectedOut)
/**
@ApiOperation(value = "处理结果并将结果回传到BDWeb", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@RequestMapping(path = "/commitToBDWeb ")
public JSONObject commitToBDWeb (@RequestParam String buildID,
@ -118,31 +122,33 @@ public class PipeLineController extends BaseController {
}
return callResult;
}
**/
@ApiOperation(value = "处理结果并将结果回传到BDWeb", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@RequestMapping(path = "/postTrainingGameInstanceResultToBDWeb ")
public void postTrainingGameInstanceResultToBDWeb(String buildID, String compileResult, String out, String in, String expectedOut){
try {
List<String> inputs=JSON.parseArray(in, String.class);
List<String> outputs=JSON.parseArray(out, String.class);
List<String> expectedOuts=JSON.parseArray(expectedOut, String.class);
TestInfo testInfo=new TestInfo();
testInfo.buildID=buildID;
TestInfo testInfo=new TestInfo(buildID,compileResult,"true");
for(int i=0;i<inputs.size();i++){
String pass="true";
if(!outputs.get(i).equals(expectedOuts.get(i))){
pass="false";
testInfo.setStatus("false");
}
Case caseOne=new Case("1",inputs.get(i),outputs.get(i),expectedOuts.get(i),pass);
// caseOne.decodeCase();
testInfo.getMsg().add(caseOne);
}
String jsonTestInfo=JSON.toJSONString(testInfo);
trustieApi.commitResultToTrustie(jsonTestInfo);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
logger.error(e.toString());
}
}
}
class TestInfo{
String buildID;
String status;
String outPut;
List<EveryOutput> msg;
}
class EveryOutput{
String caseId;
String input;
String output;
String expectedOutput;
String passed;
}

View File

@ -1,5 +1,9 @@
package com.educoder.jenkins.model;
import java.io.UnsupportedEncodingException;
import com.educoder.jenkins.utils.Base64Helper;
/**
* Created by weishao on 2017/4/12.
*/
@ -61,5 +65,12 @@ public class Case {
this.expectedOutput = expectedOutput;
this.passed = passed;
}
public void decodeCase() throws UnsupportedEncodingException {
// TODO Auto-generated constructor stub
this.caseId=Base64Helper.decode(caseId);
this.input=Base64Helper.decode(input);
this.output=Base64Helper.decode(output);
this.expectedOutput=Base64Helper.decode(expectedOutput);
this.passed=Base64Helper.decode(passed);
}
}

View File

@ -0,0 +1,99 @@
/**
* 文件名 : TestInfo.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author liliy
* 版本 : <版本>
* 修改时间 2017年4月14日
* 修改内容 <修改内容>
*/
package com.educoder.jenkins.model;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import com.educoder.jenkins.utils.Base64Helper;
/**
* <一句话功能简述>
* <功能详细描述>
* @author liliy
* @version [版本号2017年4月14日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class TestInfo {
private String buildID;
private String status;
private String outPut;
private List<Case> msg;
/**
* <一句话功能简述>
* <功能详细描述>
* @throws UnsupportedEncodingException
* @see [#方法#成员]
*/
public TestInfo(String buildID,String status,String outPut) throws UnsupportedEncodingException {
// TODO Auto-generated constructor stub
this.setBuildID(buildID);
this.setOutPut(outPut);
this.setStatus(status);
this.setMsg(new ArrayList<Case>());
// this.setBuildID(Base64Helper.decode(buildID));
// this.setOutPut(Base64Helper.decode(outPut));
// this.setStatus(Base64Helper.decode(status));
// this.setMsg(new ArrayList<Case>());
}
/**
* @return the buildID
*/
public String getBuildID() {
return buildID;
}
/**
* @param buildID the buildID to set
*/
public void setBuildID(String buildID) {
this.buildID = buildID;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return the outPut
*/
public String getOutPut() {
return outPut;
}
/**
* @param outPut the outPut to set
*/
public void setOutPut(String outPut) {
this.outPut = outPut;
}
/**
* @return the msg
*/
public List<Case> getMsg() {
return msg;
}
/**
* @param msg the msg to set
*/
public void setMsg(List<Case> msg) {
this.msg = msg;
}
}

View File

@ -89,6 +89,70 @@ public class HttpHelper {
outputStream.close();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
//使用finally块来关闭输出流输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
public static String sendPost(String url, String jsonTestDetails) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
// conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
String data = jsonTestDetails;
log.debug("POST: "+url+" DATA: "+data);
OutputStream outputStream = conn.getOutputStream();
outputStream.write(data.getBytes(Charset.forName("UTF-8")));
outputStream.flush();
outputStream.close();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;

View File

@ -0,0 +1,42 @@
/**
* 文件名 : JsonTest.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author liliy
* 版本 : <版本>
* 修改时间 2017年4月14日
* 修改内容 <修改内容>
*/
package cn.lili.test;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
/**
* <一句话功能简述>
* <功能详细描述>
* @author liliy
* @version [版本号2017年4月14日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class JsonTest {
@Test
public void testJsonArray() {
List<String> strList=new ArrayList<String>();
strList.add("111");
strList.add("222");
String jsonString2 = JSON.toJSONString(strList);
System.out.println(jsonString2);
List<String> users2 = JSON.parseArray(jsonString2, String.class);
System.out.println(users2);
}
}

View File

@ -0,0 +1,34 @@
/**
* 文件名 : PipelineControllerTest.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author liliy
* 版本 : <版本>
* 修改时间 2017年4月14日
* 修改内容 <修改内容>
*/
package cn.lili.test;
import org.junit.Test;
import com.educoder.jenkins.controller.PipeLineController;
/**
* <一句话功能简述>
* <功能详细描述>
* @author liliy
* @version [版本号2017年4月14日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class PipelineControllerTest {
@Test
public void testPostTrainingGameInstanceResultToBDWeb() {
PipeLineController pipeLineController=new PipeLineController();
String in="[\"输入1\",\"输入2\"]";String out="[\"输入1\",\"输入2\"]";String expectedOut="[\"输入1\",\"输入2\"]";
pipeLineController.postTrainingGameInstanceResultToBDWeb("321214", "qwsdfsewadfdafs", in, out, expectedOut);
}
}