Patrick Thiel 4 лет назад
Родитель
Сommit
3ca6326e59

+ 36 - 31
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/helper/JPlagTestSuiteHelper.java

@@ -26,33 +26,62 @@ public class JPlagTestSuiteHelper {
 	private static final Logger logger = LoggerFactory.getLogger("EndToEndTesting");
 
 	private String[] resourceNames;
-	private String tempFolderPath;
+	private String temporaryFolderPath;
 	private List<ResultJsonModel> resultModel;
 	private LanguageOption languageOption;
 
 	/**
 	 * Helper class for the endToEnd tests. In this class the necessary resources
 	 * are loaded, prepared and copied for the tests based on the passed parameters.
+	 * An instance of this class loads all necessary paths and properties for a test
+	 * run with the specified language
 	 * 
-	 * @param classNames of the resources that are required for the tests
+	 * @param languageOption for loading language-specific resources
 	 * @throws Exception
 	 */
 	public JPlagTestSuiteHelper(LanguageOption languageOption) throws Exception {
 		this.languageOption = languageOption;
-		this.resourceNames = loadResource();
-		this.tempFolderPath = getTempFolderPath();
+		this.resourceNames = new File(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toString()).list();
+		this.temporaryFolderPath = getTempFolderPath();
 
 		this.resultModel = JsonHelper
 				.getResultModelFromPath(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toAbsolutePath().toString());
 		logger.info(String.format("temp path at [%s]", this.temporaryFolderPath));
 	}
 
+	/**
+	 * creates all necessary folder paths and objects for a test run.
+	 * 
+	 * @param classNames
+	 * @return
+	 * @throws Exception
+	 */
 	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);
