Merge branch 'master' of github.com:fit2cloudrd/metersphere-server

This commit is contained in:
Captain.B 2020-07-17 10:19:40 +08:00
commit 430b1e9fca
8 changed files with 59 additions and 45 deletions

View File

@ -14,10 +14,23 @@ import org.apache.commons.lang3.StringUtils;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class PostmanParser extends ApiImportAbstractParser { public class PostmanParser extends ApiImportAbstractParser {
private static Map<String, String> postmanBodyRowMap;
static {
postmanBodyRowMap = new HashMap<>();
postmanBodyRowMap.put("json", "application/json");
postmanBodyRowMap.put("text", "text/plain");
postmanBodyRowMap.put("html", "text/html");
postmanBodyRowMap.put("xml", "text/xml");
postmanBodyRowMap.put("javascript", "application/x-javascript");
}
@Override @Override
public ApiImport parse(InputStream source) { public ApiImport parse(InputStream source) {
String testStr = getApiTestStr(source); String testStr = getApiTestStr(source);
@ -69,7 +82,7 @@ public class PostmanParser extends ApiImportAbstractParser {
if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) { if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) {
body.setRaw(postmanBody.getString(bodyMode)); body.setRaw(postmanBody.getString(bodyMode));
body.setType(MsRequestBodyType.RAW.value()); body.setType(MsRequestBodyType.RAW.value());
String contentType = postmanBody.getJSONObject("options").getJSONObject("raw").getString("language"); String contentType = postmanBodyRowMap.get(postmanBody.getJSONObject("options").getJSONObject("raw").getString("language"));
addContentType(request, contentType); addContentType(request, contentType);
} else if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.FORM_DATA.value()) || StringUtils.equals(bodyMode, PostmanRequestBodyMode.URLENCODED.value())) { } else if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.FORM_DATA.value()) || StringUtils.equals(bodyMode, PostmanRequestBodyMode.URLENCODED.value())) {
List<PostmanKeyValue> postmanKeyValues = JSON.parseArray(postmanBody.getString(bodyMode), PostmanKeyValue.class); List<PostmanKeyValue> postmanKeyValues = JSON.parseArray(postmanBody.getString(bodyMode), PostmanKeyValue.class);

View File

@ -31,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
@ -39,8 +40,6 @@ import java.util.Random;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Resource;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class APITestService { public class APITestService {
@ -76,6 +75,7 @@ public class APITestService {
if (files == null || files.isEmpty()) { if (files == null || files.isEmpty()) {
throw new IllegalArgumentException(Translator.get("file_cannot_be_null")); throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
} }
checkNameExist(request);
ApiTest test = createTest(request); ApiTest test = createTest(request);
saveFile(test.getId(), files); saveFile(test.getId(), files);
} }
@ -173,12 +173,6 @@ public class APITestService {
} }
} }
private Boolean isNameExist(SaveAPITestRequest request) {
ApiTestExample example = new ApiTestExample();
example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
return apiTestMapper.countByExample(example) > 0;
}
private ApiTest updateTest(SaveAPITestRequest request) { private ApiTest updateTest(SaveAPITestRequest request) {
checkNameExist(request); checkNameExist(request);
final ApiTest test = new ApiTest(); final ApiTest test = new ApiTest();
@ -193,7 +187,6 @@ public class APITestService {
} }
private ApiTest createTest(SaveAPITestRequest request) { private ApiTest createTest(SaveAPITestRequest request) {
checkNameExist(request);
final ApiTest test = new ApiTest(); final ApiTest test = new ApiTest();
test.setId(request.getId()); test.setId(request.getId());
test.setName(request.getName()); test.setName(request.getName());
@ -290,10 +283,6 @@ public class APITestService {
request.setName(name.substring(0, name.length() - suffix.length())); request.setName(name.substring(0, name.length() - suffix.length()));
} }
} }
if (isNameExist(request)) {
request.setName(request.getName() + "_" + request.getId().substring(0, 5));
}
return request; return request;
} }
} }

