-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhauled the end to end tests and added the test code from progpedia (
#1279) * Overhauled the end to end tests and added the test code from progpedia. * Added missing result files for end to end tests * Fixed test results * Reduced epsilon value for end to end tests. * Generate expected test values for the progpedia dataset. * Added token output for end to end tests. * Improved end to end test output. * Added strict order for submissions in comparison. * Fixed sonarcloud issues. * Implemented timurs suggestions. * Moved progpedia data into a zip file. * Fixed spotless issues concerning zips. * spotless. * Fixed sonarcloud issues. * Improved language in test descriptions. * Improved handling of io streams in end to end tests. * Added logging when permissions cannot be set on temp directory. * Spotless * Fixed sonarcloud issues. --------- Co-authored-by: Dominik Fuchß <dominik.fuchss@kit.edu> Co-authored-by: Timur Saglam <timur.saglam@kit.edu>
- Loading branch information
1 parent
9a0d142
commit 40d466e
Showing
42 changed files
with
22,199 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
endtoend-testing/src/main/java/de/jplag/endtoend/helper/LanguageDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.jplag.endtoend.helper; | ||
|
||
import java.io.IOException; | ||
|
||
import de.jplag.Language; | ||
import de.jplag.cli.LanguageLoader; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
/** | ||
* Deserialized a language from a json file | ||
*/ | ||
public class LanguageDeserializer extends JsonDeserializer<Language> { | ||
@Override | ||
public Language deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { | ||
String name = jsonParser.getText(); | ||
return LanguageLoader.getLanguage(name).orElseThrow(() -> new IllegalStateException(String.format("Language %s not found.", name))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
endtoend-testing/src/main/java/de/jplag/endtoend/helper/UnzipManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.jplag.endtoend.helper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.attribute.FileAttribute; | ||
import java.nio.file.attribute.PosixFilePermission; | ||
import java.nio.file.attribute.PosixFilePermissions; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
import de.jplag.endtoend.model.DataSet; | ||
|
||
public class UnzipManager { | ||
private final Map<DataSet, File> unzippedFiles; | ||
private static UnzipManager instance; | ||
private final Logger logger = Logger.getLogger("Unzip Manager"); | ||
|
||
private static synchronized UnzipManager getInstance() { | ||
if (instance == null) { | ||
instance = new UnzipManager(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
public static File unzipOrCache(DataSet dataSet, File zip) throws IOException { | ||
return getInstance().unzipOrCacheInternal(dataSet, zip); | ||
} | ||
|
||
private UnzipManager() { | ||
this.unzippedFiles = new HashMap<>(); | ||
} | ||
|
||
private File unzipOrCacheInternal(DataSet dataSet, File zip) throws IOException { | ||
if (!unzippedFiles.containsKey(dataSet)) { | ||
File target; | ||
|
||
if (SystemUtils.IS_OS_UNIX) { | ||
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")); | ||
target = Files.createTempDirectory(zip.getName(), attr).toFile(); | ||
} else { | ||
target = Files.createTempDirectory(zip.getName()).toFile(); | ||
if (!(target.setReadable(true, true) && target.setWritable(true, true) && target.setExecutable(true, true))) { | ||
logger.warning("Could not set permissions for temp directory (" + target.getAbsolutePath() + ")."); | ||
} | ||
} | ||
|
||
FileHelper.unzip(zip, target); | ||
this.unzippedFiles.put(dataSet, target); | ||
} | ||
|
||
return this.unzippedFiles.get(dataSet); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
endtoend-testing/src/main/java/de/jplag/endtoend/model/ComparisonIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.jplag.endtoend.model; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.util.HashSet; | ||
import java.util.Scanner; | ||
import java.util.Set; | ||
|
||
/** | ||
* Identifier for a comparison. The order of the names does not matter | ||
* @param firstName The first name | ||
* @param secondName The second name | ||
*/ | ||
public record ComparisonIdentifier(String firstName, String secondName) { | ||
private static final String INVALID_LINE_ERROR_MESSAGE = "Comparison identifier file (%s) has an invalid line: %s"; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof ComparisonIdentifier other)) { | ||
return false; | ||
} | ||
|
||
return (firstName.equals(other.firstName) && secondName.equals(other.secondName)) | ||
|| (secondName.equals(other.firstName) && firstName.equals(other.secondName)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return firstName.hashCode() + secondName.hashCode(); | ||
} | ||
|
||
/** | ||
* Loads the identifiers stored in a csv (semicolon separated) file. | ||
* @param file The file to load | ||
* @return The comparisons in the file | ||
*/ | ||
public static Set<ComparisonIdentifier> loadIdentifiersFromFile(File file, String delimiter) { | ||
try (Scanner scanner = new Scanner(file)) { | ||
Set<ComparisonIdentifier> identifiers = new HashSet<>(); | ||
while (scanner.hasNextLine()) { | ||
String[] parts = scanner.nextLine().split(delimiter); | ||
if (parts.length != 2) { | ||
throw new IllegalStateException(String.format(INVALID_LINE_ERROR_MESSAGE, file.getAbsolutePath(), String.join(delimiter, parts))); | ||
} | ||
identifiers.add(new ComparisonIdentifier(parts[0], parts[1])); | ||
} | ||
return identifiers; | ||
} catch (FileNotFoundException e) { | ||
throw new IllegalStateException(String.format("Comparisons could not be loaded for %s.", file.getName()), e); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return firstName + " - " + secondName; | ||
} | ||
} |
Oops, something went wrong.