refactor: 简化代码

This commit is contained in:
q4speed 2020-07-23 17:39:26 +08:00
parent ebefc9df76
commit f7f8258371
3 changed files with 6 additions and 15 deletions

View File

@ -11,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.http.HttpMethod;
import java.io.InputStream;
import java.util.Map;
public class MsParser extends ApiImportAbstractParser {
@ -19,9 +18,7 @@ public class MsParser extends ApiImportAbstractParser {
public ApiImport parse(InputStream source, ApiTestImportRequest request) {
String testStr = getApiTestStr(source);
ApiImport apiImport = JSON.parseObject(parsePluginFormat(testStr), ApiImport.class);
apiImport.getScenarios().forEach(scenario -> {
setScenarioByRequest(scenario, request);
});
apiImport.getScenarios().forEach(scenario -> setScenarioByRequest(scenario, request));
return apiImport;
}
@ -45,9 +42,7 @@ public class MsParser extends ApiImportAbstractParser {
requestObject.put("type", RequestType.HTTP);
}
requestTmpObject.keySet().forEach(key -> {
requestObject.put(key, requestTmpObject.get(key));
});;
requestTmpObject.keySet().forEach(key -> requestObject.put(key, requestTmpObject.get(key)));
requestObject.put("name", requestName);
JSONArray bodies = requestObject.getJSONArray("body");
if (StringUtils.equalsIgnoreCase(requestObject.getString("method"), HttpMethod.POST.name()) && bodies != null) {

View File

@ -22,7 +22,7 @@ import java.util.Map;
public class PostmanParser extends ApiImportAbstractParser {
private static Map<String, String> postmanBodyRowMap;
private static final Map<String, String> postmanBodyRowMap;
static {
postmanBodyRowMap = new HashMap<>();

View File

@ -27,7 +27,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
@Override
public ApiImport parse(InputStream source, ApiTestImportRequest request) {
Swagger swagger = null;
Swagger swagger;
if (StringUtils.isNotBlank(request.getSwaggerUrl())) {
swagger = new SwaggerParser().read(request.getSwaggerUrl());
} else {
@ -35,9 +35,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
}
ApiImport apiImport = new ApiImport();
apiImport.setScenarios(parseRequests(swagger));
apiImport.getScenarios().forEach(scenario -> {
scenario.setEnvironmentId(request.getEnvironmentId());
});
apiImport.getScenarios().forEach(scenario -> scenario.setEnvironmentId(request.getEnvironmentId()));
return apiImport;
}
@ -45,7 +43,6 @@ public class Swagger2Parser extends ApiImportAbstractParser {
Map<String, Path> paths = swagger.getPaths();
Set<String> pathNames = paths.keySet();
Map<String, Scenario> scenarioMap = new HashMap<>();
List<Scenario> scenarios = new ArrayList<>();
for (String pathName : pathNames) {
Path path = paths.get(pathName);
Map<HttpMethod, Operation> operationMap = path.getOperationMap();
@ -78,8 +75,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
}
}
scenarios.addAll(scenarioMap.values());
return scenarios;
return new ArrayList<>(scenarioMap.values());
}
private void parseParameters(Operation operation, Map<String, Model> definitions, HttpRequest request) {