View File

@ -34,7 +34,7 @@ public class ApiTestEnvironmentService {
} }
public void update(ApiTestEnvironmentWithBLOBs apiTestEnvironment) { public void update(ApiTestEnvironmentWithBLOBs apiTestEnvironment) {
apiTestEnvironmentMapper.updateByPrimaryKeySelective(apiTestEnvironment); apiTestEnvironmentMapper.updateByPrimaryKey(apiTestEnvironment);
} }
public String add(ApiTestEnvironmentWithBLOBs apiTestEnvironmentWithBLOBs) { public String add(ApiTestEnvironmentWithBLOBs apiTestEnvironmentWithBLOBs) {

View File

@ -255,7 +255,7 @@
return this.test.isValid() && !this.change; return this.test.isValid() && !this.change;
}, },
isDisabled() { isDisabled() {
return !(this.test.isValid()) return !(this.test.isValid() && this.change);
} }
}, },

View File

@ -50,19 +50,34 @@
this.getEnvironments(); this.getEnvironments();
}, },
deleteEnvironment(environment) { deleteEnvironment(environment) {
this.result = this.$get('/api/environment/delete/' + environment.id, response => { if (environment.id) {
this.$success(this.$t('commons.delete_success')); this.result = this.$get('/api/environment/delete/' + environment.id, () => {
this.getEnvironments(); this.$success(this.$t('commons.delete_success'));
}); this.getEnvironments();
});
}
}, },
copyEnvironment(environment) { copyEnvironment(environment) {
let newEnvironment = {}; let newEnvironment = {};
Object.assign(newEnvironment, environment); Object.assign(newEnvironment, environment);
newEnvironment.id = null; newEnvironment.id = null;
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
this.$refs.environmentEdit._save(newEnvironment);
this.environments.push(newEnvironment); this.environments.push(newEnvironment);
this.$refs.environmentItems.itemSelected(this.environments.length -1 , newEnvironment);
},
getNoRepeatName(name) {
for (let i in this.environments) {
if (this.environments[i].name === name) {
return this.getNoRepeatName(name + ' copy');
}
}
return name;
}, },
addEnvironment() { addEnvironment() {
this.environments.push(this.getDefaultEnvironment()); let newEnvironment = this.getDefaultEnvironment();
this.environments.push(newEnvironment);
this.$refs.environmentItems.itemSelected(this.environments.length -1 , newEnvironment);
}, },
environmentSelected(environment) { environmentSelected(environment) {
this.getEnvironment(environment); this.getEnvironment(environment);
@ -97,6 +112,7 @@
close() { close() {
this.$emit('close'); this.$emit('close');
this.visible = false; this.visible = false;
this.$refs.environmentEdit.clearValidate();
} }
} }
} }
@ -116,7 +132,4 @@
height: 100%; height: 100%;
position: absolute; position: absolute;
} }
</style> </style>

View File

@ -16,10 +16,6 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- <el-form-item :label="$t('api_test.scenario.base_url')" prop="url">-->
<!-- <el-input :placeholder="$t('api_test.scenario.base_url_description')" v-model="scenario.url" maxlength="200"/>-->
<!-- </el-form-item>-->
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane :label="$t('api_test.scenario.variables')" name="parameters"> <el-tab-pane :label="$t('api_test.scenario.variables')" name="parameters">
<ms-api-scenario-variables :is-read-only="isReadOnly" :items="scenario.variables" :description="$t('api_test.scenario.kv_description')"/> <ms-api-scenario-variables :is-read-only="isReadOnly" :items="scenario.variables" :description="$t('api_test.scenario.kv_description')"/>
@ -86,6 +82,7 @@
for (let i in this.environments) { for (let i in this.environments) {
if (this.environments[i].id === this.scenario.environmentId) { if (this.environments[i].id === this.scenario.environmentId) {
this.scenario.environment = this.environments[i]; this.scenario.environment = this.environments[i];
this.setRequestEnvironments();
hasEnvironment = true; hasEnvironment = true;
break; break;
} }
@ -104,9 +101,7 @@
for (let i in this.environments) { for (let i in this.environments) {
if (this.environments[i].id === value) { if (this.environments[i].id === value) {
this.scenario.environment = this.environments[i]; this.scenario.environment = this.environments[i];
this.scenario.requests.forEach(request => { this.setRequestEnvironments();
request.environment = this.environments[i];
});
break; break;
} }
} }
@ -126,6 +121,11 @@
}, },
environmentConfigClose() { environmentConfigClose() {
this.getEnvironments(); this.getEnvironments();
},
setRequestEnvironments() {
this.scenario.requests.forEach(request => {
request.environment = this.scenario.environment;
});
} }
} }
} }

