Skip to content

Commit

Permalink
added equals methods for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardo-boone committed May 1, 2024
2 parents 4faa98f + e8be970 commit 143a93d
Show file tree
Hide file tree
Showing 53 changed files with 256 additions and 141 deletions.
4 changes: 3 additions & 1 deletion src/main/java/edu/university/ecs/lab/CimetRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public static void main(String[] args) throws Exception {

// RUN IR MERGE
System.out.println("Starting IR Merge...");
String[] IRMergeArgs = {FullCimetUtils.pathToIR, FullCimetUtils.pathToDelta, configPath, compareBranch, compareCommit};
String[] IRMergeArgs = {
FullCimetUtils.pathToIR, FullCimetUtils.pathToDelta, configPath, compareBranch, compareCommit
};
IRMergeRunner.main(IRMergeArgs);

// RUN REPORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import javassist.NotFoundException;
import lombok.Getter;
import lombok.Setter;

/** Model to represent the microservice object in the configuration JSON file input */
@Getter
public class InputRepository {
/** The url of the git repository */
private String repoUrl;

// /** Commit number the service originated from */
// @Setter private String baseCommit;
// /** Commit number the service originated from */
// @Setter private String baseCommit;

/** The paths to each microservice TLD in the repository */
private String[] paths;
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/edu/university/ecs/lab/common/models/Annotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.university.ecs.lab.common.models;

import lombok.*;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;

/** Represents an annotation in Java */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Annotation implements JsonSerializable {
/** The name of the annotation * */
protected String annotationName;

/** The contents of the annotation * */
protected String contents;

@Override
public JsonObject toJsonObject() {
return createBuilder().build();
}

protected JsonObjectBuilder createBuilder() {
JsonObjectBuilder methodObjectBuilder = Json.createObjectBuilder();

methodObjectBuilder.add("annotationName", annotationName);
methodObjectBuilder.add("contents", contents);

return methodObjectBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public class Endpoint extends Method implements JsonSerializable {
* @param msId the microservice id that this endpoint belongs to
*/
public Endpoint(Method method, String url, String decorator, String httpMethod, String msId) {
super(method.getMethodName(), method.getParameterList(), method.getReturnType());
super(
method.getMethodName(),
method.getParameterList(),
method.getReturnType(),
method.getAnnotations());
setMsId(msId);
setUrl(url);
setDecorator(decorator);
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/edu/university/ecs/lab/common/models/JClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class JClass implements JsonSerializable {
@SerializedName("variables")
protected List<Field> fields;

/** Class level annotations * */
protected List<Annotation> annotations;

/** List of method invocations made from within this class e.g. obj.method() */
protected List<MethodCall> methodCalls;

Expand Down Expand Up @@ -81,16 +84,19 @@ public JClass(
ClassRole classRole,
List<Method> methods,
List<Field> fields,
List<Annotation> annotations,
List<MethodCall> methodCalls,
String msId) {
this.className = className;

setClassName(className);
setClassPath(classPath);
this.packageName = packageName;
this.classRole = classRole;
this.methods = methods;
this.fields = fields;
this.methodCalls = methodCalls;
this.msId = msId;
setPackageName(packageName);
setClassRole(classRole);
setMethods(methods);
setFields(fields);
setAnnotations(annotations);
setMethodCalls(methodCalls);
setMsId(msId);
}

/**
Expand All @@ -106,14 +112,15 @@ public JsonObject toJsonObject() {
protected JsonObjectBuilder createBuilder() {
JsonObjectBuilder jClassBuilder = Json.createObjectBuilder();

jClassBuilder.add("className", this.className);
jClassBuilder.add("classPath", this.classPath);
jClassBuilder.add("packageName", this.packageName);
jClassBuilder.add("classRole", this.classRole.name());
jClassBuilder.add("msId", msId);
jClassBuilder.add("methods", listToJsonArray(methods));
jClassBuilder.add("variables", listToJsonArray(fields));
jClassBuilder.add("methodCalls", listToJsonArray(methodCalls));
jClassBuilder.add("className", getClassName());
jClassBuilder.add("classPath", getClassPath());
jClassBuilder.add("packageName", getPackageName());
jClassBuilder.add("classRole", getClassRole().name());
jClassBuilder.add("msId", getMsId());
jClassBuilder.add("methods", listToJsonArray(getMethods()));
jClassBuilder.add("variables", listToJsonArray(getFields()));
jClassBuilder.add("methodCalls", listToJsonArray(getMethodCalls()));
jClassBuilder.add("annotations", listToJsonArray(getAnnotations()));

return jClassBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public JController(JClass jClass) {
jClass.getClassRole(),
jClass.getMethods(),
jClass.getFields(),
jClass.getAnnotations(),
jClass.getMethodCalls(),
jClass.getMsId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public JService(@NonNull JClass jClass) {
jClass.getClassRole(),
jClass.getMethods(),
jClass.getFields(),
jClass.getAnnotations(),
jClass.getMethodCalls(),
jClass.getMsId());
this.restCalls = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import java.util.List;

import static edu.university.ecs.lab.common.utils.ObjectToJsonUtils.listToJsonArray;

/** Represents a method declaration in Java. */
@AllArgsConstructor
Expand All @@ -26,6 +29,9 @@ public class Method implements JsonSerializable {
/** Java return type of the method */
protected String returnType;

/** Method definition level annotations * */
protected List<Annotation> annotations;

@Override
public JsonObject toJsonObject() {
return createBuilder().build();
Expand All @@ -37,6 +43,7 @@ protected JsonObjectBuilder createBuilder() {
methodObjectBuilder.add("methodName", methodName);
methodObjectBuilder.add("parameter", parameterList);
methodObjectBuilder.add("returnType", returnType);
methodObjectBuilder.add("annotations", listToJsonArray(annotations));

return methodObjectBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public class Microservice implements JsonSerializable {
@SerializedName("commitId")
private String commit;



/** Controller classes belonging to the microservice. */
private List<JController> controllers;

Expand Down
41 changes: 19 additions & 22 deletions src/main/java/edu/university/ecs/lab/common/models/RestCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class RestCall extends MethodCall {
*/
private String httpMethod;

/** The object holding payload for api call */
private String payloadObject;

/**
* Constructor for RestCall
*
Expand All @@ -52,20 +55,29 @@ public RestCall(
HttpMethod httpMethod,
String destEndpoint,
String destMsId,
String destFile) {
String destFile,
String payloadObject) {
super(methodName, objectName, calledFrom, msId);
this.httpMethod = httpMethod.name();
this.destEndpoint = destEndpoint;
this.destMsId = destMsId;
this.destFile = destFile;
this.payloadObject = payloadObject;
}

public JsonObject toJsonObject() {
// Get "restCall" methodCalls in service
JsonObjectBuilder restCallBuilder = super.createBuilder();

restCallBuilder.add("httpMethod", httpMethod);
restCallBuilder.add("dest-endpoint", destEndpoint);
restCallBuilder.add("dest-msId", destMsId);
restCallBuilder.add("dest-file", destFile);
restCallBuilder.add("payloadObject", payloadObject);

return restCallBuilder.build();
}

/**
* Set the destination of this call to the given controller. Does not change the destEndpoint as
* this is used to determine if this is called, and the controller endpoints may have parameters.
*
* @param destController The controller to set as the destination
*/
public void setDestination(JController destController) {
this.destMsId = destController.getMsId();
setDestFile(destController.getClassPath());
Expand Down Expand Up @@ -103,21 +115,6 @@ public String getId() {
return msId + "#" + calledFrom + "[" + httpMethod + "]" + "->" + destMsId + ":" + destEndpoint;
}

/**
* @return Converted JsonObject of RestCall object
*/
public JsonObject toJsonObject() {
// Get "restCall" methodCalls in service
JsonObjectBuilder restCallBuilder = super.createBuilder();

restCallBuilder.add("httpMethod", httpMethod);
restCallBuilder.add("dest-endpoint", destEndpoint);
restCallBuilder.add("dest-msId", destMsId);
restCallBuilder.add("dest-file", destFile);

return restCallBuilder.build();
}

/** Represents a call as an endpoint source. */
@Getter
public static class EndpointCall implements JsonSerializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public enum ErrorCodes {
"No microservices were detected in intermediate representation extraction. "
+ "Check your config file to make sure that the repositories are correct and"
+ "contain the correct structure for the microservices to be detected."),
/** Given file not found */
FILE_NOT_FOUND("File not found"),
;

/** The message associated with the error code (may be empty, never null) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import edu.university.ecs.lab.delta.models.SystemChange;
import edu.university.ecs.lab.delta.models.SystemChangeDTO;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

import static edu.university.ecs.lab.common.models.enums.ErrorCodes.*;

/** Utility class for parsing IR and delta files previously created. */
public class IRParserUtils {
/** Gson parser */
Expand All @@ -24,11 +27,19 @@ public class IRParserUtils {
* @return the parsed MsSystem object
* @throws IOException if an I/O error occurs
*/
public static MsSystem parseIRSystem(String irFileName) throws IOException {
Reader irReader = new FileReader(irFileName);

MsSystem msSystem = gson.fromJson(irReader, MsSystem.class);
irReader.close();
public static MsSystem parseIRSystem(String irFileName) {
MsSystem msSystem = null;
try {
Reader irReader = new FileReader(irFileName);
msSystem = gson.fromJson(irReader, MsSystem.class);
irReader.close();
} catch (FileNotFoundException e) {
System.err.println("IR File not Found: " + irFileName);
System.exit(FILE_NOT_FOUND.ordinal());
} catch (IOException e) {
System.err.println("Error reading IR file: " + irFileName);
System.exit(IR_EXTRACTION_FAIL.ordinal());
}

return msSystem;
}
Expand All @@ -40,11 +51,19 @@ public static MsSystem parseIRSystem(String irFileName) throws IOException {
* @return the parsed SystemChange object
* @throws IOException if an I/O error occurs
*/
public static SystemChange parseSystemChange(String deltaFileName) throws IOException {
Reader deltaReader = new FileReader(deltaFileName);

SystemChangeDTO systemChangeDto = gson.fromJson(deltaReader, SystemChangeDTO.class);
deltaReader.close();
public static SystemChange parseSystemChange(String deltaFileName) {
SystemChangeDTO systemChangeDto = null;
try {
Reader deltaReader = new FileReader(deltaFileName);
systemChangeDto = gson.fromJson(deltaReader, SystemChangeDTO.class);
deltaReader.close();
} catch (FileNotFoundException e) {
System.err.println("Delta file not Found: " + deltaFileName);
System.exit(FILE_NOT_FOUND.ordinal());
} catch (IOException e) {
System.err.println("Error reading delta file: " + deltaFileName);
System.exit(DELTA_EXTRACTION_FAIL.ordinal());
}

return systemChangeDto.toSystemChange();
}
Expand Down
Loading

0 comments on commit 143a93d

Please sign in to comment.