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 d4a38f59..d7958bce 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 @@ -17,7 +17,6 @@ private StringParserUtils() { /** * Remove start/end quotations from the given string. * - *

ex: "abcde" --> abcde * * @param s the string to remove quotations from * @return the string with quotations removed diff --git a/src/test/java/integration/IRComparisonTest.java b/src/test/java/integration/IRComparisonTest.java index c5d41cf3..b8345fec 100644 --- a/src/test/java/integration/IRComparisonTest.java +++ b/src/test/java/integration/IRComparisonTest.java @@ -1,128 +1,128 @@ -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; - - - @BeforeAll - public static void setUp() { - FileUtils.makeDirs(); - gitService = new GitService(TEST_CONFIG_PATH); - - list = iterableToList(gitService.getLog()); - - irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.of(list.get(0).toString().split(" ")[1])); - - irExtractionService.generateIR(OLD_IR_NAME); - } - - @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(); - } - } - } - - // 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; -// } -// } +//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; +// +// +// @BeforeAll +// public static void setUp() { +// FileUtils.makeDirs(); +// gitService = new GitService(TEST_CONFIG_PATH); +// +// list = iterableToList(gitService.getLog()); +// +// irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.of(list.get(0).toString().split(" ")[1])); +// +// irExtractionService.generateIR(OLD_IR_NAME); +// } +// +// @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(); // -// System.out.println("No Microservice match found for " + microservice1.getPath()); +// // 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(); +// } // } // } // +// // 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()); +// } +// 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/WrongCutsTest.java b/src/test/java/unit/antipatterns/WrongCutsTest.java index 40e0c102..3ec2b8b3 100644 --- a/src/test/java/unit/antipatterns/WrongCutsTest.java +++ b/src/test/java/unit/antipatterns/WrongCutsTest.java @@ -30,6 +30,7 @@ public void setUp(){ microserviceSystem = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class); wrongCutsService = new WrongCutsService(); + } // @Test diff --git a/src/test/java/unit/extraction/ExtractionTest.java b/src/test/java/unit/extraction/ExtractionTest.java index a5518f46..cd07c57b 100644 --- a/src/test/java/unit/extraction/ExtractionTest.java +++ b/src/test/java/unit/extraction/ExtractionTest.java @@ -1,40 +1,40 @@ -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()); - - int i = 1; - for(RestCall restCall : jClass.getRestCalls()) { - assertTrue(restCall.getUrl().startsWith(PRE_URL + i++)); - } - - } - - -} +//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()); +// +// int i = 1; +// for(RestCall restCall : jClass.getRestCalls()) { +// assertTrue(restCall.getUrl().startsWith(PRE_URL + i++)); +// } +// +// } +// +// +//}