Compare commits

...
Author SHA1 Message Date
Philipp Schramm e9d925a659 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:38:49 +02:00
Philipp Schramm 44a1f7a0aa RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:38:36 +02:00
Philipp Schramm e95656f9aa RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:25:44 +02:00
Philipp Schramm ce123be9d1 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:15:19 +02:00
Philipp Schramm 41ab998c23 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:15:07 +02:00
Philipp Schramm 95cd64ca87 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:05:36 +02:00
Philipp Schramm a4f2b2a1d8 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 15:05:00 +02:00
Philipp Schramm 79aee79567 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 14:56:03 +02:00
Philipp Schramm 2237ae3910 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 13:55:25 +02:00
Philipp Schramm 4236ba868f RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 13:35:20 +02:00
Philipp Schramm 712b86a19a RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 13:25:58 +02:00
Philipp Schramm c54ee6e7bf RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 13:22:34 +02:00
Philipp Schramm a4d41fc164 RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 13:10:59 +02:00
Philipp Schramm e1b8f5b89a RED-4510: Generated Redaction Log and Generating will not run with profile 2022-07-26 13:03:16 +02:00
10 changed files with 59 additions and 27 deletions
@@ -49,7 +49,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.junit4.SpringRunner;
import com.amazonaws.services.s3.AmazonS3;
@@ -113,7 +112,9 @@ public class RulesTest {
private static final String IMPORTED_REDACTION = "imported_redaction";
private static final String PII = "PII";
private static final String RESOURCES_PATH = "src/test/resources/";
private static final String REDACTION_LOG_PATH = RESOURCES_PATH + "RedactionLog/";
private static final String REDACTION_LOG_PATH = "RedactionLog/";
private static final String REDACTION_LOG_RESOURCES_PATH = RESOURCES_PATH + REDACTION_LOG_PATH;
private final static String TEST_DOSSIER_TEMPLATE_ID = "123";
private final static String TEST_DOSSIER_ID = "123";
private String TEST_FILE_ID = "123";
@@ -175,7 +176,9 @@ public class RulesTest {
.hexColor("#ffe187")
.isHint(hintTypeMap.get(DOSSIER_REDACTIONS))
.isCaseInsensitive(caseInSensitiveMap.get(DOSSIER_REDACTIONS))
.isRecommendation(recommendationTypeMap.get(DOSSIER_REDACTIONS)).rank(rankTypeMap.get(DOSSIER_REDACTIONS)).build()));
.isRecommendation(recommendationTypeMap.get(DOSSIER_REDACTIONS))
.rank(rankTypeMap.get(DOSSIER_REDACTIONS))
.build()));
mockDictionaryCalls(null);
mockDictionaryCalls(0L);
@@ -195,7 +198,7 @@ public class RulesTest {
/**
* Generates RedactionLog for given file and saves it here: REDACTION_LOG_PATH.
* If the RedactionLog already exists, the generating will be skipped
* If the RedactionLog already exists, it will be overwritten
* Test is ignored, because it's for manual tests.
*/
@Ignore
@@ -203,7 +206,7 @@ public class RulesTest {
public void generateRedactionLogForOneFile() {
String fileName = "files/Compounds/31 A14111B - EU AIR3 - MCP Section 1 - Identity of the plant protection product.pdf";
generateAndSaveRedactionLog(fileName);
generateAndSaveRedactionLog(fileName, true);
}
@@ -224,13 +227,13 @@ public class RulesTest {
/**
* Analyses file and compares its RedactionLog with saved one from here: REDACTION_LOG_PATH.
* If RedactionLog Json does not exist, test will fail.
* Test is ignored, because it's for manual tests.
*/
@Ignore
@Test
public void analyseFileAndCompareRedactionLog() {
String fileName = "files/Compounds/31 A14111B - EU AIR3 - MCP Section 1 - Identity of the plant protection product.pdf";
String fileName = "files/RulesTest/SYNGENTA_EFSA_sanitisation_GFL_v1_withHighlights.pdf"; //TODO PSC
// String fileName = "scanned/VV-377031.pdf";
fileName = "files/Cyprodinil/49 Cyprodinil - EU AIR3 - MCA Section 8 Supplement - Ecotoxicological studies on the active substance.pdf";
analyseFileAndCompareRedactionLog(fileName);
}
@@ -239,7 +242,7 @@ public class RulesTest {
* Analyses all files and compares its RedactionLog with saved one from here: REDACTION_LOG_PATH.
* If RedactionLog Json for one file does not exist, whole test will fail.
*/
@IfProfileValue(name = "test-groups", value = "rules-test")
// @IfProfileValue(name = "test-groups", value = "rules-test") //TODO PSC
@Test
public void analyseAllFilesAndCompareRedactionLogs() {
@@ -249,10 +252,16 @@ public class RulesTest {
}
@SneakyThrows
private void generateAndSaveRedactionLog(String fileName) {
if (doesRedactionLogExist(fileName)) {
generateAndSaveRedactionLog(fileName, false);
}
@SneakyThrows
private void generateAndSaveRedactionLog(String fileName, boolean force) {
if (!force && doesRedactionLogExist(fileName)) {
System.out.println("Skip generating RedactionLog as Json for " + fileName + " because it already exists.");
} else {
@@ -386,7 +395,7 @@ public class RulesTest {
assertThat(savedManualChange).isPresent();
}
assertThat(savedRedactionLogEntry.get().getEngines()).containsExactly(redactionLogEntry.getEngines().toArray(new Engine[0]));
assertThat(savedRedactionLogEntry.get().getEngines()).containsExactlyInAnyOrder(redactionLogEntry.getEngines().toArray(new Engine[0]));
assertThat(savedRedactionLogEntry.get().getReference()).containsAll(redactionLogEntry.getReference());
assertThat(savedRedactionLogEntry.get().getImportedRedactionIntersections()).containsAll(redactionLogEntry.getImportedRedactionIntersections());
@@ -398,7 +407,7 @@ public class RulesTest {
private boolean doesRedactionLogExist(String pdfFileName) {
File pdfFile = new File(pdfFileName);
String directory = REDACTION_LOG_PATH + pdfFile.getParentFile().getPath();
String directory = REDACTION_LOG_RESOURCES_PATH + pdfFile.getParentFile().getPath();
String fileName = StringUtils.replace(pdfFile.getName(), ".pdf", ".json");
File file = new File(directory, fileName);
return file.exists();
@@ -420,7 +429,7 @@ public class RulesTest {
File pdfFile = new File(pdfFileName);
String directory = REDACTION_LOG_PATH + pdfFile.getParentFile().getPath();
String directory = REDACTION_LOG_RESOURCES_PATH + pdfFile.getParentFile().getPath();
File dr = new File(directory);
boolean created = dr.mkdirs();
if (created) {
@@ -440,8 +449,20 @@ public class RulesTest {
private RedactionLog loadSavedRedactionLog(String pdfFileName) {
File pdfFile = new File(pdfFileName);
String directory = REDACTION_LOG_PATH + pdfFile.getParentFile().getPath();
String directory = cleanPath(pdfFile.getParentFile().getPath());
if (StringUtils.contains(directory, RESOURCES_PATH)) {
if (!StringUtils.endsWith(directory, "/")) {
directory = directory + "/";
}
directory = directory + REDACTION_LOG_PATH;
} else {
if (StringUtils.startsWith(directory, "/")) {
directory = StringUtils.substring(directory, 1);
}
directory = REDACTION_LOG_RESOURCES_PATH + directory;
}
String fileName = StringUtils.replace(pdfFile.getName(), ".pdf", ".json");
File file = new File(directory, fileName);
assertThat(file).exists();
@@ -449,6 +470,12 @@ public class RulesTest {
}
private String cleanPath(String path) {
return StringUtils.replace(path, "\\", "/");
}
@SneakyThrows
private void loadNerForTest() {
@@ -595,9 +622,15 @@ public class RulesTest {
if (path.toFile().isDirectory()) {
getFileNames(fileNames, path);
} else if (StringUtils.endsWith(path.toAbsolutePath().toString(), ".pdf")) {
String absolutePath = path.toAbsolutePath().toString();
int pos = StringUtils.indexOf(absolutePath, StringUtils.replace(RESOURCES_PATH, "/", "\\")) + 18;
fileNames.add(StringUtils.substring(absolutePath, pos));
String absolutePath = cleanPath(path.toAbsolutePath().toString());
int pos = StringUtils.indexOf(absolutePath, RESOURCES_PATH) + RESOURCES_PATH.length();
if (StringUtils.contains(absolutePath, "scanned/VV-377031.pdf")) {
System.out.println("SKIPPED! " + absolutePath);// TODO PSC
} else {
fileNames.add(StringUtils.substring(absolutePath, pos));
}
}
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long