Commit 64458285 authored by Jueun Park's avatar Jueun Park
Browse files

Update attributes

parent 405a0c39
......@@ -85,33 +85,33 @@ public class OperationObject extends ASTNode<ASTNode> implements Cloneable {
}
/**
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:126
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:114
*/
public void writeDictionary(SchemaOb schema,String resp)throws Exception{
ObjectMapper mapper = new ObjectMapper();
JsonNode respNode = mapper.readTree(resp);
ObjectMapper mapper=new ObjectMapper();
JsonNode respNode=mapper.readTree(resp);
String value;
if (schema instanceof SchemaReference) {
for (PropertyItem p : schema.schemaObject().getPropertyItems()) {
String infName = p.writePropertyName(schema, p);
value = p.writePropertyValue(respNode, p);
if(schema instanceof SchemaReference){
for(PropertyItem p:schema.schemaObject().getPropertyItems()){
String infName=p.writePropertyName(schema,p);
value=p.writePropertyValue(respNode,p);
root().addInferredParameter(new InferredParameter(infName + "?" + value));
root().addInferredParameter(new InferredParameter(p.getName() + "?" + value));
root().addInferredParameter(new InferredParameter(infName+"?"+value));
root().addInferredParameter(new InferredParameter(p.getName()+"?"+value));
}
} else {
for (PropertyItem p : schema.schemaObject().getPropertyItems()) {
value = p.writePropertyValue(respNode, p);
}else{
for(PropertyItem p:schema.schemaObject().getPropertyItems()){
value=p.writePropertyValue(respNode,p);
root().addInferredParameter(new InferredParameter(p.getName() + "?" + respNode.get(p.getName()).textValue()));
root().addInferredParameter(new InferredParameter(p.getName()+"?"+respNode.get(p.getName()).textValue()));
}
}
}
/**
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:149
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:137
*/
public void writeDictionaryWithArray(SchemaOb schema,String resp)throws Exception{
ObjectMapper mapper=new ObjectMapper();
......
......@@ -828,6 +828,82 @@ protected java.util.Set composeParameter_ParameterOb_Map_Object__ASTNode__visite
}
}
/** @apilevel internal */
protected java.util.Set addinfPathParameters_String_List_String__visited;
/**
* @attribute syn
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:80
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:80")
public List<String> addinfPathParameters(String pathRef, List<String> paths) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef);
_parameters.add(paths);
if (addinfPathParameters_String_List_String__visited == null) addinfPathParameters_String_List_String__visited = new java.util.HashSet(4);
if (addinfPathParameters_String_List_String__visited.contains(_parameters)) {
throw new RuntimeException("Circular definition of attribute ParameterObject.addinfPathParameters(String,List_String_).");
}
addinfPathParameters_String_List_String__visited.add(_parameters);
try {
for(InferredParameter i:root().collectInferredParameters()){
// get the field which must be modified
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1);
// case insensitive comparison of parameter name and name of inferred parameters
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
return paths;
}
finally {
addinfPathParameters_String_List_String__visited.remove(_parameters);
}
}
/** @apilevel internal */
protected java.util.Set addinfQueryParameters_String_List_String__visited;
/**
* @attribute syn
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:92
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:92")
public List<String> addinfQueryParameters(String pathRef, List<String> paths) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef);
_parameters.add(paths);
if (addinfQueryParameters_String_List_String__visited == null) addinfQueryParameters_String_List_String__visited = new java.util.HashSet(4);
if (addinfQueryParameters_String_List_String__visited.contains(_parameters)) {
throw new RuntimeException("Circular definition of attribute ParameterObject.addinfQueryParameters(String,List_String_).");
}
addinfQueryParameters_String_List_String__visited.add(_parameters);
try {
SchemaObject s=getSchemaOb().schemaObject();
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+getName()+"="+i.value());
}
}
return paths;
}
finally {
addinfQueryParameters_String_List_String__visited.remove(_parameters);
}
}
/** @apilevel internal */
protected java.util.Set randomPathParameter_String_visited;
/**
* @attribute syn
......
......@@ -29,7 +29,7 @@ import java.util.stream.IntStream;
public class Post extends ASTNode<ASTNode> implements Cloneable {
/**
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:184
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:172
*/
public void connectPOST(String path){
try{URL url=new URL(path);
......@@ -219,10 +219,10 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited;
/**
* @attribute syn
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:82
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:59
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:82")
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:59")
public String inferRandomUrl(String pathRef, OperationObject operationObject) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef);
......@@ -240,35 +240,12 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited;
SchemaObject s=p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'.
if(p.getIn().equals("path")){
for(InferredParameter i:root().collectInferredParameters()){
// get the field which must be modified
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1);
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
} // check if the parameter is in type 'query'
else if(p.getIn().equals("query")){
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value());
}
}
}
if(p.getIn().equals("path"))
paths=p.addinfPathParameters(pathRef,paths);
// check if the parameter is in type 'query'
else if(p.getIn().equals("query"))
paths=p.addinfQueryParameters(pathRef,paths);
System.out.println(paths.size()+" Paths are inferred.");
}
for(String path:paths)
......
......@@ -225,7 +225,7 @@ protected java.util.Set writePropertyName_SchemaOb_PropertyItem_visited;
throw new RuntimeException("Circular definition of attribute PropertyItem.writePropertyName(SchemaOb,PropertyItem).");
}
writePropertyName_SchemaOb_PropertyItem_visited.add(_parameters);
String writePropertyName_SchemaOb_PropertyItem_value = ((SchemaReference) schema).getRef().substring(((SchemaReference) schema).getRef().lastIndexOf("/") + 1) + p.getName();
String writePropertyName_SchemaOb_PropertyItem_value = ((SchemaReference)schema).getRef().substring(((SchemaReference)schema).getRef().lastIndexOf("/")+1)+p.getName();
writePropertyName_SchemaOb_PropertyItem_visited.remove(_parameters);
return writePropertyName_SchemaOb_PropertyItem_value;
}
......@@ -247,7 +247,7 @@ protected java.util.Set writePropertyValue_JsonNode_PropertyItem_visited;
throw new RuntimeException("Circular definition of attribute PropertyItem.writePropertyValue(JsonNode,PropertyItem).");
}
writePropertyValue_JsonNode_PropertyItem_visited.add(_parameters);
String writePropertyValue_JsonNode_PropertyItem_value = node.get(p.getName()).toString().startsWith("\"") && node.get(p.getName()).toString().endsWith("\"") ? node.get(p.getName()).toString().substring(1, node.get(p.getName()).toString().length() - 1) : node.get(p.getName()).toString();
String writePropertyValue_JsonNode_PropertyItem_value = node.get(p.getName()).toString().startsWith("\"")&&node.get(p.getName()).toString().endsWith("\"")?node.get(p.getName()).toString().substring(1,node.get(p.getName()).toString().length()-1):node.get(p.getName()).toString();
writePropertyValue_JsonNode_PropertyItem_visited.remove(_parameters);
return writePropertyValue_JsonNode_PropertyItem_value;
}
......
......@@ -3,13 +3,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
aspect InferParameter{
syn String PropertyItem.writePropertyName(SchemaOb schema, PropertyItem p) = ((SchemaReference) schema).getRef().substring(((SchemaReference) schema).getRef().lastIndexOf("/") + 1) + p.getName();
syn String PropertyItem.writePropertyName(SchemaOb schema,PropertyItem p)=((SchemaReference)schema).getRef().substring(((SchemaReference)schema).getRef().lastIndexOf("/")+1)+p.getName();
syn String PropertyItem.writePropertyValue(JsonNode node, PropertyItem p) = node.get(p.getName()).toString().startsWith("\"") && node.get(p.getName()).toString().endsWith("\"") ? node.get(p.getName()).toString().substring(1, node.get(p.getName()).toString().length() - 1) : node.get(p.getName()).toString();
syn String PropertyItem.writePropertyValue(JsonNode node,PropertyItem p)=node.get(p.getName()).toString().startsWith("\"")&&node.get(p.getName()).toString().endsWith("\"")?node.get(p.getName()).toString().substring(1,node.get(p.getName()).toString().length()-1):node.get(p.getName()).toString();
coll Set<InferredParameter> OpenAPIObject.collectInferredParameters()[new HashSet<InferredParameter>()];
InferredParameter contributes this
to OpenAPIObject.collectInferredParameters();
syn String InferredParameter.name()=getParameter().substring(0,getParameter().indexOf("?"));
syn String InferredParameter.value()=getParameter().substring(getParameter().indexOf("?")+1);
......@@ -19,20 +20,20 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti
generateRequests();
for(PathsObject p:getPathsObjects())
p.inferUrl(urls);
p.inferUrl();
}
inh Set<String> PathsObject.inferUrl(Set<String> urls);
eq OpenAPIObject.getPathsObject(int i).inferUrl(Set<String> urls){
inh boolean PathsObject.inferUrl();
eq OpenAPIObject.getPathsObject(int i).inferUrl(){
PathItemObject p=getPathsObject(i).getPathItemObject();
String path=getServerObject(0).getUrl();
if(p.hasGet())
urls.add(p.getGet().inferRandomUrl(path+getPathsObject(i).getRef(),p.getGet().getOperationObject()));
p.getGet().inferRandomUrl(path+getPathsObject(i).getRef(),p.getGet().getOperationObject());
else if(p.hasPost())
urls.add(p.getPost().inferRandomUrl(path+getPathsObject(i).getRef(),p.getPost().getOperationObject()));
p.getPost().inferRandomUrl(path+getPathsObject(i).getRef(),p.getPost().getOperationObject());
return urls;
return true;
}
syn String Get.inferRandomUrl(String pathRef,OperationObject operationObject){
......@@ -43,35 +44,12 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti
SchemaObject s=p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'.
if(p.getIn().equals("path")){
for(InferredParameter i:root().collectInferredParameters()){
// get the field which must be modified
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1);
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
} // check if the parameter is in type 'query'
else if(p.getIn().equals("query")){
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value());
}
}
}
if(p.getIn().equals("path"))
paths=p.addinfPathParameters(pathRef,paths);
// check if the parameter is in type 'query'
else if(p.getIn().equals("query"))
paths=p.addinfQueryParameters(pathRef,paths);
System.out.println(paths.size()+" Paths are inferred.");
}
for(String path:paths)
......@@ -87,60 +65,71 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti
SchemaObject s=p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'.
if(p.getIn().equals("path")){
if(p.getIn().equals("path"))
paths=p.addinfPathParameters(pathRef,paths);
// check if the parameter is in type 'query'
else if(p.getIn().equals("query"))
paths=p.addinfQueryParameters(pathRef,paths);
System.out.println(paths.size()+" Paths are inferred.");
}
for(String path:paths)
connectPOST(path);
return pathRef;
}
syn List<String> ParameterObject.addinfPathParameters(String pathRef,List<String> paths){
for(InferredParameter i:root().collectInferredParameters()){
// get the field which must be modified
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1);
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
} // check if the parameter is in type 'query'
else if(p.getIn().equals("query")){
return paths;
}
syn List<String> ParameterObject.addinfQueryParameters(String pathRef,List<String> paths){
SchemaObject s=getSchemaOb().schemaObject();
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value();
pathRef=pathRef+"&"+getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value());
}
paths.add(pathRef+"?"+getName()+"="+i.value());
}
}
System.out.println(paths.size()+" Paths are inferred.");
}
for(String path:paths)
connectPOST(path);
return pathRef;
return paths;
}
public void OperationObject.writeDictionary(SchemaOb schema,String resp)throws Exception{
ObjectMapper mapper = new ObjectMapper();
JsonNode respNode = mapper.readTree(resp);
ObjectMapper mapper=new ObjectMapper();
JsonNode respNode=mapper.readTree(resp);
String value;
if (schema instanceof SchemaReference) {
for (PropertyItem p : schema.schemaObject().getPropertyItems()) {
String infName = p.writePropertyName(schema, p);
value = p.writePropertyValue(respNode, p);
if(schema instanceof SchemaReference){
for(PropertyItem p:schema.schemaObject().getPropertyItems()){
String infName=p.writePropertyName(schema,p);
value=p.writePropertyValue(respNode,p);
root().addInferredParameter(new InferredParameter(infName + "?" + value));
root().addInferredParameter(new InferredParameter(p.getName() + "?" + value));
root().addInferredParameter(new InferredParameter(infName+"?"+value));
root().addInferredParameter(new InferredParameter(p.getName()+"?"+value));
}
} else {
for (PropertyItem p : schema.schemaObject().getPropertyItems()) {
value = p.writePropertyValue(respNode, p);
}else{
for(PropertyItem p:schema.schemaObject().getPropertyItems()){
value=p.writePropertyValue(respNode,p);
root().addInferredParameter(new InferredParameter(p.getName() + "?" + respNode.get(p.getName()).textValue()));
root().addInferredParameter(new InferredParameter(p.getName()+"?"+respNode.get(p.getName()).textValue()));
}
}
......
......@@ -50,9 +50,12 @@ aspect RandomRequestGenerator{
return pathRef;
}
public void OpenAPIObject.generateRequests()throws Exception{
syn boolean OpenAPIObject.generateRequests(){
try{
for(PathsObject p:getPathsObjects())
p.generateUrl();
p.generateUrl();} catch (Exception e) {
return false;
}
}
inh boolean PathsObject.generateUrl();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment