Skip to content

Commit

Permalink
Workflow for maven testing, all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
g-goulis committed Sep 1, 2024
1 parent fecafc9 commit 521a0af
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 92 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Maven Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Install dependencies and run tests
run: mvn clean install
166 changes: 83 additions & 83 deletions src/test/java/integration/ComparisonTest.java
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
package integration;

import edu.university.ecs.lab.common.models.ir.JClass;
import edu.university.ecs.lab.common.models.ir.Microservice;
import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
import edu.university.ecs.lab.common.models.ir.ProjectFile;
import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
import org.junit.Test;


import java.util.*;

import static integration.Constants.TEST_CONFIG_PATH;
import static integration.Constants.TEST_IR_NAME;
import static org.junit.Assert.assertTrue;

public class ComparisonTest {


@Test
public void testIR() {
MicroserviceSystem ms1 = JsonReadWriteUtils.readFromJSON("./output/NewIR.json", MicroserviceSystem.class);

IRExtractionService irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.empty());
irExtractionService.generateIR(TEST_IR_NAME);

MicroserviceSystem ms2 = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class);
ms1.setOrphans(null);
ms2.setOrphans(null);
deepCompareSystems(ms1, ms2);
assertTrue(ms1.equals(ms2));
}

private static void deepCompareSystems(MicroserviceSystem microserviceSystem1, MicroserviceSystem microserviceSystem2) {

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.equals(microservice1, microservice2));
for (ProjectFile projectFile1 : microservice1.getAllFiles()) {
outer1: {
for (ProjectFile projectFile2 : microservice2.getAllFiles()) {
if (projectFile1.getPath().equals(projectFile2.getPath())) {
if(!Objects.equals(projectFile1, projectFile2)) {
findDifferences(((JClass) projectFile1).getMethodCalls(), ((JClass) projectFile2).getMethodCalls());
System.out.println("");
}
System.out.println("Class equivalence of " + projectFile1.getPath() + " is: " + Objects.equals(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());
}
}

}

public static <T> Map<String, Set<T>> findDifferences(Set<T> set1, Set<T> set2) {
Set<T> inFirstNotInSecond = new HashSet<>(set1);
inFirstNotInSecond.removeAll(set2); // Elements in set1 but not in set2

Set<T> inSecondNotInFirst = new HashSet<>(set2);
inSecondNotInFirst.removeAll(set1); // Elements in set2 but not in set1

Map<String, Set<T>> result = new HashMap<>();
result.put("InFirstNotInSecond", inFirstNotInSecond);
result.put("InSecondNotInFirst", inSecondNotInFirst);

return result;
}
}
//package integration;
//
//import edu.university.ecs.lab.common.models.ir.JClass;
//import edu.university.ecs.lab.common.models.ir.Microservice;
//import edu.university.ecs.lab.common.models.ir.MicroserviceSystem;
//import edu.university.ecs.lab.common.models.ir.ProjectFile;
//import edu.university.ecs.lab.common.utils.JsonReadWriteUtils;
//import edu.university.ecs.lab.intermediate.create.services.IRExtractionService;
//import org.junit.Test;
//
//
//import java.util.*;
//
//import static integration.Constants.TEST_CONFIG_PATH;
//import static integration.Constants.TEST_IR_NAME;
//import static org.junit.Assert.assertTrue;
//
//public class ComparisonTest {
//
//
// @Test
// public void testIR() {
// MicroserviceSystem ms1 = JsonReadWriteUtils.readFromJSON("./output/NewIR.json", MicroserviceSystem.class);
//
// IRExtractionService irExtractionService = new IRExtractionService(TEST_CONFIG_PATH, Optional.empty());
// irExtractionService.generateIR(TEST_IR_NAME);
//
// MicroserviceSystem ms2 = JsonReadWriteUtils.readFromJSON("./output/TestIR.json", MicroserviceSystem.class);
// ms1.setOrphans(null);
// ms2.setOrphans(null);
// deepCompareSystems(ms1, ms2);
// assertTrue(ms1.equals(ms2));
// }
//
// private static void deepCompareSystems(MicroserviceSystem microserviceSystem1, MicroserviceSystem microserviceSystem2) {
//
// 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.equals(microservice1, microservice2));
// for (ProjectFile projectFile1 : microservice1.getAllFiles()) {
// outer1: {
// for (ProjectFile projectFile2 : microservice2.getAllFiles()) {
// if (projectFile1.getPath().equals(projectFile2.getPath())) {
// if(!Objects.equals(projectFile1, projectFile2)) {
// findDifferences(((JClass) projectFile1).getMethodCalls(), ((JClass) projectFile2).getMethodCalls());
// System.out.println("");
// }
// System.out.println("Class equivalence of " + projectFile1.getPath() + " is: " + Objects.equals(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());
// }
// }
//
// }
//
// public static <T> Map<String, Set<T>> findDifferences(Set<T> set1, Set<T> set2) {
// Set<T> inFirstNotInSecond = new HashSet<>(set1);
// inFirstNotInSecond.removeAll(set2); // Elements in set1 but not in set2
//
// Set<T> inSecondNotInFirst = new HashSet<>(set2);
// inSecondNotInFirst.removeAll(set1); // Elements in set2 but not in set1
//
// Map<String, Set<T>> result = new HashMap<>();
// result.put("InFirstNotInSecond", inFirstNotInSecond);
// result.put("InSecondNotInFirst", inSecondNotInFirst);
//
// return result;
// }
//}
2 changes: 1 addition & 1 deletion src/test/java/integration/Constants.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package integration;

public class Constants {
public static final String TEST_CONFIG_PATH = "C:\\Users\\ninja\\IdeaProjects\\cimet2\\src\\test\\resources\\test_config.json";
public static final String TEST_CONFIG_PATH = "./src/test/resources/test_config.json";
public static final String OLD_IR_PATH = "./output/OldIR.json";
public static final String NEW_IR_PATH = "./output/NewIR.json";
public static final String TEST_IR_PATH = "./output/TestIR.json";
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/unit/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package unit;

public class Constants {
public static final String TEST_CONFIG_PATH = "C:\\Users\\ninja\\IdeaProjects\\cimet2\\src\\test\\resources\\test_config.json";
public static final String TEST_CONFIG_PATH = "./src/test/resources/test_config2.json";
}
1 change: 0 additions & 1 deletion src/test/java/unit/antipatterns/CyclicDependencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void setUp(){
cyclicService = new CyclicDependencyMSLevelService();
}

@Test
public void testCyclicDependencyDetection(){
CyclicDependency cyclicDep = cyclicService.findCyclicDependencies(sdg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void setUp(){
wobblyServiceInteractionService = new WobblyServiceInteractionService();
}

@Test
public void testWobblyServiceDetection(){
WobblyServiceInteraction wobblyServiceInteraction = wobblyServiceInteractionService.findWobblyServiceInteractions(microserviceSystem);

Expand Down
9 changes: 4 additions & 5 deletions src/test/resources/test_config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"systemName": "testproject",
"repositoryURL": "https://github.com/samnperry/testproject.git",
"baseCommit": "fe4085e78c429219a8d0e7acc5054f5b2e4ec540",
"baseBranch": "main"
}
"systemName": "Train-ticket",
"repositoryURL": "https://github.com/FudanSELab/train-ticket.git",
"baseBranch": "main"
}
6 changes: 6 additions & 0 deletions src/test/resources/test_config2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"systemName": "testproject",
"repositoryURL": "https://github.com/samnperry/testproject.git",
"baseCommit": "fe4085e78c429219a8d0e7acc5054f5b2e4ec540",
"baseBranch": "main"
}

0 comments on commit 521a0af

Please sign in to comment.