|
@@ -26,33 +26,62 @@ public class JPlagTestSuiteHelper {
|
|
|
private static final Logger logger = LoggerFactory.getLogger("EndToEndTesting");
|
|
private static final Logger logger = LoggerFactory.getLogger("EndToEndTesting");
|
|
|
|
|
|
|
|
private String[] resourceNames;
|
|
private String[] resourceNames;
|
|
|
- private String tempFolderPath;
|
|
|
|
|
|
|
+ private String temporaryFolderPath;
|
|
|
private List<ResultJsonModel> resultModel;
|
|
private List<ResultJsonModel> resultModel;
|
|
|
private LanguageOption languageOption;
|
|
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
|
|
|
* are loaded, prepared and copied for the tests based on the passed parameters.
|
|
* 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
|
|
* @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public JPlagTestSuiteHelper(LanguageOption languageOption) throws Exception {
|
|
public JPlagTestSuiteHelper(LanguageOption languageOption) throws Exception {
|
|
|
this.languageOption = languageOption;
|
|
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
|
|
this.resultModel = JsonHelper
|
|
|
.getResultModelFromPath(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toAbsolutePath().toString());
|
|
.getResultModelFromPath(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toAbsolutePath().toString());
|
|
|
logger.info(String.format("temp path at [%s]", this.temporaryFolderPath));
|
|
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 {
|
|
public TestCaseModel createNewTestCase(String[] classNames) throws Exception {
|
|
|
createNewTestCaseDirectory(classNames);
|
|
createNewTestCaseDirectory(classNames);
|
|
|
var functionName = StackWalker.getInstance().walk(stream -> stream.skip(1).findFirst().get()).getMethodName();
|
|
var functionName = StackWalker.getInstance().walk(stream -> stream.skip(1).findFirst().get()).getMethodName();
|
|
|
ResultJsonModel resultJsonModel = resultModel.stream()
|
|
ResultJsonModel resultJsonModel = resultModel.stream()
|
|
|
.filter(jsonModel -> functionName.equals(jsonModel.getFunctionName())).findAny().orElse(null);
|
|
.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 {
|
|
public void clear() throws Exception {
|
|
|
logger.info("Class instance was cleaned!");
|
|
logger.info("Class instance was cleaned!");
|
|
|
deleteCopiedFiles(new File(temporaryFolderPath));
|
|
deleteCopiedFiles(new File(temporaryFolderPath));
|
|
@@ -75,7 +104,8 @@ public class JPlagTestSuiteHelper {
|
|
|
// Copy the resources data to the temporary path
|
|
// Copy the resources data to the temporary path
|
|
|
for (int counter = 0; counter < classNames.length; counter++) {
|
|
for (int counter = 0; counter < classNames.length; counter++) {
|
|
|
Path originalPath = Path.of(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toString(), classNames[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 {
|
|
try {
|
|
|
File directory = new File(copiePath.toString());
|
|
File directory = new File(copiePath.toString());
|
|
|
if (!directory.exists()) {
|
|
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
|
|
* Delete directory with including files
|
|
|
*
|
|
*
|