기본 골격
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.eactive.httpmockserver.api.dto;
|
||||
|
||||
public class MockConditionDTO {
|
||||
private String type;
|
||||
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.eactive.httpmockserver.api.dto;
|
||||
|
||||
public class MockHeaderDTO {
|
||||
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.eactive.httpmockserver.api.dto;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MockRequest {
|
||||
|
||||
public static Map<String, String> parseQueryString(HttpServletRequest request) {
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
String queryString = request.getQueryString();
|
||||
if (queryString != null) {
|
||||
String[] queryParamsArr = queryString.split("&");
|
||||
for (String queryParam : queryParamsArr) {
|
||||
String[] pair = queryParam.split("=");
|
||||
String key = pair[0];
|
||||
String value = "";
|
||||
if (pair.length > 1) {
|
||||
value = pair[1];
|
||||
}
|
||||
queryParams.put(key, value);
|
||||
}
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
public MockRequest(HttpServletRequest request) {
|
||||
this.method = request.getMethod();
|
||||
this.uri = request.getRequestURI();
|
||||
this.headers = Collections.list(request.getHeaderNames()).stream()
|
||||
.collect(Collectors.toMap(name -> name, request::getHeader));
|
||||
|
||||
this.params = parseQueryString(request);
|
||||
|
||||
try {
|
||||
this.body = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String uri;
|
||||
private String method;
|
||||
private String body;
|
||||
|
||||
private Map<String, String> headers;
|
||||
|
||||
private Map<String, String> params;
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public String getHeader(String key) {
|
||||
return this.headers.get(key);
|
||||
}
|
||||
|
||||
public String getParam(String key) {
|
||||
return this.params.get(key);
|
||||
}
|
||||
|
||||
public Map<String, String> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.eactive.httpmockserver.api.dto;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MockResponseDTO {
|
||||
|
||||
@Min(100)
|
||||
private int statusCode = 100;
|
||||
|
||||
private List<MockHeaderDTO> headers = new ArrayList<>();
|
||||
|
||||
private String body;
|
||||
|
||||
private long delay = 0; //millisecond
|
||||
|
||||
|
||||
private List<MockConditionDTO> conditions;
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public List<MockHeaderDTO> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(List<MockHeaderDTO> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public List<MockConditionDTO> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void setConditions(List<MockConditionDTO> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.eactive.httpmockserver.api.dto;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MockRouteDTO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@NotEmpty
|
||||
private String method;
|
||||
|
||||
@NotEmpty
|
||||
private String pathPattern;
|
||||
|
||||
@NotEmpty
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
@Size(min = 1, message = "Response must have at least one item")
|
||||
private List<MockResponseDTO> responses = new ArrayList<>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getPathPattern() {
|
||||
return pathPattern;
|
||||
}
|
||||
|
||||
public void setPathPattern(String pathPattern) {
|
||||
this.pathPattern = pathPattern;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<MockResponseDTO> getResponses() {
|
||||
return responses;
|
||||
}
|
||||
|
||||
public void setResponses(List<MockResponseDTO> responses) {
|
||||
this.responses = responses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.eactive.httpmockserver.api.dto;
|
||||
|
||||
import com.eactive.httpmockserver.api.entity.MockRoute;
|
||||
import com.eactive.httpmockserver.common.search.BaseSearch;
|
||||
import com.eactive.httpmockserver.common.search.ColumnSearchModel;
|
||||
import com.eactive.httpmockserver.common.search.SearchCondition;
|
||||
import com.eactive.httpmockserver.common.search.SearchModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MockRouteSearch implements BaseSearch<MockRoute> {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> checkedIdForDel;
|
||||
|
||||
@Override
|
||||
public List<SearchModel> buildSearchCondition() {
|
||||
List<SearchModel> models = new ArrayList<>();
|
||||
models.add(new ColumnSearchModel("name", SearchCondition.LIKE, name));
|
||||
return models;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getCheckedIdForDel() {
|
||||
return checkedIdForDel;
|
||||
}
|
||||
|
||||
public void setCheckedIdForDel(List<String> checkedIdForDel) {
|
||||
this.checkedIdForDel = checkedIdForDel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user