diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index 842cad4825..33ca262ce5 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -95,7 +95,7 @@ public class APITestController { @PostMapping(value = "/import", consumes = {"multipart/form-data"}) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) - public ApiTest testCaseImport(@RequestPart(value = "file") MultipartFile file, @RequestPart("request") ApiTestImportRequest request) { + public ApiTest testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) { return apiTestService.apiTestImport(file, request); } diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index d0a9704d40..90bb70d770 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -35,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; @@ -263,7 +264,7 @@ public class APITestService { ApiImportParser apiImportParser = ApiImportParserFactory.getApiImportParser(request.getPlatform()); ApiImport apiImport = null; try { - apiImport = apiImportParser.parse(file.getInputStream(), request); + apiImport = apiImportParser.parse(file == null ? null : file.getInputStream(), request); } catch (Exception e) { LogUtil.error(e.getMessage(), e); MSException.throwException(Translator.get("parse_data_error")); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java index 99220cbdcd..49c9cce4c5 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestEnvironmentService.java @@ -5,6 +5,7 @@ import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.mapper.ApiTestEnvironmentMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.i18n.Translator; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -34,6 +35,7 @@ public class ApiTestEnvironmentService { } public void update(ApiTestEnvironmentWithBLOBs apiTestEnvironment) { + checkEnvironmentExist(apiTestEnvironment); apiTestEnvironmentMapper.updateByPrimaryKeyWithBLOBs(apiTestEnvironment); } @@ -47,9 +49,12 @@ public class ApiTestEnvironmentService { private void checkEnvironmentExist (ApiTestEnvironmentWithBLOBs environment) { if (environment.getName() != null) { ApiTestEnvironmentExample example = new ApiTestEnvironmentExample(); - example.createCriteria() - .andNameEqualTo(environment.getName()) + ApiTestEnvironmentExample.Criteria criteria = example.createCriteria(); + criteria.andNameEqualTo(environment.getName()) .andProjectIdEqualTo(environment.getProjectId()); + if (StringUtils.isNotBlank(environment.getId())) { + criteria.andIdNotEqualTo(environment.getId()); + } if (apiTestEnvironmentMapper.selectByExample(example).size() > 0) { MSException.throwException(Translator.get("api_test_environment_already_exists")); } diff --git a/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue b/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue index bb856849e9..3f837f59ab 100644 --- a/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue +++ b/frontend/src/business/components/api/test/components/ApiEnvironmentConfig.vue @@ -49,13 +49,16 @@ this.projectId = projectId; this.getEnvironments(); }, - deleteEnvironment(environment) { + deleteEnvironment(environment, index) { if (environment.id) { this.result = this.$get('/api/environment/delete/' + environment.id, () => { this.$success(this.$t('commons.delete_success')); this.getEnvironments(); }); } + else { + this.environments.splice(index, 1); + } }, copyEnvironment(environment) { if (!environment.id) { @@ -149,4 +152,5 @@ height: 100%; position: absolute; } + diff --git a/frontend/src/business/components/api/test/components/import/ApiImport.vue b/frontend/src/business/components/api/test/components/import/ApiImport.vue index beb1397e8d..44aa5b07c4 100644 --- a/frontend/src/business/components/api/test/components/import/ApiImport.vue +++ b/frontend/src/business/components/api/test/components/import/ApiImport.vue @@ -29,7 +29,7 @@ - + {{$t('api_test.environment.environment_config')}} +