microservices, String fileName) {
MicroserviceSystem microserviceSystem = new MicroserviceSystem(config.getSystemName(), commitID, microservices, new HashSet<>());
- JsonReadWriteUtils.writeToJSON("./output/" + fileName, microserviceSystem.toJsonObject());
+ JsonReadWriteUtils.writeToJSON(fileName, microserviceSystem.toJsonObject());
LoggerManager.info(() -> "Successfully extracted IR at " + commitID);
}
diff --git a/src/main/java/edu/university/ecs/lab/intermediate/merge/IRMergeRunner.java b/src/main/java/edu/university/ecs/lab/intermediate/merge/IRMergeRunner.java
index 6059520a..5ab74354 100644
--- a/src/main/java/edu/university/ecs/lab/intermediate/merge/IRMergeRunner.java
+++ b/src/main/java/edu/university/ecs/lab/intermediate/merge/IRMergeRunner.java
@@ -25,13 +25,13 @@ public static void main(String[] args) throws IOException {
String[] finalArgs = args;
LoggerManager.info(() -> "IRMergeRunner starting... args: " + Arrays.toString(finalArgs));
- if (args.length != 3) {
+ if (args.length != 4) {
Error.reportAndExit(Error.INVALID_ARGS, Optional.empty());
}
Config config = ConfigUtil.readConfig(args[0]);
- MergeService mergeService = new MergeService(args[0], args[1], args[2]);
+ MergeService mergeService = new MergeService(args[0], args[1], args[2], args[3]);
//mergeService.generateMergeIR();
}
diff --git a/src/main/java/edu/university/ecs/lab/intermediate/merge/services/MergeService.java b/src/main/java/edu/university/ecs/lab/intermediate/merge/services/MergeService.java
index 6b9cb884..2b58b869 100644
--- a/src/main/java/edu/university/ecs/lab/intermediate/merge/services/MergeService.java
+++ b/src/main/java/edu/university/ecs/lab/intermediate/merge/services/MergeService.java
@@ -23,15 +23,18 @@ public class MergeService {
private final Config config;
private final MicroserviceSystem microserviceSystem;
private final SystemChange systemChange;
+ private final String outputPath;
// TODO handle exceptions here
public MergeService(
String intermediatePath,
String deltaPath,
- String configPath) {
+ String configPath,
+ String outputPath) {
this.config = ConfigUtil.readConfig(configPath);
this.microserviceSystem = JsonReadWriteUtils.readFromJSON(Path.of(intermediatePath).toAbsolutePath().toString(), MicroserviceSystem.class);
this.systemChange = JsonReadWriteUtils.readFromJSON(Path.of(deltaPath).toAbsolutePath().toString(), SystemChange.class);
+ this.outputPath = outputPath.isEmpty() ? "./NewIR.json" : outputPath;
}
/**
@@ -42,8 +45,7 @@ public void generateMergeIR(String newCommitID) {
// If no changes are present we will write back out same IR
if (Objects.isNull(systemChange.getChanges())) {
LoggerManager.debug(() -> "No changes found at " + systemChange.getOldCommit() + " -> " + systemChange.getNewCommit());
- String filePath = "./output/IR_" + newCommitID + ".json";
- JsonReadWriteUtils.writeToJSON(filePath, microserviceSystem);
+ JsonReadWriteUtils.writeToJSON(outputPath, microserviceSystem);
return;
}
@@ -70,8 +72,7 @@ public void generateMergeIR(String newCommitID) {
microserviceSystem.setCommitID(systemChange.getNewCommit());
LoggerManager.info(() -> "Merged to new IR at " + systemChange.getNewCommit());
- String filePath = "./output/IR_" + newCommitID + ".json";
- JsonReadWriteUtils.writeToJSON(filePath, microserviceSystem);
+ JsonReadWriteUtils.writeToJSON(outputPath, microserviceSystem);
}
diff --git a/src/main/java/edu/university/ecs/lab/intermediate/utils/StringParserUtils.java b/src/main/java/edu/university/ecs/lab/intermediate/utils/StringParserUtils.java
index d7958bce..e3bbaa3f 100644
--- a/src/main/java/edu/university/ecs/lab/intermediate/utils/StringParserUtils.java
+++ b/src/main/java/edu/university/ecs/lab/intermediate/utils/StringParserUtils.java
@@ -28,39 +28,6 @@ public static String removeOuterQuotations(String s) {
return s;
}
-// /**
-// * Merge the given class and method paths into a single path.
-// *
-// * ex: /abc/def and ghi/jkl --> abc/def/ghi/jkl
-// *
-// * @param classPath the class base (api) path
-// * @param methodPath the method (api) path
-// * @return the merged path
-// */
-// public static String mergePaths(String classPath, String methodPath) {
-// if (classPath.startsWith("/")) classPath = classPath.substring(1);
-// if (methodPath.startsWith("/")) methodPath = methodPath.substring(1);
-//
-// String path =
-// FilenameUtils.normalizeNoEndSeparator(FilenameUtils.concat(classPath, methodPath), true);
-// if (!path.startsWith("/")) path = "/" + path;
-//
-// return path;
-// }
-//
-// /**
-// * Find the package name in the given compilation unit.
-// *
-// * @param cu the compilation unit
-// * @return the package name else null if not found
-// */
-// public static String findPackage(CompilationUnit cu) {
-// for (PackageDeclaration pd : cu.findAll(PackageDeclaration.class)) {
-// return pd.getNameAsString();
-// }
-// return null;
-// }
-
/**
* Simplifies all path arguments to {?}.
*
diff --git a/src/test/java/integration/IRComparisonTest.java b/src/test/java/integration/IRComparisonTest.java
index b8345fec..7667ee18 100644
--- a/src/test/java/integration/IRComparisonTest.java
+++ b/src/test/java/integration/IRComparisonTest.java
@@ -1,32 +1,35 @@
-//package integration;
-//
-//import edu.university.ecs.lab.common.models.ir.*;
-//import edu.university.ecs.lab.common.services.GitService;
-//import edu.university.ecs.lab.common.utils.FileUtils;
-//import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
-//import edu.university.ecs.lab.delta.services.DeltaExtractionService;
-//import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
-//import edu.university.ecs.lab.intermediate.merge.services.MergeService;
-//import org.eclipse.jgit.revwalk.RevCommit;
-//import org.junit.jupiter.api.Assertions;
-//import org.junit.jupiter.api.BeforeAll;
-//import org.junit.jupiter.api.Test;
-//
-//import java.io.IOException;
-//import java.nio.file.Files;
-//import java.nio.file.Paths;
-//import java.nio.file.StandardCopyOption;
-//import java.util.*;
-//
-//import static integration.Constants.*;
-//
-//class IRComparisonTest {
-// private static IRExtractionService irExtractionService;
-// private static DeltaExtractionService deltaExtractionService;
-// private static List list;
-// private static GitService gitService;
-//
-//
+package integration;
+
+import edu.university.ecs.lab.common.models.ir.*;
+import edu.university.ecs.lab.common.services.GitService;
+import edu.university.ecs.lab.common.utils.FileUtils;
+import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
+import edu.university.ecs.lab.delta.services.DeltaExtractionService;
+import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
+import edu.university.ecs.lab.intermediate.merge.services.MergeService;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Ignore;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.*;
+
+import static integration.Constants.*;
+
+
+@Ignore
+class IRComparisonTest {
+ private static IRExtractionService irExtractionService;
+ private static DeltaExtractionService deltaExtractionService;
+ private static List list;
+ private static GitService gitService;
+
+
// @BeforeAll
// public static void setUp() {
// FileUtils.makeDirs();
@@ -36,93 +39,93 @@
//
// irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.of(list.get(0).toString().split(" ")[1]));
//
-// irExtractionService.generateIR(OLD_IR_NAME);
+// irExtractionService.generateIR("./output/OldIR.json");
// }
-//
+
// @Test
-// void testComparison() {
-//
-// // Loop through commit history and create delta, merge, etc...
-// for (int i = 0; i < list.size() - 1; i++) {
-// String commitIdOld = list.get(i).toString().split(" ")[1];
-// String commitIdNew = list.get(i + 1).toString().split(" ")[1];
-//
-// // Extract changes from one commit to the other
-// deltaExtractionService = new DeltaExtractionService(TEST_CONFIG_PATH, OLD_IR_PATH, commitIdOld, commitIdNew);
-// deltaExtractionService.generateDelta();
-//
-// // Merge Delta changes to old IR to create new IR representing new commit changes
-// MergeService mergeService = new MergeService(OLD_IR_PATH, DELTA_PATH, TEST_CONFIG_PATH);
-// mergeService.generateMergeIR(commitIdNew);
-//
-// if(i < list.size() - 2) {
-// try {
-// Files.move(Paths.get(NEW_IR_PATH), Paths.get(OLD_IR_PATH), StandardCopyOption.REPLACE_EXISTING);
-// } catch (IOException e) {
-// e.printStackTrace();
+ void testComparison() {
+
+ // Loop through commit history and create delta, merge, etc...
+ for (int i = 0; i < list.size() - 1; i++) {
+ String commitIdOld = list.get(i).toString().split(" ")[1];
+ String commitIdNew = list.get(i + 1).toString().split(" ")[1];
+
+ // Extract changes from one commit to the other
+ deltaExtractionService = new DeltaExtractionService(TEST_CONFIG_PATH, "./output/Delta.json", commitIdOld, commitIdNew);
+ deltaExtractionService.generateDelta();
+
+ // Merge Delta changes to old IR to create new IR representing new commit changes
+ MergeService mergeService = new MergeService("./output/OldIR.json", "./output/Delta.json", TEST_CONFIG_PATH, "./output/NewIR.json");
+ mergeService.generateMergeIR(commitIdNew);
+
+ if(i < list.size() - 2) {
+ try {
+ Files.move(Paths.get("./output/NewIR.json"), Paths.get("./output/OldIR.json"), StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // Create IR of last commit
+ irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.of(list.get(list.size() - 1).toString().split(" ")[1]));
+ irExtractionService.generateIR("./output/TestIR.json");
+
+ // Compare two IR's for equivalence
+ MicroserviceSystem microserviceSystem1 = JsonReadWriteUtils.readFromJSON("./output/NewIR.json", MicroserviceSystem.class);
+ MicroserviceSystem microserviceSystem2 = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class);
+
+ microserviceSystem1.setOrphans(new HashSet<>());
+ microserviceSystem2.setOrphans(new HashSet<>());
+
+ Assertions.assertTrue(Objects.deepEquals(microserviceSystem1, microserviceSystem2));
+
+ }
+
+
+// private static void deepCompareSystems(MicroserviceSystem microserviceSystem1, MicroserviceSystem microserviceSystem2) {
+// // Ignore orphans for testing
+// microserviceSystem1.setOrphans(null);
+// microserviceSystem2.setOrphans(null);
+// System.out.println("System equivalence is: " + Objects.deepEquals(microserviceSystem1, microserviceSystem2));
+//
+// for (Microservice microservice1 : microserviceSystem1.getMicroservices()) {
+// outer2: {
+// for (Microservice microservice2 : microserviceSystem2.getMicroservices()) {
+// if (microservice1.getName().equals(microservice2.getName())) {
+// System.out.println("Microservice equivalence of " + microservice1.getPath() + " is: " + Objects.deepEquals(microservice1, microservice2));
+// for (ProjectFile projectFile1 : microservice1.getAllFiles()) {
+// outer1: {
+// for (ProjectFile projectFile2 : microservice2.getAllFiles()) {
+// if (projectFile1.getPath().equals(projectFile2.getPath())) {
+// System.out.println("Class equivalence of " + projectFile1.getPath() + " is: " + Objects.deepEquals(projectFile1, projectFile2));
+// break outer1;
+// }
+// }
+//
+// System.out.println("No JClass match found for " + projectFile1.getPath());
+// }
+// }
+// break outer2;
+// }
// }
-// }
-// }
-//
-// // Create IR of last commit
-// irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.of(list.get(list.size() - 1).toString().split(" ")[1]));
-// irExtractionService.generateIR(TEST_IR_NAME);
-//
-// // Compare two IR's for equivalence
-// MicroserviceSystem microserviceSystem1 = JsonReadWriteUtils.readFromJSON(NEW_IR_PATH, MicroserviceSystem.class);
-// MicroserviceSystem microserviceSystem2 = JsonReadWriteUtils.readFromJSON(TEST_IR_PATH, MicroserviceSystem.class);
-//
-// microserviceSystem1.setOrphans(new HashSet<>());
-// microserviceSystem2.setOrphans(new HashSet<>());
-//
-// Assertions.assertTrue(Objects.deepEquals(microserviceSystem1, microserviceSystem2));
-//
-// }
-//
-//
-//// private static void deepCompareSystems(MicroserviceSystem microserviceSystem1, MicroserviceSystem microserviceSystem2) {
-//// // Ignore orphans for testing
-//// microserviceSystem1.setOrphans(null);
-//// microserviceSystem2.setOrphans(null);
-//// System.out.println("System equivalence is: " + Objects.deepEquals(microserviceSystem1, microserviceSystem2));
-////
-//// for (Microservice microservice1 : microserviceSystem1.getMicroservices()) {
-//// outer2: {
-//// for (Microservice microservice2 : microserviceSystem2.getMicroservices()) {
-//// if (microservice1.getName().equals(microservice2.getName())) {
-//// System.out.println("Microservice equivalence of " + microservice1.getPath() + " is: " + Objects.deepEquals(microservice1, microservice2));
-//// for (ProjectFile projectFile1 : microservice1.getAllFiles()) {
-//// outer1: {
-//// for (ProjectFile projectFile2 : microservice2.getAllFiles()) {
-//// if (projectFile1.getPath().equals(projectFile2.getPath())) {
-//// System.out.println("Class equivalence of " + projectFile1.getPath() + " is: " + Objects.deepEquals(projectFile1, projectFile2));
-//// break outer1;
-//// }
-//// }
-////
-//// System.out.println("No JClass match found for " + projectFile1.getPath());
-//// }
-//// }
-//// break outer2;
-//// }
-//// }
-////
-//// System.out.println("No Microservice match found for " + microservice1.getPath());
-//// }
-//// }
-////
-//// }
//
-// private static List iterableToList(Iterable iterable) {
-// Iterator iterator = iterable.iterator();
-// List list = new LinkedList<>();
-// while (iterator.hasNext()) {
-// list.add(iterator.next());
+// System.out.println("No Microservice match found for " + microservice1.getPath());
+// }
// }
-// Collections.reverse(list);
//
-// return list;
// }
-//
-//
-//}
+
+ private static List iterableToList(Iterable iterable) {
+ Iterator iterator = iterable.iterator();
+ List list = new LinkedList<>();
+ while (iterator.hasNext()) {
+ list.add(iterator.next());
+ }
+ Collections.reverse(list);
+
+ return list;
+ }
+
+
+}
diff --git a/src/test/java/unit/antipatterns/CyclicDependencyTest.java b/src/test/java/unit/antipatterns/CyclicDependencyTest.java
index 70dfd3d1..0fdf9dde 100644
--- a/src/test/java/unit/antipatterns/CyclicDependencyTest.java
+++ b/src/test/java/unit/antipatterns/CyclicDependencyTest.java
@@ -3,16 +3,18 @@
import static org.junit.jupiter.api.Assertions.*;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
+import edu.university.ecs.lab.common.models.enums.ClassRole;
+import edu.university.ecs.lab.common.models.enums.HttpMethod;
+import edu.university.ecs.lab.common.models.ir.*;
+import edu.university.ecs.lab.detection.antipatterns.models.ServiceChain;
import edu.university.ecs.lab.detection.antipatterns.services.CyclicDependencyMSLevelService;
+import edu.university.ecs.lab.detection.antipatterns.services.ServiceChainMSLevelService;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
-import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
import edu.university.ecs.lab.common.models.sdg.ServiceDependencyGraph;
import edu.university.ecs.lab.common.utils.FileUtils;
import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
@@ -20,23 +22,25 @@
import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
import unit.Constants;
+
+@Ignore
public class CyclicDependencyTest {
private CyclicDependencyMSLevelService cyclicService;
private ServiceDependencyGraph sdg;
@Before
public void setUp(){
- FileUtils.makeDirs();
-
- IRExtractionService irExtractionService = new IRExtractionService(Constants.TEST_CONFIG_PATH, Optional.empty());
-
- irExtractionService.generateIR("TestIR.json");
-
- MicroserviceSystem microserviceSystem = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class);
-
- sdg = new ServiceDependencyGraph(microserviceSystem);
-
- cyclicService = new CyclicDependencyMSLevelService();
+// FileUtils.makeDirs();
+//
+// IRExtractionService irExtractionService = new IRExtractionService(Constants.TEST_CONFIG_PATH, Optional.empty());
+//
+// irExtractionService.generateIR("TestIR.json");
+//
+// MicroserviceSystem microserviceSystem = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class);
+//
+// sdg = new ServiceDependencyGraph(microserviceSystem);
+//
+// cyclicService = new CyclicDependencyMSLevelService();
}
public void testCyclicDependencyDetection(){
@@ -50,5 +54,159 @@ public void testCyclicDependencyDetection(){
assertTrue(Objects.equals(cyclicDep.getCycles(), expectedCyclicDep));
}
+
+ @Test
+ public void cyclicDependencyHasNOne() {
+ Microservice microservice1 = new Microservice("ms1", "/ms1");
+ JClass jClass1 = new JClass("class1", "/class1","class1", ClassRole.CONTROLLER);
+ jClass1.setMethods(Set.of(new Endpoint(new Method(), "/endpoint1", HttpMethod.GET)));
+ microservice1.addJClass(jClass1);
+ JClass jClass5 = new JClass("class5", "/class5","class5", ClassRole.SERVICE);
+ jClass5.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint3", HttpMethod.GET)));
+ microservice1.addJClass(jClass5);
+
+ Microservice microservice2 = new Microservice("ms2", "/ms2");
+ JClass jClass2 = new JClass("class2", "/class2","class2", ClassRole.SERVICE);
+ jClass2.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint1", HttpMethod.GET)));
+ microservice2.addJClass(jClass2);
+ JClass jClass3 = new JClass("class3", "/class3","class3", ClassRole.CONTROLLER);
+ jClass3.setMethods(Set.of(new Endpoint(new Method(), "/endpoint2", HttpMethod.GET)));
+ microservice2.addJClass(jClass3);
+
+ Microservice microservice3 = new Microservice("ms3", "/ms3");
+ JClass jClass4 = new JClass("class4", "/class4","class4", ClassRole.SERVICE);
+ jClass4.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint2", HttpMethod.GET)));
+ microservice3.addJClass(jClass4);
+
+
+ MicroserviceSystem microserviceSystem1 = new MicroserviceSystem("test", "1", Set.of(microservice1, microservice2, microservice3), new HashSet<>());
+ ServiceDependencyGraph sdg1 = new ServiceDependencyGraph(microserviceSystem1);
+ CyclicDependencyMSLevelService cs1 = new CyclicDependencyMSLevelService();
+
+ CyclicDependency cd = cs1.findCyclicDependencies(sdg1);
+ assertTrue(cd.getCycles().size() == 0);
+
+ }
+
+ @Test
+ public void cyclicDependencyHasOne() {
+ Microservice microservice1 = new Microservice("ms1", "/ms1");
+ JClass jClass1 = new JClass("class1", "/class1","class1", ClassRole.CONTROLLER);
+ jClass1.setMethods(Set.of(new Endpoint(new Method(), "/endpoint1", HttpMethod.GET)));
+ microservice1.addJClass(jClass1);
+ JClass jClass5 = new JClass("class5", "/class5","class5", ClassRole.SERVICE);
+ jClass5.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint3", HttpMethod.GET)));
+ microservice1.addJClass(jClass5);
+
+ Microservice microservice2 = new Microservice("ms2", "/ms2");
+ JClass jClass2 = new JClass("class2", "/class2","class2", ClassRole.SERVICE);
+ jClass2.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint1", HttpMethod.GET)));
+ microservice2.addJClass(jClass2);
+ JClass jClass3 = new JClass("class3", "/class3","class3", ClassRole.CONTROLLER);
+ jClass3.setMethods(Set.of(new Endpoint(new Method(), "/endpoint2", HttpMethod.GET)));
+ microservice2.addJClass(jClass3);
+
+ Microservice microservice3 = new Microservice("ms3", "/ms3");
+ JClass jClass4 = new JClass("class4", "/class4","class4", ClassRole.SERVICE);
+ jClass4.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint2", HttpMethod.GET)));
+ microservice3.addJClass(jClass4);
+ JClass jClass6 = new JClass("class6", "/class6","class6", ClassRole.CONTROLLER);
+ jClass6.setMethods(Set.of(new Endpoint(new Method(), "/endpoint3", HttpMethod.GET)));
+ microservice3.addJClass(jClass6);
+
+
+ MicroserviceSystem microserviceSystem1 = new MicroserviceSystem("test", "1", Set.of(microservice1, microservice2, microservice3), new HashSet<>());
+ ServiceDependencyGraph sdg1 = new ServiceDependencyGraph(microserviceSystem1);
+ CyclicDependencyMSLevelService cs1 = new CyclicDependencyMSLevelService();
+
+ CyclicDependency cd = cs1.findCyclicDependencies(sdg1);
+ assertTrue(cd.getCycles().size() == 1);
+ assertTrue(cd.getCycles().get(0).size() == 3);
+ assertTrue(cd.getCycles().get(0).containsAll(List.of("ms1", "ms2", "ms3")));
+
+ }
+
+ @Test
+ public void cyclicDependencyHasOneAlso() {
+ Microservice microservice1 = new Microservice("ms1", "/ms1");
+ JClass jClass1 = new JClass("class1", "/class1","class1", ClassRole.CONTROLLER);
+ jClass1.setMethods(Set.of(new Endpoint(new Method(), "/endpoint1", HttpMethod.GET)));
+ microservice1.addJClass(jClass1);
+ JClass jClass2 = new JClass("class5", "/class2","class5", ClassRole.SERVICE);
+ jClass2.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint2", HttpMethod.GET)));
+ microservice1.addJClass(jClass2);
+
+ Microservice microservice2 = new Microservice("ms2", "/ms2");
+ JClass jClass3 = new JClass("class2", "/class3","class2", ClassRole.SERVICE);
+ jClass3.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint1", HttpMethod.GET)));
+ microservice2.addJClass(jClass3);
+ JClass jClass4 = new JClass("class3", "/class4","class3", ClassRole.CONTROLLER);
+ jClass4.setMethods(Set.of(new Endpoint(new Method(), "/endpoint2", HttpMethod.GET)));
+ microservice2.addJClass(jClass4);
+
+
+
+
+ MicroserviceSystem microserviceSystem1 = new MicroserviceSystem("test", "1", Set.of(microservice1, microservice2), new HashSet<>());
+ ServiceDependencyGraph sdg1 = new ServiceDependencyGraph(microserviceSystem1);
+ CyclicDependencyMSLevelService cs1 = new CyclicDependencyMSLevelService();
+
+ CyclicDependency cd = cs1.findCyclicDependencies(sdg1);
+ assertTrue(cd.getCycles().size() == 1);
+ assertTrue(cd.getCycles().get(0).size() == 2);
+ assertTrue(cd.getCycles().get(0).containsAll(List.of("ms1", "ms2")));
+
+ }
+
+ @Test
+ public void cyclicDependencyHasTwo() {
+ Microservice microservice1 = new Microservice("ms1", "/ms1");
+ JClass jClass1 = new JClass("class1", "/class1","class1", ClassRole.CONTROLLER);
+ jClass1.setMethods(Set.of(new Endpoint(new Method(), "/endpoint1", HttpMethod.GET)));
+ microservice1.addJClass(jClass1);
+ JClass jClass5 = new JClass("class5", "/class5","class5", ClassRole.SERVICE);
+ jClass5.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint3", HttpMethod.GET)));
+ microservice1.addJClass(jClass5);
+
+ Microservice microservice2 = new Microservice("ms2", "/ms2");
+ JClass jClass2 = new JClass("class2", "/class2","class2", ClassRole.SERVICE);
+ jClass2.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint1", HttpMethod.GET)));
+ microservice2.addJClass(jClass2);
+ JClass jClass3 = new JClass("class3", "/class3","class3", ClassRole.CONTROLLER);
+ jClass3.setMethods(Set.of(new Endpoint(new Method(), "/endpoint2", HttpMethod.GET)));
+ microservice2.addJClass(jClass3);
+
+ Microservice microservice3 = new Microservice("ms3", "/ms3");
+ JClass jClass4 = new JClass("class4", "/class4","class4", ClassRole.SERVICE);
+ jClass4.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint2", HttpMethod.GET)));
+ microservice3.addJClass(jClass4);
+ JClass jClass9 = new JClass("class9", "/class9","class9", ClassRole.SERVICE);
+ jClass9.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint4", HttpMethod.GET)));
+ microservice3.addJClass(jClass9);
+ JClass jClass6 = new JClass("class6", "/class6","class6", ClassRole.CONTROLLER);
+ jClass6.setMethods(Set.of(new Endpoint(new Method(), "/endpoint3", HttpMethod.GET)));
+ microservice3.addJClass(jClass6);
+
+ Microservice microservice4 = new Microservice("ms4", "/ms4");
+ JClass jClass7 = new JClass("jClass7", "/jClass7","jClass7", ClassRole.SERVICE);
+ jClass7.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint3", HttpMethod.GET)));
+ microservice4.addJClass(jClass7);
+ JClass jClass8 = new JClass("jClass8", "/jClass8","jClass8", ClassRole.CONTROLLER);
+ jClass8.setMethods(Set.of(new Endpoint(new Method(), "/endpoint4", HttpMethod.GET)));
+ microservice4.addJClass(jClass8);
+
+
+ MicroserviceSystem microserviceSystem1 = new MicroserviceSystem("test", "1", Set.of(microservice1, microservice2, microservice3, microservice4), new HashSet<>());
+ ServiceDependencyGraph sdg1 = new ServiceDependencyGraph(microserviceSystem1);
+ CyclicDependencyMSLevelService cs1 = new CyclicDependencyMSLevelService();
+
+ CyclicDependency cd = cs1.findCyclicDependencies(sdg1);
+ assertTrue(cd.getCycles().size() == 2);
+ assertTrue(cd.getCycles().get(0).size() == 3);
+ assertTrue(cd.getCycles().get(1).size() == 2);
+ assertTrue(cd.getCycles().get(0).containsAll(List.of("ms1", "ms2", "ms3")));
+ assertTrue(cd.getCycles().get(1).containsAll(List.of("ms3", "ms4")));
+
+ }
}
diff --git a/src/test/java/unit/antipatterns/GreedyMicroserviceTest.java b/src/test/java/unit/antipatterns/GreedyMicroserviceTest.java
index f885ace5..af79ccb0 100644
--- a/src/test/java/unit/antipatterns/GreedyMicroserviceTest.java
+++ b/src/test/java/unit/antipatterns/GreedyMicroserviceTest.java
@@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
@@ -16,6 +17,8 @@
import java.util.*;
+
+@Ignore
public class GreedyMicroserviceTest {
private GreedyService greedyService;
private ServiceDependencyGraph sdg;
diff --git a/src/test/java/unit/antipatterns/HubLikeMicroserviceTest.java b/src/test/java/unit/antipatterns/HubLikeMicroserviceTest.java
index 3ca4c74b..71618e81 100644
--- a/src/test/java/unit/antipatterns/HubLikeMicroserviceTest.java
+++ b/src/test/java/unit/antipatterns/HubLikeMicroserviceTest.java
@@ -5,6 +5,7 @@
import java.util.*;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
@@ -16,6 +17,8 @@
import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
import unit.Constants;
+
+@Ignore
public class HubLikeMicroserviceTest {
private HubLikeService hubLikeService;
private ServiceDependencyGraph sdg;
diff --git a/src/test/java/unit/antipatterns/NoApiGatewayTest.java b/src/test/java/unit/antipatterns/NoApiGatewayTest.java
index 4e478e00..06f35945 100644
--- a/src/test/java/unit/antipatterns/NoApiGatewayTest.java
+++ b/src/test/java/unit/antipatterns/NoApiGatewayTest.java
@@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
import edu.university.ecs.lab.common.utils.FileUtils;
@@ -14,6 +15,8 @@
import java.util.Optional;
+
+@Ignore
public class NoApiGatewayTest {
private NoApiGatewayService noApiGatewayService;
private MicroserviceSystem microserviceSystem;
diff --git a/src/test/java/unit/antipatterns/ServiceChainTest.java b/src/test/java/unit/antipatterns/ServiceChainTest.java
index a2b963ac..62bc0442 100644
--- a/src/test/java/unit/antipatterns/ServiceChainTest.java
+++ b/src/test/java/unit/antipatterns/ServiceChainTest.java
@@ -2,13 +2,16 @@
import static org.junit.jupiter.api.Assertions.*;
+import edu.university.ecs.lab.common.models.enums.ClassRole;
+import edu.university.ecs.lab.common.models.enums.HttpMethod;
+import edu.university.ecs.lab.common.models.ir.*;
import edu.university.ecs.lab.detection.antipatterns.services.ServiceChainMSLevelService;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import java.util.*;
-import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
import edu.university.ecs.lab.common.models.sdg.ServiceDependencyGraph;
import edu.university.ecs.lab.common.utils.FileUtils;
import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
@@ -16,6 +19,8 @@
import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
import unit.Constants;
+
+@Ignore
public class ServiceChainTest {
private ServiceChainMSLevelService serviceChainService;
private ServiceDependencyGraph sdg;
@@ -73,4 +78,70 @@ public void testEmptyGraph() {
public void testNullGraph() {
assertThrows(NullPointerException.class, () -> serviceChainService.getServiceChains(null));
}
+
+ @Test
+ public void serviceChainHasOne() {
+ Microservice microservice1 = new Microservice("ms1", "/ms1");
+ JClass jClass1 = new JClass("class1", "/class1","class1", ClassRole.CONTROLLER);
+ jClass1.setMethods(Set.of(new Endpoint(new Method(), "/endpoint1", HttpMethod.GET)));
+ microservice1.addJClass(jClass1);
+
+ Microservice microservice2 = new Microservice("ms2", "/ms2");
+ JClass jClass2 = new JClass("class2", "/class2","class2", ClassRole.SERVICE);
+ jClass2.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint1", HttpMethod.GET)));
+ microservice2.addJClass(jClass2);
+ JClass jClass3 = new JClass("class3", "/class3","class3", ClassRole.CONTROLLER);
+ jClass3.setMethods(Set.of(new Endpoint(new Method(), "/endpoint2", HttpMethod.GET)));
+ microservice2.addJClass(jClass3);
+
+ Microservice microservice3 = new Microservice("ms3", "/ms3");
+ JClass jClass4 = new JClass("class4", "/class4","class4", ClassRole.SERVICE);
+ jClass4.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint2", HttpMethod.GET)));
+ microservice3.addJClass(jClass4);
+
+ MicroserviceSystem microserviceSystem1 = new MicroserviceSystem("test", "1", Set.of(microservice1, microservice2, microservice3), new HashSet<>());
+ ServiceDependencyGraph sdg1 = new ServiceDependencyGraph(microserviceSystem1);
+ ServiceChainMSLevelService scs1 = new ServiceChainMSLevelService();
+
+ ServiceChain sc1 = scs1.getServiceChains(sdg1);
+
+ assertTrue(sc1.getChain().size() == 1);
+ assertEquals(sc1.getChain().get(0), List.of("ms3", "ms2", "ms1"));
+ }
+
+ @Test
+ public void serviceChainHasNoneCycle() {
+ Microservice microservice1 = new Microservice("ms1", "/ms1");
+ JClass jClass1 = new JClass("class1", "/class1","class1", ClassRole.CONTROLLER);
+ jClass1.setMethods(Set.of(new Endpoint(new Method(), "/endpoint1", HttpMethod.GET)));
+ microservice1.addJClass(jClass1);
+ JClass jClass5 = new JClass("class5", "/class5","class5", ClassRole.SERVICE);
+ jClass5.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint3", HttpMethod.GET)));
+ microservice1.addJClass(jClass5);
+
+ Microservice microservice2 = new Microservice("ms2", "/ms2");
+ JClass jClass2 = new JClass("class2", "/class2","class2", ClassRole.SERVICE);
+ jClass2.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint1", HttpMethod.GET)));
+ microservice2.addJClass(jClass2);
+ JClass jClass3 = new JClass("class3", "/class3","class3", ClassRole.CONTROLLER);
+ jClass3.setMethods(Set.of(new Endpoint(new Method(), "/endpoint2", HttpMethod.GET)));
+ microservice2.addJClass(jClass3);
+
+ Microservice microservice3 = new Microservice("ms3", "/ms3");
+ JClass jClass4 = new JClass("class4", "/class4","class4", ClassRole.SERVICE);
+ jClass4.setMethodCalls(List.of(new RestCall(new MethodCall(), "/endpoint2", HttpMethod.GET)));
+ microservice3.addJClass(jClass4);
+ JClass jClass6 = new JClass("class6", "/class6","class6", ClassRole.CONTROLLER);
+ jClass6.setMethods(Set.of(new Endpoint(new Method(), "/endpoint3", HttpMethod.GET)));
+ microservice3.addJClass(jClass6);
+
+
+ MicroserviceSystem microserviceSystem1 = new MicroserviceSystem("test", "1", Set.of(microservice1, microservice2, microservice3), new HashSet<>());
+ ServiceDependencyGraph sdg1 = new ServiceDependencyGraph(microserviceSystem1);
+ ServiceChainMSLevelService scs1 = new ServiceChainMSLevelService();
+
+ ServiceChain sc1 = scs1.getServiceChains(sdg1);
+ assertTrue(sc1.getChain().isEmpty());
+
+ }
}
diff --git a/src/test/java/unit/extraction/ExtractionTest.java b/src/test/java/unit/extraction/ExtractionTest.java
index cd07c57b..7359d0a9 100644
--- a/src/test/java/unit/extraction/ExtractionTest.java
+++ b/src/test/java/unit/extraction/ExtractionTest.java
@@ -1,40 +1,58 @@
-//package unit.extraction;
-//
-//import edu.university.ecs.lab.common.config.ConfigUtil;
-//import edu.university.ecs.lab.common.models.ir.JClass;
-//import edu.university.ecs.lab.common.models.ir.RestCall;
-//import edu.university.ecs.lab.common.services.GitService;
-//import edu.university.ecs.lab.common.utils.SourceToObjectUtils;
-//import org.junit.Before;
-//import org.junit.Test;
-//
-//import java.io.File;
-//
-//import static org.junit.Assert.assertEquals;
-//import static org.junit.Assert.assertTrue;
-//
-//public class ExtractionTest {
-// private static final String TEST_FILE = "src/test/resources/TestFile.java";
-// private static final String TEST_CONFIG_FILE = "src/test/resources/test_config.json";
-// private static final int EXPECTED_CALLS = 6;
-// private static final String PRE_URL = "/api/v1/seatservice/test";
-//
-// @Before
-// public void setUp() {
-// }
-//
-// @Test
-// public void restCallExtractionTest1() {
-// JClass jClass = SourceToObjectUtils.parseClass(new File(TEST_FILE), ConfigUtil.readConfig(TEST_CONFIG_FILE), "");
-//
-// assertEquals(EXPECTED_CALLS, jClass.getRestCalls().size());
+package unit.extraction;
+
+import edu.university.ecs.lab.common.config.ConfigUtil;
+import edu.university.ecs.lab.common.models.ir.*;
+import edu.university.ecs.lab.common.services.GitService;
+import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
+import edu.university.ecs.lab.common.utils.SourceToObjectUtils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+
+@Ignore
+public class ExtractionTest {
+ private static final String TEST_FILE1 = "src/test/resources/TestFile2.java";
+ private static final String TEST_FILE2 = "src/test/resources/TestFile3.java";
+
+
+ private static final String TEST_CONFIG_FILE = "src/test/resources/test_config.json";
+ private static final int EXPECTED_CALLS = 6;
+ private static final String PRE_URL = "/api/v1/seatservice/test";
+
+ @Before
+ public void setUp() {
+ }
+
+ @Test
+ public void restCallExtractionTest1() {
+ GitService gitService = new GitService(TEST_CONFIG_FILE);
+ MicroserviceSystem ms1 = JsonReadWriteUtils.readFromJSON("C:\\Users\\ninja\\IdeaProjects\\cimet2\\output\\java-microservice\\IR\\IR1_8948.json", MicroserviceSystem.class);
+ JClass jClass1 = SourceToObjectUtils.parseClass(new File(TEST_FILE1), ConfigUtil.readConfig(TEST_CONFIG_FILE), "");
+ JClass jClass2 = SourceToObjectUtils.parseClass(new File(TEST_FILE2), ConfigUtil.readConfig(TEST_CONFIG_FILE), "");
+
+ for(Endpoint e : jClass1.getEndpoints()) {
+ for(RestCall rc : jClass2.getRestCalls()) {
+ if(RestCall.matchEndpoint(rc, e)) {
+ System.out.println("Passed " + rc.getUrl() + " " + e.getUrl());
+
+ }
+ }
+
+ }
+
//
// int i = 1;
// for(RestCall restCall : jClass.getRestCalls()) {
// assertTrue(restCall.getUrl().startsWith(PRE_URL + i++));
// }
-//
-// }
-//
-//
-//}
+
+ }
+
+
+}
diff --git a/src/test/resources/TestFile2.java b/src/test/resources/TestFile2.java
new file mode 100644
index 00000000..d24a115f
--- /dev/null
+++ b/src/test/resources/TestFile2.java
@@ -0,0 +1,108 @@
+package com.apssouza.controllers;
+
+import com.apssouza.services.TodoService;
+import com.apssouza.entities.ToDo;
+import com.apssouza.events.TodoCreatedEvent;
+import com.apssouza.exceptions.DataNotFoundException;
+import com.apssouza.infra.EventPublisher;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.net.URI;
+import java.util.List;
+import java.util.Optional;
+import javax.validation.Valid;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+
+/**
+ * Controller responsible of accessing ToDo's functionalities
+ *
+ * @author apssouza
+ */
+@RequestMapping("/todos")
+@RestController
+public class TodoController {
+
+ @Autowired
+ TodoService todoService;
+
+ @Autowired
+ EventPublisher publisher;
+
+ @GetMapping
+ public List all() {
+ return this.todoService.all();
+ }
+
+ @GetMapping("search")
+ public List getByUserEmail(@RequestParam("email") String email) {
+ return this.todoService.getByUserEmail(email);
+ }
+
+ @PostMapping
+ public ResponseEntity> save(@RequestBody @Valid ToDo todo, BindingResult result) {
+ if (result.hasErrors()) {
+ return ResponseEntity.badRequest().build();
+ }
+ ToDo saved = this.todoService.save(todo);
+ Long id = saved.getId();
+ if (id != null) {
+ URI location = ServletUriComponentsBuilder
+ .fromCurrentRequest().path("/{id}")
+ .buildAndExpand(id).toUri();
+ return ResponseEntity.created(location).build();
+ }
+ return ResponseEntity.noContent().build();
+ }
+
+ @PutMapping("{id}")
+ public ResponseEntity> update(
+ @PathVariable long id,
+ @RequestBody @Valid ToDo toDo
+ ) {
+ return ResponseEntity.ok(todoService.update(id, toDo));
+ }
+
+ @GetMapping("{id}")
+ public ResponseEntity> find(@PathVariable long id) {
+ Optional findById = todoService.findById(id);
+ return findById.map(todo -> {
+ return ResponseEntity.ok(todo);
+ }).orElseThrow(() -> new DataNotFoundException("Todo not found"));
+ }
+
+ @DeleteMapping("{id}")
+ public ResponseEntity> delete(@PathVariable long id) {
+ todoService.delete(id);
+ return ResponseEntity.status(HttpStatus.OK).build();
+ }
+
+ @PutMapping("{id}/status")
+ public ResponseEntity> statusUpdate(@PathVariable long id, @RequestBody JsonNode statusUpdate) {
+ JsonNode status = statusUpdate.get("status");
+ if (status == null) {
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST).
+ header("reason", "JSON should contains field done").
+ build();
+ }
+ ToDo todo = todoService.updateStatus(
+ id,
+ ToDo.TodoStatus.valueOf(status.asText())
+ );
+ return ResponseEntity.ok(todo);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/TestFile3.java b/src/test/resources/TestFile3.java
new file mode 100644
index 00000000..d9d3a7c2
--- /dev/null
+++ b/src/test/resources/TestFile3.java
@@ -0,0 +1,30 @@
+package com.apssouza.clients;
+
+import com.apssouza.pojos.Todo;
+import com.apssouza.pojos.User;
+import java.util.List;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Declarative To do REST client
+ *
+ * @author apssouza
+ */
+@FeignClient("todo")
+public interface TodoClient {
+
+ @RequestMapping(value = "/todos", method = RequestMethod.GET)
+ public List getAll();
+
+ @RequestMapping(value = "/todos/search", method = RequestMethod.GET)
+ public List getTodoByUserEmaill(@RequestParam("email") String email);
+
+ @RequestMapping(
+ value = "/todos",
+ method = RequestMethod.POST
+ )
+ Todo createTodo(Todo todo);
+}
\ No newline at end of file
diff --git a/src/test/resources/test_config.json b/src/test/resources/test_config.json
index 2d86cccc..9c3ce942 100644
--- a/src/test/resources/test_config.json
+++ b/src/test/resources/test_config.json
@@ -1,5 +1,5 @@
{
- "systemName": "Train-ticket",
+ "systemName": "train-ticket",
"repositoryURL": "https://github.com/FudanSELab/train-ticket.git",
- "baseBranch": "main"
+ "baseBranch": "master"
}
\ No newline at end of file