Skip to content
Snippets Groups Projects
Commit a64b569e authored by Jueun Park's avatar Jueun Park
Browse files

Added javadoc in JastAdd-Grammar partially

parent 0ea31623
Branches
No related tags found
1 merge request!6Resolve "check and fix random request generator"
Pipeline #13302 passed
......@@ -4,7 +4,20 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
aspect InferParameter{
/**
* Saves response data names generated by random requests.
* <p>This is an auxiliary method to distinguish saved dictionary values.</p>
* <p>(Future work: translate this to Map or Tuple).</p>
* @return first String part divided by <code>?</code>.
*/
syn String ParameterObject.dictName(String dict) = dict.substring(0, dict.indexOf("?"));
/**
* Saves response data values generated by random requests.
* <p>This is an auxiliary method to distinguish saved dictionary values.</p>
* <p>(Future work: translate this to Map or Tuple).</p>
* @return second String part divided by <code>?</code>.
*/
syn String ParameterObject.dictValue(String dict) = dict.substring(dict.indexOf("?")+1);
inh List<String> PathsObject.inferUrl(List<String> dict);
......
aspect RandomRequestGenerator{
syn String ParameterObject.randomPathParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
String pathPart = pathRef.substring(pathRef.indexOf("{"), pathRef.indexOf("}") + 1);
if (s.getType().equals("string"))
pathRef = pathRef.replace(pathPart, generateRandomString(s.getEList()));
else if (s.getType().equals("integer"))
pathRef = pathRef.replace(pathPart, generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10 // s.getMaximum() != null ? s.getMaximum().intValue() : -1
));
return pathRef;
}
syn String ParameterObject.randomQueryParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
if (s.getType().equals("string"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomString(s.getEList());
else if (s.getType().equals("integer"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
else if (s.getType().equals("array")) {
if (s.getI().getSchema().schemaObject().getType().equals("string")) {
for (EnumObj e : s.getI().getSchema().schemaObject().getEList())
pathRef = pathWithEnum(e, pathRef);
} else if (s.getI().getSchema().schemaObject().getType().equals("integer")) {
for (int i = 0; i < 5; i++)
pathRef = pathRef + "&" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
}
pathRef = pathRef.replaceFirst("&", "?");
}
return pathRef;
}
syn List<String> OpenAPIObject.generateRequests(){
/**
* Calls <code>generateUrl()</code> for all paths.
* @return The list of String representing the generated URLs.
*/ syn List<String> OpenAPIObject.generateRequests(){
List<String> urls = new ArrayList<>();
try {
for (PathsObject p : getPList())
......@@ -50,6 +15,11 @@ aspect RandomRequestGenerator{
return urls;
}
/**
* Checks if a path has the request types <code>GET</code> and/or <code>POST</code>, and calls <code>generateRandomUrl(String pathRef)</code>.
* <p>Afterwards, generated URLs are saved in a list.</p>
* @return The list of String representing the generated URLs.
*/
inh List<String> PathsObject.generateUrl();
eq OpenAPIObject.getP(int i).generateUrl(){
List<String> urls = new ArrayList<>();
......@@ -59,7 +29,7 @@ aspect RandomRequestGenerator{
if (p.hasG())
urls.add(p.getG().generateRandomUrl(path + getP(i).getRef()));
else if (p.hasPostOb())
if (p.hasPostOb())
urls.add(p.getPostOb().generateRandomUrl(path + getP(i).getRef()));
return urls;
......@@ -69,6 +39,11 @@ aspect RandomRequestGenerator{
}
}
/**
* Checks which parameter types the targeted GET request has (Path or Query) and calls corresponding random parameter generator.
* <p>Afterwards, generated parameters are written in the url.</p>
* @return An URL with the generated parameters in String.
*/
syn String Get.generateRandomUrl(String pathRef){
try {
for (ParameterOb o : getO().getPList()) {
......@@ -85,6 +60,12 @@ aspect RandomRequestGenerator{
return null;
}
}
/**
* Checks which parameter types the targeted POST request has (Path or Query) and calls corresponding random parameter generator.
* <p>Afterwards, generated parameters are written in the url.</p>
* @return An URL with the generated parameters in String.
*/
syn String Post.generateRandomUrl(String pathRef){
try {
for (ParameterOb o : getO().getPList()) {
......@@ -102,6 +83,44 @@ aspect RandomRequestGenerator{
}
}
syn String ParameterObject.randomPathParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
String pathPart = pathRef.substring(pathRef.indexOf("{"), pathRef.indexOf("}") + 1);
if (s.getType().equals("string"))
pathRef = pathRef.replace(pathPart, generateRandomString(s.getEList()));
else if (s.getType().equals("integer"))
pathRef = pathRef.replace(pathPart, generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10 // s.getMaximum() != null ? s.getMaximum().intValue() : -1
));
return pathRef;
}
syn String ParameterObject.randomQueryParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
if (s.getType().equals("string"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomString(s.getEList());
else if (s.getType().equals("integer"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
else if (s.getType().equals("array")) {
if (s.getI().getSchema().schemaObject().getType().equals("string")) {
for (EnumObj e : s.getI().getSchema().schemaObject().getEList())
pathRef = pathWithEnum(e, pathRef);
} else if (s.getI().getSchema().schemaObject().getType().equals("integer")) {
for (int i = 0; i < 5; i++)
pathRef = pathRef + "&" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
}
pathRef = pathRef.replaceFirst("&", "?");
}
return pathRef;
}
public String ParameterObject.generateRandomString(JastAddList<EnumObj> objs){
Random rand = new Random();
if (objs.getNumChild() != 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment