Selaa lähdekoodia

Change from org.json to jackson-json, replacing current classes and functions with the new architecture. Unclear code was removed or replaced

Patrick Thiel 4 vuotta sitten
vanhempi
commit
dd025e69c3

+ 3 - 10
jplag.endToEndTesting/pom.xml

@@ -7,22 +7,15 @@
 		<version>${revision}</version>
 		<version>${revision}</version>
 	</parent>
 	</parent>
 	<artifactId>jplag.endToEndTesting</artifactId>
 	<artifactId>jplag.endToEndTesting</artifactId>
-
 	<dependencies>
 	<dependencies>
 		<dependency>
 		<dependency>
 			<groupId>de.jplag</groupId>
 			<groupId>de.jplag</groupId>
 			<artifactId>jplag</artifactId>
 			<artifactId>jplag</artifactId>
 		</dependency>
 		</dependency>
 		<dependency>
 		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>4.9</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.json</groupId>
-			<artifactId>json</artifactId>
-			<version>20070829</version>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-databind</artifactId>
+			<version>2.13.0</version>
 		</dependency>
 		</dependency>
 	</dependencies>
 	</dependencies>
 </project>
 </project>

+ 2 - 6
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/constants/Constant.java

@@ -5,7 +5,7 @@ import java.nio.file.Path;
 public final class Constant {
 public final class Constant {
 
 
 	private Constant() {
 	private Constant() {
-		// No need to instantiate the class, we can hide its constructor
+		// private constructor to prevent instantiation
 	}
 	}
 
 
 	// can be exchanged for a suitable standard path if necessary
 	// can be exchanged for a suitable standard path if necessary
@@ -13,13 +13,9 @@ public final class Constant {
 	public static final String TEMP_DIRECTORY_NAME = "submission";
 	public static final String TEMP_DIRECTORY_NAME = "submission";
 	public static final String TEMP_SYSTEM_DIRECTORY = "java.io.tmpdir";
 	public static final String TEMP_SYSTEM_DIRECTORY = "java.io.tmpdir";
 
 
-	//constant final project strings
+	// constant final project strings
 	public static final Path BASE_PATH_TO_JAVA_RESOURCES_SORTALGO = Path.of("src", "test", "resources", "java",
 	public static final Path BASE_PATH_TO_JAVA_RESOURCES_SORTALGO = Path.of("src", "test", "resources", "java",
 			"sortAlgo");
 			"sortAlgo");
 	public static final Path BASE_PATH_TO_JAVA_RESULT_JSON = Path.of("src", "test", "resources", "results",
 	public static final Path BASE_PATH_TO_JAVA_RESULT_JSON = Path.of("src", "test", "resources", "results",
 			"javaResult.json");
 			"javaResult.json");
-
-	//json-file constants
-	public static final String JSON_TEST_NAME_NODE = "functionName";
-	public static final String JSON_SIMILARITY_NODE = "resultSimilarity";
 }
 }

+ 20 - 24
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/helper/JPlagTestSuiteHelper.java

@@ -9,34 +9,21 @@ import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
 import java.nio.file.StandardCopyOption;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
+import java.util.List;
 
 
 import javax.annotation.processing.FilerException;
 import javax.annotation.processing.FilerException;
 
 
 import de.jplag.endToEndTesting.constants.Constant;
 import de.jplag.endToEndTesting.constants.Constant;
+import de.jplag.options.LanguageOption;
+import model.ResultJsonModel;
+import model.TestCaseModel;
 
 
 public class JPlagTestSuiteHelper {
 public class JPlagTestSuiteHelper {
 
 
 	private String[] resourceNames;
 	private String[] resourceNames;
 	private String tempFolderPath;
 	private String tempFolderPath;
-	private String[] classNames;
-
-	/**
-	 * 
-	 * @return the used temporary folder where the test data is copied to build the
-	 *         structure for the jplag api
-	 */
-	public String getFolderPath() {
-		return tempFolderPath;
-	}
-
-	/**
-	 * 
-	 * @return the class names for the current test instance that were passed in the
-	 *         constructor
-	 */
-	public String[] resourceNames() {
-		return resourceNames;
-	}
+	private List<ResultJsonModel> resultModel;
+	private LanguageOption languageOption;
 
 
 	/**
 	/**
 	 * Helper class for the endToEnd tests. In this class the necessary resources
 	 * Helper class for the endToEnd tests. In this class the necessary resources
@@ -45,13 +32,22 @@ public class JPlagTestSuiteHelper {
 	 * @param classNames of the resources that are required for the tests
 	 * @param classNames of the resources that are required for the tests
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
-	public JPlagTestSuiteHelper(String[] classNames) throws Exception {
-		this.classNames = classNames;
+	public JPlagTestSuiteHelper(LanguageOption languageOption) throws Exception {
+		this.languageOption = languageOption;
 		this.resourceNames = loadResource();
 		this.resourceNames = loadResource();
 		this.tempFolderPath = getTempFolderPath();
 		this.tempFolderPath = getTempFolderPath();
 
 
+		this.resultModel = JsonHelper
+				.getResultModelFromPath(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toAbsolutePath().toString());
 		System.out.println(String.format("temp path at [%s]", this.tempFolderPath));
 		System.out.println(String.format("temp path at [%s]", this.tempFolderPath));
-		createNewTestCaseDirectory();
+	}
+
+	public TestCaseModel createNewTestCase(String[] classNames) throws Exception {
+		createNewTestCaseDirectory(classNames);
+		var functionName = StackWalker.getInstance().walk(stream -> stream.skip(1).findFirst().get()).getMethodName();
+		ResultJsonModel resultJsonModel = resultModel.stream()
+				.filter(jsonModel -> functionName.equals(jsonModel.getFunctionName())).findAny().orElse(null);
+		return new TestCaseModel(tempFolderPath, resultJsonModel, languageOption);
 	}
 	}
 
 
 	/**
 	/**
@@ -59,7 +55,7 @@ public class JPlagTestSuiteHelper {
 	 * 
 	 * 
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
-	private void createNewTestCaseDirectory() throws Exception {
+	private void createNewTestCaseDirectory(String[] classNames) throws Exception {
 		// before copying files to the test path, check if all files are in the resource
 		// before copying files to the test path, check if all files are in the resource
 		// directory
 		// directory
 		for (String className : classNames) {
 		for (String className : classNames) {
@@ -139,7 +135,7 @@ public class JPlagTestSuiteHelper {
 	 * 
 	 * 
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
-	public void close() throws Exception {
+	public void clear() throws Exception {
 		System.out.println("Class instance is terminated!");
 		System.out.println("Class instance is terminated!");
 		System.out.println(new File(tempFolderPath));
 		System.out.println(new File(tempFolderPath));
 		deleteCopiedFiles(new File(tempFolderPath));
 		deleteCopiedFiles(new File(tempFolderPath));

+ 33 - 0
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/helper/JsonHelper.java

@@ -0,0 +1,33 @@
+package de.jplag.endToEndTesting.helper;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import java.io.Reader;
+
+import java.nio.charset.Charset;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import de.jplag.endToEndTesting.constants.Constant;
+import model.ResultJsonModel;
+
+public class JsonHelper {
+
+	public static List<ResultJsonModel> getResultModelFromPath(String pathToJsonFile)
+			throws JsonMappingException, JsonProcessingException, Exception {
+		ObjectMapper objectMapper = new ObjectMapper();
+
+		return Arrays.asList(objectMapper.readValue(Paths.get(pathToJsonFile).toFile(), ResultJsonModel[].class));
+	}
+}

+ 0 - 53
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/helper/JsonReader.java

@@ -1,53 +0,0 @@
-package de.jplag.endToEndTesting.helper;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import java.io.Reader;
-
-import java.nio.charset.Charset;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-public class JsonReader {
-
-	private static String readAll(Reader rd) throws IOException {
-		StringBuilder sb = new StringBuilder();
-		int cp;
-		while ((cp = rd.read()) != -1) {
-			sb.append((char) cp);
-		}
-		return sb.toString();
-	}
-
-	/**
-	 * read in a json file located at the passing path
-	 * 
-	 * @param path to the json file with extension
-	 * @return a JSONObject of the persistence file in .json format
-	 * @throws IOException
-	 * @throws JSONException
-	 */
-	public static JSONObject readJsonFromPath(String path) throws IOException, JSONException {
-		if (!path.endsWith(".json")) {
-			throw new JSONException("the specified filename in the path must be a *.json file");
-		}
-
-		File initialFile = new File(path);
-		InputStream targetStream = new FileInputStream(initialFile);
-
-		try {
-			BufferedReader rd = new BufferedReader(new InputStreamReader(targetStream, Charset.forName("UTF-8")));
-			String jsonText = readAll(rd);
-			JSONObject json = new JSONObject(jsonText);
-			return json;
-		} finally {
-			targetStream.close();
-		}
-	}
-}

+ 0 - 68
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/helper/ResultComparison.java

@@ -1,68 +0,0 @@
-package de.jplag.endToEndTesting.helper;
-
-import java.io.IOException;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import de.jplag.endToEndTesting.constants.Constant;
-
-public class ResultComparison {
-	private String functionName;
-	private float similarity;
-
-	/**
-	 * Based on the passed function name the stored values in the json-file are
-	 * loaded and parsed
-	 * 
-	 * @param functionName of the current test which is searched for as key in the
-	 *                     json-file
-	 * @throws JSONException
-	 * @throws IOException
-	 */
-	public ResultComparison(String functionName) throws JSONException, IOException {
-		if (functionName != null && !functionName.isEmpty()) {
-			this.functionName = functionName;
-			loadStoredComparativeValues();
-		} else {
-			throw new IllegalArgumentException("function name cannot be empty");
-		}
-	}
-
-	/**
-	 * @return the function name passed in the constructor
-	 */
-	public String getFunctionName() {
-		return functionName;
-	}
-
-	/**
-	 * @return the stored similarity value from the json file for the function
-	 *         specified in the constructor.
-	 */
-	public float getSimilarity() {
-		return similarity;
-	}
-
-	/**
-	 * Loads the comparison values of the current function into the object
-	 * 
-	 * @throws JSONException
-	 * @throws IOException
-	 */
-	private void loadStoredComparativeValues() throws JSONException, IOException {
-
-		var jsonResultObj = JsonReader
-				.readJsonFromPath(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toAbsolutePath().toString());
-
-		var resultsArray = jsonResultObj.getJSONArray("results");
-
-		for (int i = 0; i < resultsArray.length(); i++) {
-			JSONObject articleObject = resultsArray.getJSONObject(i);
-			if (articleObject.getString(Constant.JSON_TEST_NAME_NODE).equals(functionName)) {
-				similarity = (float) articleObject.getDouble(Constant.JSON_SIMILARITY_NODE);
-				return;
-			}
-		}
-	}
-}

+ 31 - 0
jplag.endToEndTesting/src/main/java/model/ResultJsonModel.java

@@ -0,0 +1,31 @@
+package model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class ResultJsonModel {
+
+	@JsonProperty("functionName")
+	private String functionName;
+	@JsonProperty("resultSimilarity")
+	private String resultSimilarity;
+	
+	public ResultJsonModel(String functionName, String resultSimilarity)
+	{
+		this.functionName = functionName;
+		this.resultSimilarity = resultSimilarity;
+	}
+	
+	public ResultJsonModel()
+	{
+	}
+	
+	public float similarity()
+	{
+		return Float.parseFloat(resultSimilarity);
+	}
+	
+	public String getFunctionName()
+	{
+		return functionName;
+	}
+}

+ 38 - 0
jplag.endToEndTesting/src/main/java/model/TestCaseModel.java

@@ -0,0 +1,38 @@
+package model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import de.jplag.JPlagComparison;
+import de.jplag.JPlagResult;
+import de.jplag.options.JPlagOptions;
+import de.jplag.options.LanguageOption;
+
+public class TestCaseModel {
+	private ResultJsonModel resultJsonModel;
+	private LanguageOption languageOption;
+	private String submissionFolderPath;
+
+	public TestCaseModel(String submissionFolderPath, ResultJsonModel resultJsonModel, LanguageOption languageOption) {
+		this.submissionFolderPath = submissionFolderPath;
+		this.resultJsonModel = resultJsonModel;
+		this.languageOption = languageOption;
+	}
+
+	public Boolean compaireModelProperties(JPlagResult jplagResult) {
+		// for the fine-granular testing strategy, the result object contains only one
+		// comparison.
+		for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
+			System.out.println("Comparison of the stored values and the current equality values");
+			if (Float.compare(jPlagComparison.similarity(),  resultJsonModel.similarity()) != 0) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	public JPlagOptions getJPlagOptionsFromCurrentModel() {
+		return new JPlagOptions(new ArrayList<>(Arrays.asList(submissionFolderPath)), new ArrayList<String>(),
+				languageOption);
+	}
+}

+ 54 - 163
jplag.endToEndTesting/src/test/java/jplag/endToEndTesting/javaTestCases.java

@@ -1,242 +1,133 @@
 package jplag.endToEndTesting;
 package jplag.endToEndTesting;
 
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+
 import de.jplag.JPlag;
 import de.jplag.JPlag;
-import de.jplag.JPlagComparison;
 import de.jplag.JPlagResult;
 import de.jplag.JPlagResult;
 import de.jplag.endToEndTesting.constants.Constant;
 import de.jplag.endToEndTesting.constants.Constant;
 import de.jplag.endToEndTesting.helper.JPlagTestSuiteHelper;
 import de.jplag.endToEndTesting.helper.JPlagTestSuiteHelper;
-import de.jplag.endToEndTesting.helper.ResultComparison;
-import de.jplag.options.JPlagOptions;
 import de.jplag.options.LanguageOption;
 import de.jplag.options.LanguageOption;
 
 
+import model.TestCaseModel;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
 class javaTestCases {
 class javaTestCases {
+	private JPlagTestSuiteHelper jplagTestSuiteHelper;
 
 
-	@Before
-	public void setUp() {
+	@BeforeAll
+	public void setUp() throws Exception {
+		jplagTestSuiteHelper = new JPlagTestSuiteHelper(LanguageOption.JAVA);
 		assertTrue(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toFile().exists(), "Could not find base directory!");
 		assertTrue(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toFile().exists(), "Could not find base directory!");
-		try {
-			assertTrue(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toFile().exists(),
-					"Could not find java result xml at " + Constant.BASE_PATH_TO_JAVA_RESULT_JSON + "!");
+		assertTrue(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toFile().exists(),
+				"Could not find java result json at " + Constant.BASE_PATH_TO_JAVA_RESULT_JSON + "!");
+	}
 
 
-		} catch (Exception e) {
-			assertTrue(false, e.getMessage());
-		}
+	@AfterEach
+	public void teardown() throws Exception {
+		// after close the created directories are deleted
+		jplagTestSuiteHelper.clear();
 	}
 	}
 
 
 	/**
 	/**
 	 * Inserting comments or empty lines (normalization level)
 	 * Inserting comments or empty lines (normalization level)
+	 * 
+	 * @throws Exception
 	 */
 	 */
 	@Test
 	@Test
-	void normalizationLevelTest_one() {
+	void normalizationLevelTest_one() throws Exception {
 
 
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo1.java" };
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo1.java" };
 
 
-		try {
-			var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
-
-			List<String> submissionTestPaths = new ArrayList<String>();
-			submissionTestPaths.add(testSuiteHelper.getFolderPath());
-
-			JPlagOptions options = new JPlagOptions(submissionTestPaths, new ArrayList<String>(), LanguageOption.JAVA);
+		TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
 
 
-			JPlag jplag = new JPlag(options);
-			JPlagResult result = jplag.run();
-			// after close the created directories are deleted
-			testSuiteHelper.close();
+		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
 
-			ResultComparison resultComparison = new ResultComparison(new Object() {
-			}.getClass().getEnclosingMethod().getName());
-
-			// for the fine-granular testing strategy, the result object contains only one
-			// comparison.
-			for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
-				System.out.println("Comparison of the stored values and the current equality values");
-				assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
-			}
-		} catch (Exception e) {
-			fail(e.getMessage());
-		}
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
 	}
 	}
 
 
 	/**
 	/**
 	 * Changing variable names or function names (normalization level)
 	 * Changing variable names or function names (normalization level)
+	 * 
+	 * @throws Exception
 	 */
 	 */
 	@Test
 	@Test
-	void normalizationLevelTest_two() {
+	void normalizationLevelTest_two() throws Exception {
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo2.java" };
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo2.java" };
 
 
-		try {
-			var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
-
-			List<String> tempList = new ArrayList<String>();
-			tempList.add(testSuiteHelper.getFolderPath());
-
-			JPlagOptions options = new JPlagOptions(tempList, new ArrayList<String>(), LanguageOption.JAVA);
+		TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
 
 
-			JPlag jplag = new JPlag(options);
-			JPlagResult result = jplag.run();
-			// after close the created directories are deleted
-			testSuiteHelper.close();
+		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
 
-			ResultComparison resultComparison = new ResultComparison(new Object() {
-			}.getClass().getEnclosingMethod().getName());
-			// for the fine-granular testing strategy, the result object contains only one
-			// comparison.
-			for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
-				System.out.println("Comparison of the stored values and the current equality values");
-				assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
-			}
-			// after close the created directories are deleted
-
-		} catch (Exception e) {
-			fail(e.getMessage());
-		}
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
 	}
 	}
 
 
 	/**
 	/**
 	 * Inserting comments or empty lines (normalization level)
 	 * Inserting comments or empty lines (normalization level)
+	 * 
+	 * @throws Exception
 	 */
 	 */
 	@Test
 	@Test
-	void normalizationLevelTest_three() {
+	void normalizationLevelTest_three() throws Exception {
 		String[] testClassNames = new String[] { "SortAlgo1.java", "SortAlgo2.java" };
 		String[] testClassNames = new String[] { "SortAlgo1.java", "SortAlgo2.java" };
 
 
-		try {
-			var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
-
-			List<String> tempList = new ArrayList<String>();
-			tempList.add(testSuiteHelper.getFolderPath());
+		TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
 
 
-			JPlagOptions options = new JPlagOptions(tempList, new ArrayList<String>(), LanguageOption.JAVA);
+		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
 
-			JPlag jplag = new JPlag(options);
-			JPlagResult result = jplag.run();
-			// after close the created directories are deleted
-			testSuiteHelper.close();
-
-			ResultComparison resultComparison = new ResultComparison(new Object() {
-			}.getClass().getEnclosingMethod().getName());
-			// for the fine-granular testing strategy, the result object contains only one
-			// comparison.
-			for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
-				System.out.println("Comparison of the stored values and the current equality values");
-				assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
-			}
-
-		} catch (Exception e) {
-			fail(e.getMessage());
-		}
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
 	}
 	}
 
 
 	/**
 	/**
 	 * Insertion of unnecessary or changed code lines (token generation)
 	 * Insertion of unnecessary or changed code lines (token generation)
+	 * 
+	 * @throws Exception
 	 */
 	 */
 	@Test
 	@Test
-	void tokenGenerationLevelTest_one() {
+	void tokenGenerationLevelTest_one() throws Exception {
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo3.java" };
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo3.java" };
 
 
-		try {
-			var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
-
-			List<String> tempList = new ArrayList<String>();
-			tempList.add(testSuiteHelper.getFolderPath());
+		TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
 
 
-			JPlagOptions options = new JPlagOptions(tempList, new ArrayList<String>(), LanguageOption.JAVA);
+		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
 
-			JPlag jplag = new JPlag(options);
-			JPlagResult result = jplag.run();
-			// after close the created directories are deleted
-			testSuiteHelper.close();
-
-			ResultComparison resultComparison = new ResultComparison(new Object() {
-			}.getClass().getEnclosingMethod().getName());
-			// for the fine-granular testing strategy, the result object contains only one
-			// comparison.
-			for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
-				System.out.println("Comparison of the stored values and the current equality values");
-				assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
-			}
-
-		} catch (Exception e) {
-			fail(e.getMessage());
-		}
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
 	}
 	}
 
 
 	/**
 	/**
 	 * Changing the program flow (token generation) (statments and functions must be
 	 * Changing the program flow (token generation) (statments and functions must be
 	 * independent from each other)
 	 * independent from each other)
+	 * 
+	 * @throws Exception
 	 */
 	 */
 	@Test
 	@Test
-	void tokenGenerationLevelTest_two() {
+	void tokenGenerationLevelTest_two() throws Exception {
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo4.java" };
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo4.java" };
 
 
-		try {
-			var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
-
-			List<String> tempList = new ArrayList<String>();
-			tempList.add(testSuiteHelper.getFolderPath());
+		TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
 
 
-			JPlagOptions options = new JPlagOptions(tempList, new ArrayList<String>(), LanguageOption.JAVA);
+		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
 
-			JPlag jplag = new JPlag(options);
-			JPlagResult result = jplag.run();
-			// after close the created directories are deleted
-			testSuiteHelper.close();
-
-			ResultComparison resultComparison = new ResultComparison(new Object() {
-			}.getClass().getEnclosingMethod().getName());
-			// for the fine-granular testing strategy, the result object contains only one
-			// comparison.
-			for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
-				System.out.println("Comparison of the stored values and the current equality values");
-				assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
-			}
-
-		} catch (Exception e) {
-			fail(e.getMessage());
-		}
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
 	}
 	}
 
 
 	/**
 	/**
 	 * Variable decleration at the beginning of the program (Detecting Source Code
 	 * Variable decleration at the beginning of the program (Detecting Source Code
 	 * Plagiarism [...])
 	 * Plagiarism [...])
+	 * @throws Exception 
 	 */
 	 */
 	@Test
 	@Test
-	void tokenGenerationLevelTest_three() {
+	void tokenGenerationLevelTest_three() throws Exception {
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo4d1.java" };
 		String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo4d1.java" };
 
 
-		try {
-			var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
-
-			List<String> tempList = new ArrayList<String>();
-			tempList.add(testSuiteHelper.getFolderPath());
-
-			JPlagOptions options = new JPlagOptions(tempList, new ArrayList<String>(), LanguageOption.JAVA);
-
-			JPlag jplag = new JPlag(options);
-			JPlagResult result = jplag.run();
-			// after close the created directories are deleted
-			testSuiteHelper.close();
+		TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
 
 
-			ResultComparison resultComparison = new ResultComparison(new Object() {
-			}.getClass().getEnclosingMethod().getName());
-			// for the fine-granular testing strategy, the result object contains only one
-			// comparison.
-			for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
-				System.out.println("Comparison of the stored values and the current equality values");
-				assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
-			}
+		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
 
-		} catch (Exception e) {
-			fail(e.getMessage());
-		}
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
 	}
 	}
 }
 }

+ 26 - 28
jplag.endToEndTesting/src/test/resources/results/JavaResult.json

@@ -1,28 +1,26 @@
-{ "results" :
-	[
-    	{
-			"functionName":"normalizationLevelTest_one",
-			"resultSimilarity": 100.0
-		}, 
-    	{
-			"functionName":"normalizationLevelTest_two",
-			"resultSimilarity": 100.0
-		}, 
-    	{
-			"functionName":"normalizationLevelTest_three",
-			"resultSimilarity": 100.0
-		},
-		{
-			"functionName":"tokenGenerationLevelTest_one",
-			"resultSimilarity": 64.0
-		},
-		{
-			"functionName":"tokenGenerationLevelTest_two",
-			"resultSimilarity": 73.04348
-		},
-		{
-			"functionName":"tokenGenerationLevelTest_three",
-			"resultSimilarity": 73.94958
-		}
-	]
-}
+[
+   {
+      "functionName":"normalizationLevelTest_one",
+      "resultSimilarity":100.0
+   },
+   {
+      "functionName":"normalizationLevelTest_two",
+      "resultSimilarity":100.0
+   },
+   {
+      "functionName":"normalizationLevelTest_three",
+      "resultSimilarity":100.0
+   },
+   {
+      "functionName":"tokenGenerationLevelTest_one",
+      "resultSimilarity":64.0
+   },
+   {
+      "functionName":"tokenGenerationLevelTest_two",
+      "resultSimilarity":73.04348
+   },
+   {
+      "functionName":"tokenGenerationLevelTest_three",
+      "resultSimilarity":73.94958
+   }
+]