Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: save case merge interfaces #431

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ public Response validInvitation(@Valid @RequestBody ValidInvitationRequestType r
@PostMapping("/addItemsByAppNameAndInterfaceName")
@ResponseBody
public Response addItemsByAppAndInterface(
@RequestHeader(name = Constants.ACCESS_TOKEN) String token,
@Valid @RequestBody FSAddItemsByAppAndInterfaceRequestType request) {
List<String> path = fileSystemService.addItemsByAppAndInterface(request);
String userName = jwtService.getUserName(token);
List<String> path = fileSystemService.addItemsByAppAndInterface(request, userName);
FSAddItemsByAppAndInterfaceResponseType response = new FSAddItemsByAppAndInterfaceResponseType();
if (CollectionUtils.isEmpty(path)) {
response.setSuccess(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.arextest.common.exceptions.ArexException;
import com.arextest.common.jwt.JWTService;
import com.arextest.config.model.dto.record.ServiceCollectConfiguration;
import com.arextest.config.repository.ConfigRepositoryProvider;
import com.arextest.web.common.LoadResource;
import com.arextest.web.common.LogUtils;
Expand All @@ -23,7 +22,6 @@
import com.arextest.web.core.repository.ReportPlanStatisticRepository;
import com.arextest.web.core.repository.UserRepository;
import com.arextest.web.core.repository.UserWorkspaceRepository;
import com.arextest.web.core.repository.mongo.ScheduleConfigurationRepositoryImpl;
import com.arextest.web.model.contract.contracts.config.replay.ScheduleConfiguration;
import com.arextest.web.model.contract.contracts.filesystem.BatchGetInterfaceCaseRequestType;
import com.arextest.web.model.contract.contracts.filesystem.BatchGetInterfaceCaseResponseType;
Expand Down Expand Up @@ -805,7 +803,8 @@ public FSQueryCaseResponseType queryDebuggingCase(String planId, String recordId
return response;
}

public List<String> addItemsByAppAndInterface(FSAddItemsByAppAndInterfaceRequestType request) {
public List<String> addItemsByAppAndInterface(FSAddItemsByAppAndInterfaceRequestType request,
String userName) {
List<String> path = new ArrayList<>();
if (CollectionUtils.isNotEmpty(request.getParentPath())) {
path.addAll(request.getParentPath());
Expand All @@ -815,7 +814,8 @@ public List<String> addItemsByAppAndInterface(FSAddItemsByAppAndInterfaceRequest
LogUtils.error(LOGGER, "Workspace not found, workspaceId: {}", request.getWorkspaceId());
return null;
}
String[] defaultPath = new String[2];
String[] defaultPath = new String[3];
// add folder
FSNodeDto appIdNode = fileSystemUtils.findByNodeName(treeDto.getRoots(),
request.getAppName());
if (appIdNode == null) {
Expand All @@ -836,6 +836,7 @@ public List<String> addItemsByAppAndInterface(FSAddItemsByAppAndInterfaceRequest
} else {
defaultPath[0] = appIdNode.getInfoId();
}
// add interface
FSNodeDto interfaceNode = fileSystemUtils.findByNodeName(appIdNode.getChildren(),
request.getInterfaceName());
if (interfaceNode == null) {
Expand All @@ -851,13 +852,50 @@ public List<String> addItemsByAppAndInterface(FSAddItemsByAppAndInterfaceRequest
request.getInterfaceName());
return null;
}
interfaceNode = fileSystemUtils.findByNodeName(addInterface.getRight().getRoots(),
request.getInterfaceName());
defaultPath[1] = addInterface.getLeft();
} else {
defaultPath[1] = interfaceNode.getInfoId();
}

// add case
FSNodeDto caseNode = fileSystemUtils.findByNodeName(interfaceNode.getChildren(),
request.getNodeName());
if (caseNode == null) {
FSAddItemRequestType addCaseRequest = new FSAddItemRequestType();
addCaseRequest.setId(treeDto.getId());
addCaseRequest.setNodeName(request.getNodeName());
addCaseRequest.setNodeType(FSInfoItem.CASE);
addCaseRequest.setParentPath(Arrays.asList(defaultPath));
MutablePair<String, FSTreeDto> addCase = addItem(addCaseRequest);
if (addCase == null) {
LogUtils.error(LOGGER, "Add case failed, workspaceId: {}, nodeName: {}",
request.getWorkspaceId(),
request.getNodeName());
return null;
}
defaultPath[2] = addCase.getLeft();
} else {
defaultPath[2] = caseNode.getInfoId();
}
path.addAll(Arrays.asList(defaultPath));

// save interface
FSSaveInterfaceRequestType saveInterfaceRequest = buildSaveInterfaceRequest(request,
defaultPath[1]);
saveInterface(saveInterfaceRequest, userName);

//save case
FSSaveCaseRequestType saveCaseRequest = buildSaveCaseRequest(request, defaultPath[2]);
saveCase(saveCaseRequest, userName);

//pin case
FSPinMockRequestType pinMockRequest = buildPinMockRequest(request, defaultPath[2]);
pinMock(pinMockRequest);
}


// add the related information about the replay interface to the manual interface
this.addReplayInfoToManual(request.getOperationId(), path);
return path;
Expand Down Expand Up @@ -1529,4 +1567,50 @@ public List<FSPathInfoDto> getAbsolutePathInfo(String infoId, Integer nodeType)
}
return path;
}

private FSSaveInterfaceRequestType buildSaveInterfaceRequest(
FSAddItemsByAppAndInterfaceRequestType in, String id) {
FSSaveInterfaceRequestType out = new FSSaveInterfaceRequestType();
out.setAddress(in.getAddress());
out.setBody(in.getBody());
out.setId(id);
out.setHeaders(in.getHeaders());
out.setLabelIds(in.getLabelIds());
out.setAuth(in.getAuth());
out.setDescription(in.getDescription());
out.setParams(in.getParams());
out.setWorkspaceId(in.getWorkspaceId());
out.setPreRequestScripts(in.getPreRequestScripts());
out.setTestAddress(in.getTestAddress());
out.setTestScripts(in.getTestScripts());
return out;
}

private FSSaveCaseRequestType buildSaveCaseRequest(FSAddItemsByAppAndInterfaceRequestType in,
String id) {
FSSaveCaseRequestType out = new FSSaveCaseRequestType();
out.setId(id);
out.setAddress(in.getAddress());
out.setBody(in.getBody());
out.setHeaders(in.getHeaders());
out.setLabelIds(in.getLabelIds());
out.setAuth(in.getAuth());
out.setDescription(in.getDescription());
out.setParams(in.getParams());
out.setWorkspaceId(in.getWorkspaceId());
out.setPreRequestScripts(in.getPreRequestScripts());
out.setTestAddress(in.getTestAddress());
out.setTestScripts(in.getTestScripts());
return out;
}

private FSPinMockRequestType buildPinMockRequest(FSAddItemsByAppAndInterfaceRequestType in,
String id) {
FSPinMockRequestType out = new FSPinMockRequestType();
out.setNodeType(FSInfoItem.CASE);
out.setRecordId(in.getNodeName());
out.setWorkspaceId(in.getWorkspaceId());
out.setInfoId(id);
return out;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.arextest.web.model.contract.contracts.filesystem;

import com.arextest.web.model.contract.contracts.common.KeyValuePairType;
import com.arextest.web.model.contract.contracts.common.ScriptBlockType;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.NotBlank;
import lombok.Data;

Expand All @@ -17,4 +21,18 @@ public class FSAddItemsByAppAndInterfaceRequestType {
private String interfaceName;
@NotBlank(message = "operationId cannot be empty")
private String operationId;
private String nodeName;

// for Case & Interface
private AddressType address;
private List<ScriptBlockType> preRequestScripts;
private List<ScriptBlockType> testScripts;
private BodyType body;
private List<KeyValuePairType> headers;
private List<KeyValuePairType> params;
private AuthType auth;
private AddressType testAddress;
private Set<String> labelIds;
private String description;

}