feat(测试跟踪): 集成zentao
This commit is contained in:
parent
0c7acfebea
commit
4598c10864
|
@ -4,7 +4,7 @@
|
|||
|
||||
<select id="getProjectWithWorkspace" resultType="io.metersphere.dto.ProjectDTO">
|
||||
select p.id, p.workspace_id, p.name, p.description, p.update_time,
|
||||
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key
|
||||
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key, p.zentao_id
|
||||
from project p
|
||||
join workspace w on p.workspace_id = w.id
|
||||
<where>
|
||||
|
|
|
@ -16,5 +16,5 @@ public class ProjectDTO {
|
|||
private Long updateTime;
|
||||
private String tapdId;
|
||||
private String jiraKey;
|
||||
|
||||
private String zentaoId;
|
||||
}
|
||||
|
|
|
@ -21,17 +21,33 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class ZentaoPlatform extends AbstractIssuePlatform {
|
||||
/**
|
||||
* zentao account
|
||||
*/
|
||||
private final String account;
|
||||
/**
|
||||
* zentao password
|
||||
*/
|
||||
private final String password;
|
||||
/**
|
||||
* zentao url eg:http://x.x.x.x/zentao
|
||||
*/
|
||||
private final String url;
|
||||
|
||||
public ZentaoPlatform(IssuesRequest issuesRequest) {
|
||||
super(issuesRequest);
|
||||
String config = getPlatformConfig(IssuesManagePlatform.Zentao.toString());
|
||||
JSONObject object = JSON.parseObject(config);
|
||||
this.account = object.getString("account");
|
||||
this.password = object.getString("password");
|
||||
this.url = object.getString("url");
|
||||
}
|
||||
|
||||
@Override
|
||||
String getProjectId() {
|
||||
// TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
|
||||
// Project project = projectService.getProjectById(testCase.getProjectId());
|
||||
// todo return getZentao ID
|
||||
return "002";
|
||||
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
|
||||
Project project = projectService.getProjectById(testCase.getProjectId());
|
||||
return project.getZentaoId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,62 +79,59 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
}
|
||||
});
|
||||
return list;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Issues getZentaoIssues(String bugId) {
|
||||
String projectId = getProjectId();
|
||||
|
||||
String session = login();
|
||||
|
||||
String config = getPlatformConfig(IssuesManagePlatform.Zentao.toString());
|
||||
JSONObject object = JSON.parseObject(config);
|
||||
String account = object.getString("account");
|
||||
String password = object.getString("password");
|
||||
String url = object.getString("url");
|
||||
url = ZentaoUtils.getUrl(url, account, password);
|
||||
System.out.println(url);
|
||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(new HttpHeaders());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange("http://xx/zentao/bug-view-"+ bugId +".json?zentaosid=" + session, HttpMethod.POST, requestEntity, String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(url + "api-getModel-bug-getById-bugID={bugId}?zentaosid=" + session,
|
||||
HttpMethod.POST, requestEntity, String.class, bugId);
|
||||
String body = responseEntity.getBody();
|
||||
System.out.println(body);
|
||||
JSONObject obj = JSONObject.parseObject(body);
|
||||
System.out.println(obj);
|
||||
if (obj != null) {
|
||||
JSONObject data = obj.getJSONObject("data");
|
||||
JSONArray bugs = data.getJSONArray("bugs");
|
||||
for (int j = 0; j < bugs.size(); j++) {
|
||||
JSONObject bug = bugs.getJSONObject(j);
|
||||
String id = bug.getString("id");
|
||||
String title = bug.getString("title");
|
||||
String description = bug.getString("steps");
|
||||
Long createTime = bug.getLong("openedDate");
|
||||
String status = bug.getString("status");
|
||||
String reporter = bug.getString("openedBy");
|
||||
|
||||
Issues issues = new Issues();
|
||||
issues.setId(id);
|
||||
issues.setTitle(title);
|
||||
issues.setDescription(description);
|
||||
issues.setCreateTime(createTime);
|
||||
issues.setStatus(status);
|
||||
issues.setReporter(reporter);
|
||||
return issues;
|
||||
JSONObject bug = obj.getJSONObject("data");
|
||||
String id = bug.getString("id");
|
||||
String title = bug.getString("title");
|
||||
String description = bug.getString("steps");
|
||||
Long createTime = bug.getLong("openedDate");
|
||||
String status = bug.getString("status");
|
||||
String reporter = bug.getString("openedBy");
|
||||
int deleted = bug.getInteger("deleted");
|
||||
if (deleted == 1) {
|
||||
return new Issues();
|
||||
}
|
||||
Issues issues = new Issues();
|
||||
issues.setId(id);
|
||||
issues.setTitle(title);
|
||||
issues.setDescription(description);
|
||||
issues.setCreateTime(createTime);
|
||||
issues.setStatus(status);
|
||||
issues.setReporter(reporter);
|
||||
return issues;
|
||||
}
|
||||
return new Issues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addIssue(IssuesRequest issuesRequest) {
|
||||
String config = getPlatformConfig(IssuesManagePlatform.Zentao.toString());
|
||||
|
||||
String session = login();
|
||||
JSONObject object = JSON.parseObject(config);
|
||||
// String account = object.getString("account");
|
||||
// String password = object.getString("password");
|
||||
String projectId = getProjectId();
|
||||
|
||||
if (StringUtils.isBlank(projectId)) {
|
||||
MSException.throwException("add zentao bug fail, project zentao id is null");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(session)) {
|
||||
MSException.throwException("session is null");
|
||||
}
|
||||
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("product", "003");
|
||||
paramMap.add("product", projectId);
|
||||
paramMap.add("title", issuesRequest.getTitle());
|
||||
paramMap.add("openedBuild", "123");
|
||||
paramMap.add("steps", issuesRequest.getContent());
|
||||
|
@ -126,12 +139,12 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
|
||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(paramMap, new HttpHeaders());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
System.out.println("zentao add bug");
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange("http://xx/zentao/bug-create-3.json?zentaosid=" + session, HttpMethod.POST, requestEntity, String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(url + "api-getModel-bug-create.json?zentaosid=" + session, HttpMethod.POST, requestEntity, String.class);
|
||||
String body = responseEntity.getBody();
|
||||
JSONObject obj = JSONObject.parseObject(body);
|
||||
if (obj != null) {
|
||||
String id = obj.getString("data");
|
||||
JSONObject data = obj.getJSONObject("data");
|
||||
String id = data.getString("id");
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
// 用例与第三方缺陷平台中的缺陷关联
|
||||
TestCaseIssues testCaseIssues = new TestCaseIssues();
|
||||
|
@ -147,9 +160,6 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
issuesMapper.insert(issues);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(obj);
|
||||
// return responseEntity.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -160,26 +170,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
@Override
|
||||
public void testAuth() {
|
||||
try {
|
||||
String config = getPlatformConfig(IssuesManagePlatform.Zentao.toString());
|
||||
JSONObject object = JSON.parseObject(config);
|
||||
String account = object.getString("account");
|
||||
String password = object.getString("password");
|
||||
String url = object.getString("url");
|
||||
url = ZentaoUtils.getUrl(url, account, password);
|
||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(new HttpHeaders());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> exchange = restTemplate.exchange(url + "&m=user&f=apilogin", HttpMethod.GET, requestEntity, String.class);
|
||||
|
||||
String body = exchange.getBody();
|
||||
JSONObject obj = JSONObject.parseObject(body);
|
||||
System.out.println(obj);
|
||||
if (obj != null) {
|
||||
String errcode = obj.getString("errcode");
|
||||
String errmsg = obj.getString("errmsg");
|
||||
if (StringUtils.isNotBlank(errcode)) {
|
||||
MSException.throwException(errmsg);
|
||||
}
|
||||
}
|
||||
login();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException("验证失败!");
|
||||
|
@ -190,21 +181,34 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
|
||||
private String login() {
|
||||
String session = getSession();
|
||||
String loginUrl = "http://xx/zentao/user-login.json?zentaosid=" + session;
|
||||
String loginUrl = url + "user-login.json?zentaosid=" + session;
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("account", "admin");
|
||||
paramMap.add("password", "xx");
|
||||
|
||||
paramMap.add("account", account);
|
||||
paramMap.add("password", password);
|
||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(paramMap, new HttpHeaders());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(loginUrl, HttpMethod.POST, requestEntity, String.class);
|
||||
return session;
|
||||
String body = responseEntity.getBody();
|
||||
JSONObject obj = JSONObject.parseObject(body);
|
||||
JSONObject user = obj.getJSONObject("user");
|
||||
if (user == null) {
|
||||
LogUtil.error("login fail");
|
||||
LogUtil.error(obj);
|
||||
// 登录失败,获取的session无效,置空session
|
||||
MSException.throwException("zentao login fail");
|
||||
}
|
||||
String username = user.getString("account");
|
||||
if (!StringUtils.equals(username, account)) {
|
||||
LogUtil.error("login fail,inconsistent users");
|
||||
MSException.throwException("zentao login fail");
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
private String getSession() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(new HttpHeaders());
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange("http://xx.xxx.xxx.xxx/zentao/api-getsessionid.json", HttpMethod.GET, requestEntity, String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(url + "api-getsessionid.json", HttpMethod.GET, requestEntity, String.class);
|
||||
String body = responseEntity.getBody();
|
||||
JSONObject obj = JSONObject.parseObject(body);
|
||||
JSONObject data = obj.getJSONObject("data");
|
||||
|
|
|
@ -63,9 +63,11 @@ public class IssuesService {
|
|||
|
||||
boolean tapd = isIntegratedPlatform(orgId, IssuesManagePlatform.Tapd.toString());
|
||||
boolean jira = isIntegratedPlatform(orgId, IssuesManagePlatform.Jira.toString());
|
||||
boolean zentao = isIntegratedPlatform(orgId, IssuesManagePlatform.Zentao.toString());
|
||||
|
||||
String tapdId = getTapdProjectId(issuesRequest.getTestCaseId());
|
||||
String jiraKey = getJiraProjectKey(issuesRequest.getTestCaseId());
|
||||
String zentaoId = getZentaoProjectId(issuesRequest.getTestCaseId());
|
||||
|
||||
List<String> platforms = new ArrayList<>();
|
||||
|
||||
|
@ -82,7 +84,13 @@ public class IssuesService {
|
|||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(tapdId) && StringUtils.isBlank(jiraKey)) {
|
||||
if (zentao) {
|
||||
if (StringUtils.isNotBlank(zentaoId)) {
|
||||
platforms.add(IssuesManagePlatform.Zentao.name());
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(tapdId) && StringUtils.isBlank(jiraKey) && StringUtils.isBlank(zentaoId)) {
|
||||
platforms.add("LOCAL");
|
||||
}
|
||||
|
||||
|
@ -122,6 +130,7 @@ public class IssuesService {
|
|||
|
||||
boolean tapd = isIntegratedPlatform(orgId, IssuesManagePlatform.Tapd.toString());
|
||||
boolean jira = isIntegratedPlatform(orgId, IssuesManagePlatform.Jira.toString());
|
||||
boolean zentao = isIntegratedPlatform(orgId, IssuesManagePlatform.Zentao.toString());
|
||||
|
||||
List<String> platforms = new ArrayList<>();
|
||||
if (tapd) {
|
||||
|
@ -140,6 +149,13 @@ public class IssuesService {
|
|||
}
|
||||
}
|
||||
|
||||
if (zentao) {
|
||||
String zentaoId = getZentaoProjectId(caseId);
|
||||
if (StringUtils.isNotBlank(zentaoId)) {
|
||||
platforms.add(IssuesManagePlatform.Zentao.name());
|
||||
}
|
||||
}
|
||||
|
||||
platforms.add("LOCAL");
|
||||
IssuesRequest issueRequest = new IssuesRequest();
|
||||
issueRequest.setTestCaseId(caseId);
|
||||
|
@ -152,18 +168,24 @@ public class IssuesService {
|
|||
return list;
|
||||
}
|
||||
|
||||
public String getTapdProjectId(String testCaseId) {
|
||||
private String getTapdProjectId(String testCaseId) {
|
||||
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
|
||||
Project project = projectService.getProjectById(testCase.getProjectId());
|
||||
return project.getTapdId();
|
||||
}
|
||||
|
||||
public String getJiraProjectKey(String testCaseId) {
|
||||
private String getJiraProjectKey(String testCaseId) {
|
||||
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
|
||||
Project project = projectService.getProjectById(testCase.getProjectId());
|
||||
return project.getJiraKey();
|
||||
}
|
||||
|
||||
private String getZentaoProjectId(String testCaseId) {
|
||||
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
|
||||
Project project = projectService.getProjectById(testCase.getProjectId());
|
||||
return project.getZentaoId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否关联平台
|
||||
*/
|
||||
|
|
|
@ -63,6 +63,9 @@
|
|||
<el-form-item :label="$t('project.jira_key')" v-if="jira">
|
||||
<el-input v-model="form.jiraKey" autocomplete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="Zentao项目ID" v-if="zentao">
|
||||
<el-input v-model="form.zentaoId" autocomplete="off"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template v-slot:footer>
|
||||
<div class="dialog-footer">
|
||||
|
@ -116,6 +119,7 @@ export default {
|
|||
items: [],
|
||||
tapd: false,
|
||||
jira: false,
|
||||
zentao: false,
|
||||
form: {},
|
||||
currentPage: 1,
|
||||
pageSize: 5,
|
||||
|
@ -194,6 +198,9 @@ export default {
|
|||
if (platforms.indexOf("Jira") !== -1) {
|
||||
this.jira = true;
|
||||
}
|
||||
if (platforms.indexOf("Zentao") !== -1) {
|
||||
this.zentao = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue