load tester beta
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.eactive.testmaster.client.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiRequestDTO {
|
||||
public class ApiRequestDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String id;
|
||||
|
||||
@@ -28,6 +31,8 @@ public class ApiRequestDTO {
|
||||
|
||||
private String postRequestScript;
|
||||
|
||||
private long sentBytes; //estimated size of the request
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -115,4 +120,12 @@ public class ApiRequestDTO {
|
||||
public void setPostRequestScript(String postRequestScript) {
|
||||
this.postRequestScript = postRequestScript;
|
||||
}
|
||||
|
||||
public long getSentBytes() {
|
||||
return sentBytes;
|
||||
}
|
||||
|
||||
public void setSentBytes(long sentBytes) {
|
||||
this.sentBytes = sentBytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
package com.eactive.testmaster.client.dto;
|
||||
|
||||
public class ApiRequestKeyValueDTO {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ApiRequestKeyValueDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
|
||||
public ApiRequestKeyValueDTO(boolean enabled, String key, String value) {
|
||||
this.enabled = enabled;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.eactive.testmaster.client.dto.internal;
|
||||
|
||||
public class ScenarioConnection {
|
||||
|
||||
private String node;
|
||||
private String input;
|
||||
private String output;
|
||||
|
||||
public String getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(String node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public String getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
public void setInput(String input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public String getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setOutput(String output) {
|
||||
this.output = output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.eactive.testmaster.client.dto.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ScenarioConnections {
|
||||
|
||||
private List<ScenarioConnection> connections;
|
||||
|
||||
public List<ScenarioConnection> getConnections() {
|
||||
return connections;
|
||||
}
|
||||
|
||||
public void setConnections(List<ScenarioConnection> connections) {
|
||||
this.connections = connections;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.eactive.testmaster.client.dto.internal;
|
||||
|
||||
import com.eactive.testmaster.client.dto.ApiRequestDTO;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScenarioNode {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private Map<String, String> data;
|
||||
|
||||
@JsonProperty("class")
|
||||
private String className;
|
||||
|
||||
private String html;
|
||||
private Map<String, ScenarioConnections> inputs;
|
||||
private Map<String, ScenarioConnections> outputs;
|
||||
|
||||
private List<ScenarioNode> connections;
|
||||
|
||||
private ApiRequestDTO apiRequest;
|
||||
|
||||
public ScenarioNode() {
|
||||
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, String> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getHtml() {
|
||||
return html;
|
||||
}
|
||||
|
||||
public void setHtml(String html) {
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
public Map<String, ScenarioConnections> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
public void setInputs(Map<String, ScenarioConnections> inputs) {
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
public Map<String, ScenarioConnections> getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
public void setOutputs(Map<String, ScenarioConnections> outputs) {
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
public List<ScenarioNode> getConnections() {
|
||||
return connections;
|
||||
}
|
||||
|
||||
public void setConnections(List<ScenarioNode> connections) {
|
||||
this.connections = connections;
|
||||
}
|
||||
|
||||
public void addNode(ScenarioNode node) {
|
||||
if (this.connections == null)
|
||||
this.connections = new ArrayList<>();
|
||||
|
||||
this.connections.add(node);
|
||||
}
|
||||
|
||||
public ApiRequestDTO getApiRequest() {
|
||||
return apiRequest;
|
||||
}
|
||||
|
||||
public void setApiRequest(ApiRequestDTO apiRequest) {
|
||||
this.apiRequest = apiRequest;
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,12 @@ import com.eactive.testmaster.client.dto.ApiCollectionDTO;
|
||||
import com.eactive.testmaster.client.dto.ApiRequestDTO;
|
||||
import com.eactive.testmaster.client.entity.ApiCollection;
|
||||
import com.eactive.testmaster.client.entity.ApiRequestInfo;
|
||||
import com.eactive.testmaster.client.repository.ApiRequestRepository;
|
||||
import com.eactive.testmaster.common.mapper.CommonMapper;
|
||||
import com.eactive.testmaster.server.mapper.ServerMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,17 +19,25 @@ import java.util.List;
|
||||
uses = {CommonMapper.class, ServerMapper.class},
|
||||
unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Component
|
||||
public interface ApiRequestMapper {
|
||||
ApiCollection map(ApiCollectionDTO dto);
|
||||
public abstract class ApiRequestMapper {
|
||||
|
||||
ApiRequestInfo map(ApiRequestDTO dto);
|
||||
@Autowired
|
||||
private ApiRequestRepository apiRequestRepository;
|
||||
|
||||
public abstract ApiCollection map(ApiCollectionDTO dto);
|
||||
|
||||
ApiRequestDTO map(ApiRequestInfo entity);
|
||||
public abstract ApiRequestInfo map(ApiRequestDTO dto);
|
||||
|
||||
public abstract ApiRequestDTO map(ApiRequestInfo entity);
|
||||
|
||||
public ApiRequestInfo map(String id) {
|
||||
if(id == null) {
|
||||
return null;
|
||||
}
|
||||
return apiRequestRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("No ApiRequest found for ID: " + id));
|
||||
}
|
||||
|
||||
List<ApiRequestInfo> mapApis(List<ApiRequestDTO> apis);
|
||||
public abstract List<ApiRequestInfo> mapApis(List<ApiRequestDTO> apis);
|
||||
|
||||
List<ApiCollectionDTO> mapCollections(List<ApiCollection> apis);
|
||||
public abstract List<ApiCollectionDTO> mapCollections(List<ApiCollection> apis);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.eactive.testmaster.client.mapper;
|
||||
|
||||
import com.eactive.testmaster.client.entity.ApiScenario;
|
||||
import com.eactive.testmaster.client.repository.ApiScenarioRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ApiScenarioHelper {
|
||||
|
||||
private final ApiScenarioRepository apiScenarioRepository;
|
||||
|
||||
public ApiScenarioHelper(ApiScenarioRepository apiScenarioRepository) {
|
||||
this.apiScenarioRepository = apiScenarioRepository;
|
||||
}
|
||||
|
||||
public ApiScenario getApiScenarioById(String id) {
|
||||
// Assuming the repository has a method findById that returns an Optional<ApiScenario>
|
||||
return apiScenarioRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("No ApiScenario found for ID: " + id));
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,39 @@ package com.eactive.testmaster.client.mapper;
|
||||
|
||||
import com.eactive.testmaster.client.dto.ApiScenarioDTO;
|
||||
import com.eactive.testmaster.client.entity.ApiScenario;
|
||||
import com.eactive.testmaster.client.repository.ApiScenarioRepository;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper(componentModel = "spring",
|
||||
unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Component
|
||||
public interface ApiScenarioMapper {
|
||||
public abstract class ApiScenarioMapper {
|
||||
|
||||
ApiScenario map(ApiScenarioDTO dto);
|
||||
@Autowired
|
||||
private ApiScenarioRepository apiScenarioRepository;
|
||||
|
||||
ApiScenarioDTO map(ApiScenario scenario);
|
||||
public abstract ApiScenario map(ApiScenarioDTO dto);
|
||||
|
||||
List<ApiScenarioDTO> toDtoList(List<ApiScenario> scenarios);
|
||||
public abstract ApiScenarioDTO map(ApiScenario scenario);
|
||||
|
||||
public ApiScenario map(String id) {
|
||||
if(id == null) {
|
||||
return null;
|
||||
}
|
||||
return apiScenarioRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("No ApiScenario found for ID: " + id));
|
||||
}
|
||||
|
||||
public String mapToId(ApiScenario scenario) {
|
||||
if(scenario == null) {
|
||||
return null;
|
||||
}
|
||||
return scenario.getId();
|
||||
}
|
||||
|
||||
public abstract List<ApiScenarioDTO> toDtoList(List<ApiScenario> scenarios);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,7 @@ public class HttpHandler extends SimpleChannelInboundHandler<FullHttpResponse> {
|
||||
public List<ApiRequestKeyValueDTO> convertHttpHeadersToList(HttpHeaders headers) {
|
||||
List<ApiRequestKeyValueDTO> headerList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : headers.entries()) {
|
||||
ApiRequestKeyValueDTO header = new ApiRequestKeyValueDTO();
|
||||
header.setKey(entry.getKey());
|
||||
header.setValue(entry.getValue());
|
||||
ApiRequestKeyValueDTO header = new ApiRequestKeyValueDTO(true, entry.getKey(), entry.getValue());
|
||||
headerList.add(header);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -29,12 +31,12 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service
|
||||
public class NettyApiClient {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NettyApiClient.class);
|
||||
|
||||
@Autowired
|
||||
ServerRepository serverRepository;
|
||||
|
||||
public CompletableFuture<ApiResponse> handleRequest(ApiRequestDTO originalRequest) {
|
||||
ApiRequestDTO apiRequest = originalRequest;
|
||||
public CompletableFuture<ApiResponse> handleRequest(ApiRequestDTO apiRequest) {
|
||||
Server server = serverRepository.findById(apiRequest.getServer()).orElseThrow(() -> new ServerNotFoundException("Server not found"));
|
||||
String host = server.getHostname();
|
||||
int port = server.getPort();
|
||||
@@ -92,6 +94,8 @@ public class NettyApiClient {
|
||||
request.headers().add(customHeaders);
|
||||
}
|
||||
|
||||
apiRequest.setSentBytes(request.toString().length());
|
||||
|
||||
ch.writeAndFlush(request);
|
||||
ch.closeFuture().sync();
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user