+		return new TestCaseModel(temporaryFolderPath, resultJsonModel, languageOption);
+	}
+
+	/**
+	 * Loads a suitable system path to temporarily store the test cases.
+	 * 
+	 * @return The temporary system folder, if any, or the path of the current
+	 *         runtime environment
+	 * @throws IOException
+	 */
+	private String getTempFolderPath() throws IOException {
+		return !System.getProperty(Constant.TEMP_SYSTEM_DIRECTORY).isBlank()
+				? Path.of(System.getProperty(Constant.TEMP_SYSTEM_DIRECTORY), Constant.TEMP_DIRECTORY_NAME).toString()
+				: Path.of(new File(".").getCanonicalPath(), Constant.TEMP_DIRECTORY_NAME).toString();
+	}
+
+	/**
+	 * The copied data should be deleted after instance closure
+	 * 
+	 * @throws Exception
+	 */
 	public void clear() throws Exception {
 		logger.info("Class instance was cleaned!");
 		deleteCopiedFiles(new File(temporaryFolderPath));
@@ -75,7 +104,8 @@ public class JPlagTestSuiteHelper {
 		// Copy the resources data to the temporary path
 		for (int counter = 0; counter < classNames.length; counter++) {
 			Path originalPath = Path.of(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toString(), classNames[counter]);
-			Path copiePath = Path.of(tempFolderPath, Constant.TEMP_DIRECTORY_NAME + (counter + 1), classNames[counter]);
+			Path copiePath = Path.of(temporaryFolderPath, Constant.TEMP_DIRECTORY_NAME + (counter + 1),
+					classNames[counter]);
 			try {
 				File directory = new File(copiePath.toString());
 				if (!directory.exists()) {
@@ -92,31 +122,6 @@ public class JPlagTestSuiteHelper {
 		}
 	}
 
-	/**
-	 * loads the filenames in the specified resources
-	 * 
-	 * @return
-	 */
-	private String[] loadResource() {
-		String[] pathnames;
-		File f = new File(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toString());
-		pathnames = f.list();
-		return pathnames;
-	}
-
-	/**
-	 * Loads a suitable system path to temporarily store the test cases.
-	 * 
-	 * @return The temporary system folder, if any, or the path of the current
-	 *         runtime environment
-	 * @throws IOException
-	 */
-	private String getTempFolderPath() throws IOException {
-		return !System.getProperty(Constant.TEMP_SYSTEM_DIRECTORY).isBlank()
-				? Path.of(System.getProperty(Constant.TEMP_SYSTEM_DIRECTORY), Constant.TEMP_DIRECTORY_NAME).toString()
-				: Path.of(new File(".").getCanonicalPath(), Constant.TEMP_DIRECTORY_NAME).toString();
-	}
-
 	/**
 	 * Delete directory with including files
 	 * 

+ 1 - 12
jplag.endToEndTesting/src/main/java/de/jplag/endToEndTesting/helper/JsonHelper.java

@@ -1,25 +1,14 @@
 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 {

+ 17 - 3
jplag.endToEndTesting/src/main/java/model/TestCaseModel.java

@@ -3,12 +3,17 @@ package model;
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import de.jplag.JPlagComparison;
 import de.jplag.JPlagResult;
 import de.jplag.options.JPlagOptions;
 import de.jplag.options.LanguageOption;
 
 public class TestCaseModel {
+	private static final Logger logger = LoggerFactory.getLogger("EndToEndTesting");
+	
 	private ResultJsonModel resultJsonModel;
 	private LanguageOption languageOption;
 	private String submissionFolderPath;
@@ -19,18 +24,27 @@ public class TestCaseModel {
 		this.languageOption = languageOption;
 	}
 
+	/**
+	 * compares the current result with the values stored in the object
+	 * @param jplagResult
+	 * @return true if the values match otherwise false
+	 */
 	public Boolean compaireModelProperties(JPlagResult jplagResult) {
-		// for the fine-granular testing strategy, the result object contains only one
+		// 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) {
+			logger.info("Comparison of the stored values and the current equality values");
+			if (Float.compare(jPlagComparison.similarity(), resultJsonModel.similarity()) != 0) {
 				return false;
 			}
 		}
 		return true;
 	}
 
+	/**
+	 * creates the JPlag options for the test run from the values passed in the constructor.
+	 * @return current JPlag options for the created object
+	 */
 	public JPlagOptions getJPlagOptionsFromCurrentModel() {
 		return new JPlagOptions(new ArrayList<>(Arrays.asList(submissionFolderPath)), new ArrayList<String>(),
 				languageOption);

+ 8 - 8
jplag.endToEndTesting/src/test/java/jplag/endToEndTesting/javaTestCases.java

@@ -47,7 +47,7 @@ class javaTestCases {
 
 		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "The JPlag results do not match the stored values!");
 	}
 
 	/**
@@ -63,7 +63,7 @@ class javaTestCases {
 
 		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "The JPlag results do not match the stored values!");
 	}
 
 	/**
@@ -79,7 +79,7 @@ class javaTestCases {
 
 		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "The JPlag results do not match the stored values!");
 	}
 
 	/**
@@ -95,11 +95,11 @@ class javaTestCases {
 
 		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "The JPlag results do not match the stored values!");
 	}
 
 	/**
-	 * Changing the program flow (token generation) (statments and functions must be
+	 * Changing the program flow (token generation) (statements and functions must be
 	 * independent from each other)
 	 * 
 	 * @throws Exception
@@ -112,11 +112,11 @@ class javaTestCases {
 
 		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "The JPlag results do not match the stored values!");
 	}
 
 	/**
-	 * Variable decleration at the beginning of the program (Detecting Source Code
+	 * Variable declaration at the beginning of the program (Detecting Source Code
 	 * Plagiarism [...])
 	 * @throws Exception 
 	 */
@@ -128,6 +128,6 @@ class javaTestCases {
 
 		JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "dose not match");
+		assertTrue(testCaseModel.compaireModelProperties(jplagResult), "The JPlag results do not match the stored values!");
 	}
 }