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 all commits
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
@@ -0,0 +1,13 @@
package com.arextest.web.api.service.beans.auto;

import org.springframework.context.annotation.Configuration;

/**
* @author wildeslam.
* @create 2024/6/27 20:20
*/
@Configuration
public class SystemConfigAutoConfiguration {


}
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 @@ -98,6 +96,7 @@
import com.arextest.web.model.mapper.FSFolderMapper;
import com.arextest.web.model.mapper.FSInterfaceMapper;
import com.arextest.web.model.mapper.FSNodeMapper;
import com.arextest.web.model.mapper.FSRequestMapper;
import com.arextest.web.model.mapper.FSTreeMapper;
import com.arextest.web.model.mapper.UserWorkspaceMapper;
import com.arextest.web.model.mapper.WorkspaceMapper;
Expand Down Expand Up @@ -805,7 +804,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 +815,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 +837,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 +853,50 @@ public List<String> addItemsByAppAndInterface(FSAddItemsByAppAndInterfaceRequest
request.getInterfaceName());
return null;
}
interfaceNode = fileSystemUtils.deepFindByInfoId(addInterface.getRight().getRoots(),
addInterface.getLeft());
defaultPath[1] = addInterface.getLeft();
} else {
defaultPath[1] = interfaceNode.getInfoId();
}

// add case
FSAddItemRequestType addCaseRequest = new FSAddItemRequestType();
addCaseRequest.setId(treeDto.getId());
addCaseRequest.setNodeName(request.getNodeName());
addCaseRequest.setNodeType(FSInfoItem.CASE);
addCaseRequest.setParentPath(Arrays.asList(defaultPath[0], defaultPath[1]));
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();

path.addAll(Arrays.asList(defaultPath));

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

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

//pin case
FSPinMockRequestType pinMockRequest = FSRequestMapper.INSTANCE.buildPinMockRequest(request);
pinMockRequest.setInfoId(defaultPath[2]);
pinMockRequest.setNodeType(FSInfoItem.CASE);
pinMock(pinMockRequest);
}


// add the related information about the replay interface to the manual interface
this.addReplayInfoToManual(request.getOperationId(), path);
return path;
Expand Down
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;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.arextest.web.model.mapper;

import com.arextest.web.model.contract.contracts.filesystem.FSAddItemsByAppAndInterfaceRequestType;
import com.arextest.web.model.contract.contracts.filesystem.FSPinMockRequestType;
import com.arextest.web.model.contract.contracts.filesystem.FSSaveCaseRequestType;
import com.arextest.web.model.contract.contracts.filesystem.FSSaveInterfaceRequestType;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
* @author wildeslam.
* @create 2024/6/28 11:36
*/
@Mapper
public interface FSRequestMapper {

FSRequestMapper INSTANCE = Mappers.getMapper(FSRequestMapper.class);

FSSaveInterfaceRequestType buildSaveInterfaceRequest(
FSAddItemsByAppAndInterfaceRequestType request);

FSSaveCaseRequestType buildSaveCaseRequest(FSAddItemsByAppAndInterfaceRequestType request);

@Mapping(target = "recordId", source = "nodeName")
FSPinMockRequestType buildPinMockRequest(FSAddItemsByAppAndInterfaceRequestType request);

}