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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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
public ApiImport parse(InputStream source) {
String testStr = getApiTestStr(source);
@ -69,7 +82,7 @@ public class PostmanParser extends ApiImportAbstractParser {
if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) {
body.setRaw(postmanBody.getString(bodyMode));
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);
} 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);

View File

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

View File

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

View File

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

View File

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

View File

@ -16,10 +16,6 @@
</el-select>
</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-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')"/>
@ -86,6 +82,7 @@
for (let i in this.environments) {
if (this.environments[i].id === this.scenario.environmentId) {
this.scenario.environment = this.environments[i];
this.setRequestEnvironments();
hasEnvironment = true;
break;
}
@ -104,9 +101,7 @@
for (let i in this.environments) {
if (this.environments[i].id === value) {
this.scenario.environment = this.environments[i];
this.scenario.requests.forEach(request => {
request.environment = this.environments[i];
});
this.setRequestEnvironments();
break;
}
}
@ -126,6 +121,11 @@
},
environmentConfigClose() {
this.getEnvironments();
},
setRequestEnvironments() {
this.scenario.requests.forEach(request => {
request.environment = this.scenario.environment;
});
}
}
}

View File

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

View File

@ -10,14 +10,10 @@
</span>
</slot>
</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}">
<!-- <span :style="{'line-height': itemBarHeight - 10 + 'px'}" class="item-left">-->
<!--&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="请输入内容"/>
<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')"/>
<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>
</div>
</ms-aside-container>