- Write the results to a json-file when testing v4 guidelines.

- Add missing changes in tests.
This commit is contained in:
Lampros Smyrnaios 2024-01-17 18:04:03 +02:00
parent d9b94b25e2
commit 61067c3388
6 changed files with 44 additions and 14 deletions

View File

@ -93,6 +93,14 @@
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<!-- logback versions 1.4.X require Java-11 -->
<!-- logback versions 1.3.X require Java-8, but if this project is added as Dependency in a Spring Boot App, then Spring Boot throws an error, since it does not yet support logback 1.3.x -->

View File

@ -39,8 +39,8 @@ public class Test {
logger.info("Processing \"" + fileName + "\"");
Document doc = builder.parse(new File(fileName));
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
scorePerDoc.put(fileName, result.score());
Map<String, Guideline.Result> results = result.results();
scorePerDoc.put(fileName, result.getScore());
Map<String, Guideline.Result> results = result.getResults();
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
logger.info(entry.getKey() + " = " + entry.getValue());
}

View File

@ -42,8 +42,8 @@ public class Test_FAIR {
logger.info("Processing \"" + fileName + "\"");
Document doc = builder.parse(new File(fileName));
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
scorePerDoc.put(fileName, result.score());
Map<String, Guideline.Result> results = result.results();
scorePerDoc.put(fileName, result.getScore());
Map<String, Guideline.Result> results = result.getResults();
if ( logger.isDebugEnabled() ) {
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {

View File

@ -44,8 +44,8 @@ public class Test_FAIR_LIT {
logger.info("Processing \"" + fileName + "\"");
Document doc = builder.parse(new File(fileName));
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
scorePerDoc.put(fileName, result.score());
Map<String, Guideline.Result> results = result.results();
scorePerDoc.put(fileName, result.getScore());
Map<String, Guideline.Result> results = result.getResults();
if ( logger.isDebugEnabled() ) {
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {

View File

@ -40,15 +40,15 @@ public class Test_v2_data {
logger.info("Processing \"" + fileName + "\"");
Document doc = builder.parse(new File(fileName));
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
scorePerDoc.put(fileName, result.score());
Map<String, Guideline.Result> results = result.results();
scorePerDoc.put(fileName, result.getScore());
Map<String, Guideline.Result> results = result.getResults();
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
String key = entry.getKey();
Guideline.Result value = entry.getValue();
logger.debug(key + " = " + value);
if ( key.contains("Date")) {
logger.info("Warnings: " + results.get(key).warnings().toString());
logger.info("Errors: " + results.get(key).errors().toString());
logger.info("Warnings: " + results.get(key).getWarnings().toString());
logger.info("Errors: " + results.get(key).getErrors().toString());
logger.info("Result: " + key + " = " + value + "\n");
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.validator2.engine;
import com.google.gson.Gson;
import eu.dnetlib.validator2.validation.XMLApplicationProfile;
import eu.dnetlib.validator2.validation.guideline.Guideline;
import eu.dnetlib.validator2.validation.guideline.openaire.AbstractOpenAireProfile;
@ -9,7 +10,11 @@ import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import java.io.BufferedWriter;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.OptionalDouble;
@ -37,20 +42,37 @@ public class Test_v4 {
DocumentBuilder builder = TestUtils.getDocumentBuilder();
if ( builder == null )
return;
final Gson gson = new Gson();
for ( String fileName : FILES ) {
try {
logger.info("Processing \"" + fileName + "\"");
Document doc = builder.parse(new File(fileName));
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
scorePerDoc.put(fileName, result.score());
Map<String, Guideline.Result> results = result.results();
// Test writing to json-file.
//////////////////////////////////////////
String resultsFile = System.getProperty("user.dir") + File.separator + "results_v4.json";
logger.info("Will append the results into the results-file: " + resultsFile);
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(resultsFile), StandardCharsets.UTF_8)) {
writer.append("\n");
writer.append(gson.toJson(result));
} catch (Exception e) {
logger.error("Error when writing the \"ValidationResult\" as json into the results-file: " + resultsFile);
return;
}
/////////////////////////////////////////
scorePerDoc.put(fileName, result.getScore());
Map<String, Guideline.Result> results = result.getResults();
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
String key = entry.getKey();
Guideline.Result value = entry.getValue();
logger.debug(key + " = " + value);
if ( key.contains("Date")) {
logger.info("Warnings: " + results.get(key).warnings().toString());
logger.info("Errors: " + results.get(key).errors().toString());
logger.info("Warnings: " + results.get(key).getWarnings().toString());
logger.info("Errors: " + results.get(key).getErrors().toString());
logger.info("Result: " + key + " = " + value + "\n");
}
}