View File

@ -78,30 +78,30 @@
save() { save() {
this.$refs['from'].validate((valid) => { this.$refs['from'].validate((valid) => {
if (valid) { if (valid) {
this._save(); this._save(this.environment);
} else { } else {
return false; return false;
} }
}); });
}, },
_save() { _save(environment) {
let param = this.buildParam(); let param = this.buildParam(environment);
let url = '/api/environment/add'; let url = '/api/environment/add';
if (param.id) { if (param.id) {
url = '/api/environment/update'; url = '/api/environment/update';
} }
this.result = this.$post(url, param, response => { this.result = this.$post(url, param, response => {
if (!param.id) { if (!param.id) {
this.environment.id = response.data; environment.id = response.data;
} }
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
}); });
}, },
buildParam() { buildParam(environment) {
let param = {}; let param = {};
Object.assign(param, this.environment); Object.assign(param, environment);
param.variables = JSON.stringify(this.environment.variables); param.variables = JSON.stringify(environment.variables);
param.headers = JSON.stringify(this.environment.headers); param.headers = JSON.stringify(environment.headers);
return param; return param;
}, },
validateSocket(socket) { validateSocket(socket) {
@ -135,6 +135,9 @@
}, },
cancel() { cancel() {
this.$emit('close'); this.$emit('close');
},
clearValidate() {
this.$refs["from"].clearValidate();
} }
}, },
} }

View File

@ -10,14 +10,10 @@
</span> </span>
</slot> </slot>
</div> </div>
<div :style="{'height': itemBarHeight + 'px'}" v-for="(item, index) in data" :key="index" class="item-bar" @click="itemSelected(index, item)" :class="{'item-selected' : index == selectIndex}"> <div :style="{'height': itemBarHeight + 'px'}" v-for="(item, index) in data" :key="index" class="item-bar" @click="itemSelected(index, item)" :class="{'item-selected' : index == selectIndex}">
<!-- <span :style="{'line-height': itemBarHeight - 10 + 'px'}" class="item-left">--> <input class="item-input" :style="{'height': itemBarHeight - 12 + 'px', 'line-height': itemBarHeight - 12 + 'px', 'width': width - 90 + 'px'}" v-model="item.name" :placeholder="$t('commons.input_content')"/>
<!--&lt;!&ndash; {{item.name}}&ndash;&gt;-->
<!-- </span>-->
<input class="item-input" :style="{'height': itemBarHeight - 12 + 'px', 'line-height': itemBarHeight - 12 + 'px', 'width': width - 90 + 'px'}" v-model="item.name" placeholder="请输入内容"/>
<span :style="{'line-height': itemBarHeight - 10 + 'px'}" class="item-right"> <span :style="{'line-height': itemBarHeight - 10 + 'px'}" class="item-right">
<i v-for="(operator, index) in itemOperators" :key="index" :class="operator.icon" @click="operator.func(item)"/> <i v-for="(operator, index) in itemOperators" :key="index" :class="operator.icon" @click.stop="operator.func(item)"/>
</span> </span>
</div> </div>
</ms-aside-container> </ms-aside-container>