Skip to content

Commit

Permalink
Added Query Parameter Basic Mandatory Check
Browse files Browse the repository at this point in the history
  • Loading branch information
astroDEX2020 committed Jan 9, 2018
1 parent 49ab6c7 commit f719890
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.nio.file.StandardWatchEventKinds;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -26,6 +26,7 @@
import io.swagger.models.Operation;
import io.swagger.models.Response;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.swagger.parser.SwaggerParser;

/**
Expand All @@ -37,7 +38,8 @@ public class MockSwaggerUtil {

private static final Logger LOGGER = Logger.getLogger(MockSwaggerUtil.class.getName());

private static Map<String, Map<String, Object>> swaggerMap = new TreeMap<>();
private static Map<String, Map<String, Map<String, Response>>> swaggerResponseMap = new TreeMap<>();
private static Map<String, Map<String, List<Parameter>>> swaggerRequestMap = new TreeMap<>();
private static MockSwaggerUtil INSTANCE = null;
private String swaggerFolderPath = null;
private boolean onlySucessResponses = false;
Expand Down Expand Up @@ -93,7 +95,8 @@ public void run() {
* @param swaggerFolder
*/
private void process(String swaggerFolder) {
swaggerMap.clear();
swaggerResponseMap.clear();
swaggerRequestMap.clear();

File folder = new File(swaggerFolder);
if (folder.isDirectory()) {
Expand All @@ -106,7 +109,7 @@ private void process(String swaggerFolder) {
}
}

LOGGER.log(Level.INFO, "Map Object" + swaggerMap);
LOGGER.log(Level.INFO, "Map Object" + swaggerResponseMap);
}

/**
Expand Down Expand Up @@ -162,30 +165,55 @@ private void processSwaggerPath(String basePath, String path, io.swagger.models.
*/
private void populateSwaggerMap(String URI, String method, Operation operation) {
if (operation != null) {
Map<String, Object> responseObject = new HashMap<>();
Map<String, Map<String, Response>> responseObject = new HashMap<>();
responseObject.put(method, operation.getResponses());

if (swaggerMap.containsKey(URI)) {
responseObject.putAll(swaggerMap.get(URI));
if (swaggerResponseMap.containsKey(URI)) {
responseObject.putAll(swaggerResponseMap.get(URI));
}

swaggerMap.put(URI, responseObject);
swaggerResponseMap.put(URI, responseObject);

Map<String, List<Parameter>> requestObject = new HashMap<>();
requestObject.put(method, operation.getParameters());

if (swaggerRequestMap.containsKey(URI)) {
requestObject.putAll(swaggerRequestMap.get(URI));
}

swaggerRequestMap.put(URI, requestObject);
}
}

/**
*
* @param URI
* @param method
* @return
*/
public List<Parameter> getAllRequestParameters(String URI, String method){
for (Map.Entry<String, Map<String, List<Parameter>>> entrySet : swaggerRequestMap.entrySet()) {
if (isURIMatch(URI, entrySet.getKey())) {
Map<String, List<Parameter>> requestObject = entrySet.getValue();
return requestObject.get(method);
}
}

return null;
}

/**
*
* @param URI
* @param method
* @return
*/
@SuppressWarnings("unchecked")
public MockResponse getRandomResponse(String URI, String method) {
for (Map.Entry<String, Map<String, Object>> entrySet : swaggerMap.entrySet()) {
for (Map.Entry<String, Map<String, Map<String, Response>>> entrySet : swaggerResponseMap.entrySet()) {

if (isURIMatch(URI, entrySet.getKey())) {
Map<String, Object> responseObject = entrySet.getValue();
Map<String, Response> responses = (Map<String, Response>) responseObject.get(method);
Map<String, Map<String, Response>> responseObject = entrySet.getValue();
Map<String, Response> responses = responseObject.get(method);

if (responses != null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public class MockExceptionResponse {
private String code;
private String link;
private String message;
private String rel;
private String traceid;


public MockExceptionResponse() {
super();
}
Expand Down Expand Up @@ -52,36 +50,13 @@ public String getMessage() {
public void setMessage(String message) {
this.message = message;
}
/**
* @return the rel
*/
public String getRel() {
return rel;
}
/**
* @param rel the rel to set
*/
public void setRel(String rel) {
this.rel = rel;
}
/**
* @return the traceid
*/
public String getTraceid() {
return traceid;
}
/**
* @param traceid the traceid to set
*/
public void setTraceid(String traceid) {
this.traceid = traceid;
}


/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "MockException [code=" + code + ", link=" + link + ", message=" + message + ", rel=" + rel + ", traceid="
+ traceid + "]";
return "MockException [code=" + code + ", link=" + link + ", message=" + message + "]";
}
}
}
Loading

0 comments on commit f719890

Please sign in to comment.