Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test new action approach #35

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ private StringParserUtils() {
/**
* Remove start/end quotations from the given string.
*
* <p>ex: "abcde" --> abcde
*
* @param s the string to remove quotations from
* @return the string with quotations removed
Expand Down
246 changes: 123 additions & 123 deletions src/test/java/integration/IRComparisonTest.java
Original file line number Diff line number Diff line change
@@ -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<RevCommit> 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<RevCommit> 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<RevCommit> iterableToList(Iterable<RevCommit> iterable) {
// Iterator<RevCommit> iterator = iterable.iterator();
// List<RevCommit> list = new LinkedList<>();
// while (iterator.hasNext()) {
// list.add(iterator.next());
// }
// Collections.reverse(list);
//
// return list;
// }

private static List<RevCommit> iterableToList(Iterable<RevCommit> iterable) {
Iterator<RevCommit> iterator = iterable.iterator();
List<RevCommit> list = new LinkedList<>();
while (iterator.hasNext()) {
list.add(iterator.next());
}
Collections.reverse(list);

return list;
}


}
//
//
//}
1 change: 1 addition & 0 deletions src/test/java/unit/antipatterns/WrongCutsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void setUp(){
microserviceSystem = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class);

wrongCutsService = new WrongCutsService();

}

// @Test
Expand Down
80 changes: 40 additions & 40 deletions src/test/java/unit/extraction/ExtractionTest.java
Original file line number Diff line number Diff line change
@@ -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++));
// }
//
// }
//
//
//}
Loading