From e1b8f5b89a680a4f2d894ad7314bd49a0b1f2091 Mon Sep 17 00:00:00 2001 From: Philipp Schramm Date: Tue, 26 Jul 2022 13:03:16 +0200 Subject: [PATCH] RED-4510: Generated Redaction Log and Generating will not run with profile --- .../redaction/v1/server/RulesTest.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RulesTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RulesTest.java index 676a0763..8f36c1ca 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RulesTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RulesTest.java @@ -113,7 +113,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"; @@ -195,7 +197,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 +205,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); } @@ -221,6 +223,9 @@ 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. @@ -249,10 +254,22 @@ public class RulesTest { } - @SneakyThrows - private void generateAndSaveRedactionLog(String fileName) { + @Test + @Ignore + public void foo() { + String fileName = "oo-home/local-working-dir/3080193/RED-REDACTIONSERVICENIGHT0-JOB1/redaction-service-v1/redaction-service-server-v1/src/test/resources/files/Compounds/26 A8637C - EU AIR3 - LCP Section 10 - Ecotoxicological studies on the plant protection product - Reference list.pdf"; + loadSavedRedactionLog(fileName); + } - if (doesRedactionLogExist(fileName)) { + + private void generateAndSaveRedactionLog(String 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 { @@ -398,7 +415,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 +437,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,7 +457,12 @@ public class RulesTest { private RedactionLog loadSavedRedactionLog(String pdfFileName) { File pdfFile = new File(pdfFileName); - String directory = REDACTION_LOG_PATH + pdfFile.getParentFile().getPath(); + String directory = pdfFile.getParentFile().getPath(); + if (StringUtils.contains(directory, RESOURCES_PATH) || StringUtils.contains(directory, StringUtils.replace(RESOURCES_PATH, "/", "\\"))) { + directory = directory + "\\" + REDACTION_LOG_PATH; + } else { + directory = REDACTION_LOG_RESOURCES_PATH + directory; + } String fileName = StringUtils.replace(pdfFile.getName(), ".pdf", ".json"); File file = new File(directory, fileName); assertThat(file).exists();