From efc7ea794f200887b1b9665b38f527ba73ca1def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Tue, 28 Oct 2025 12:18:26 +0100 Subject: [PATCH] :recycle: rework test structure --- README.md | 4 +- .../com/mindee/extraction/ExtractedImage.java | 14 ++- .../com/mindee/input/LocalInputSource.java | 6 ++ .../java/com/mindee/input/LocalResponse.java | 11 +++ src/test/java/com/mindee/AppTest.java | 18 ---- .../java/com/mindee/MindeeClientTest.java | 53 +++++------ .../java/com/mindee/MindeeClientV2IT.java | 18 ++-- .../java/com/mindee/MindeeClientV2Test.java | 15 +-- .../java/com/mindee/TestingUtilities.java | 28 ++++++ .../mindee/extraction/ImageExtractorTest.java | 25 ++--- .../InvoiceSplitterAutoExtractionIT.java | 13 +-- .../mindee/extraction/PDFExtractorTest.java | 9 +- .../com/mindee/http/MindeeHttpApiTest.java | 91 ++++++++++--------- .../com/mindee/input/FileCompressionTest.java | 49 +++++----- .../mindee/input/LocalInputSourceTest.java | 61 +++++++------ .../com/mindee/input/LocalResponseTest.java | 12 ++- .../com/mindee/input/URLInputSourceIT.java | 2 +- .../common/AsyncPredictResponseTest.java | 17 ++-- .../mindee/parsing/common/CropperTest.java | 5 +- .../com/mindee/parsing/common/ErrorTest.java | 6 +- .../parsing/common/FullTextOcrTest.java | 14 +-- .../com/mindee/parsing/common/OcrTest.java | 9 +- .../parsing/common/WorkflowResponseTest.java | 21 ----- .../com/mindee/parsing/v2/InferenceTest.java | 4 +- .../java/com/mindee/pdf/PDFUtilsTest.java | 10 +- .../java/com/mindee/pdf/PdfOperationTest.java | 17 ++-- .../com/mindee/product/ProductTestHelper.java | 19 ---- .../barcodereader/BarcodeReaderV1Test.java | 11 ++- .../billoflading/BillOfLadingV1Test.java | 11 ++- .../businesscard/BusinessCardV1Test.java | 10 +- .../mindee/product/cropper/CropperV1Test.java | 14 +-- .../mindee/product/custom/CustomV1Test.java | 14 +-- .../custom/CustomV1WithLineItemsTest.java | 4 +- .../deliverynote/DeliveryNoteV1Test.java | 10 +- .../driverlicense/DriverLicenseV1Test.java | 10 +- .../FinancialDocumentV1Test.java | 24 +++-- .../BankAccountDetailsV1Test.java | 10 +- .../BankAccountDetailsV2Test.java | 10 +- .../fr/cartegrise/CarteGriseV1Test.java | 10 +- .../fr/energybill/EnergyBillV1Test.java | 10 +- .../fr/healthcard/HealthCardV1Test.java | 10 +- .../product/fr/idcard/IdCardV1Test.java | 14 +-- .../product/fr/idcard/IdCardV2Test.java | 14 +-- .../product/fr/payslip/PayslipV2Test.java | 10 +- .../product/fr/payslip/PayslipV3Test.java | 10 +- .../product/generated/GeneratedV1Test.java | 8 +- .../indianpassport/IndianPassportV1Test.java | 10 +- .../InternationalIdV2Test.java | 10 +- .../mindee/product/invoice/InvoiceV4Test.java | 10 +- .../InvoiceSplitterV1Test.java | 10 +- .../MultiReceiptsDetectorV1Test.java | 10 +- .../NutritionFactsLabelV1Test.java | 10 +- .../product/passport/PassportV1Test.java | 10 +- .../mindee/product/receipt/ReceiptV5Test.java | 10 +- .../mindee/product/resume/ResumeV1Test.java | 10 +- .../product/us/bankcheck/BankCheckV1Test.java | 14 +-- .../healthcarecard/HealthcareCardV1Test.java | 10 +- .../product/us/usmail/UsMailV3Test.java | 10 +- .../java/com/mindee/workflow/WorkflowIT.java | 5 +- .../com/mindee/workflow/WorkflowTest.java | 37 +++++--- src/test/resources | 2 +- 61 files changed, 518 insertions(+), 415 deletions(-) delete mode 100644 src/test/java/com/mindee/AppTest.java delete mode 100644 src/test/java/com/mindee/parsing/common/WorkflowResponseTest.java delete mode 100644 src/test/java/com/mindee/product/ProductTestHelper.java diff --git a/README.md b/README.md index 1ad17f55f..cf1199c44 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Quickly and easily connect to Mindee's API services using Java. This client library has support for both Mindee platform versions. ### V2 - Latest -This is the new platform located here: +This is the latest platform located here: https://app.mindee.com @@ -19,7 +19,7 @@ Consult the ### V1 -This is the legacy platform located here: +This is the platform located here: https://platform.mindee.com/ diff --git a/src/main/java/com/mindee/extraction/ExtractedImage.java b/src/main/java/com/mindee/extraction/ExtractedImage.java index f6b4c56eb..c5e84a4a5 100644 --- a/src/main/java/com/mindee/extraction/ExtractedImage.java +++ b/src/main/java/com/mindee/extraction/ExtractedImage.java @@ -38,7 +38,19 @@ public ExtractedImage(BufferedImage image, String filename, String saveFormat) { */ public void writeToFile(String outputPath) throws IOException { Path imagePath = Paths.get(outputPath, this.filename); - File outputfile = new File(imagePath.toString()); + File outputfile = imagePath.toFile(); + ImageIO.write(this.image, this.saveFormat, outputfile); + } + + /** + * Write the image to a file. + * Uses the default image format and filename. + * @param outputPath the output directory (must exist). + * @throws IOException Throws if the file can't be accessed. + */ + public void writeToFile(Path outputPath) throws IOException { + Path imagePath = outputPath.resolve(this.filename); + File outputfile = imagePath.toFile(); ImageIO.write(this.image, this.saveFormat, outputfile); } diff --git a/src/main/java/com/mindee/input/LocalInputSource.java b/src/main/java/com/mindee/input/LocalInputSource.java index 41c812309..d7a695b0e 100644 --- a/src/main/java/com/mindee/input/LocalInputSource.java +++ b/src/main/java/com/mindee/input/LocalInputSource.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Base64; import lombok.Getter; import org.apache.pdfbox.io.IOUtils; @@ -34,6 +35,11 @@ public LocalInputSource(String filePath) throws IOException { this.filename = file.getName(); } + public LocalInputSource(Path filePath) throws IOException { + this.file = Files.readAllBytes(filePath); + this.filename = filePath.getFileName().toString(); + } + public LocalInputSource(File file) throws IOException { this.file = Files.readAllBytes(file.toPath()); this.filename = file.getName(); diff --git a/src/main/java/com/mindee/input/LocalResponse.java b/src/main/java/com/mindee/input/LocalResponse.java index c8d5a4abf..44f327d54 100644 --- a/src/main/java/com/mindee/input/LocalResponse.java +++ b/src/main/java/com/mindee/input/LocalResponse.java @@ -10,6 +10,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.stream.Collectors; @@ -55,6 +56,16 @@ public LocalResponse(File input) throws IOException { ); } + /** + * Load from a {@link Path}. + * @param input will be decoded as UTF-8. + */ + public LocalResponse(Path input) throws IOException { + this.file = this.getBytes( + Files.lines(input, StandardCharsets.UTF_8) + ); + } + private byte[] getBytes(Stream stream) { return stream.collect(Collectors.joining("")).getBytes(); } diff --git a/src/test/java/com/mindee/AppTest.java b/src/test/java/com/mindee/AppTest.java deleted file mode 100644 index ab7622bc9..000000000 --- a/src/test/java/com/mindee/AppTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mindee; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Unit test for simple App. - */ -public class AppTest { - - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() { - Assertions.assertTrue(true); - } -} diff --git a/src/test/java/com/mindee/MindeeClientTest.java b/src/test/java/com/mindee/MindeeClientTest.java index 9afa98c32..3884959a6 100644 --- a/src/test/java/com/mindee/MindeeClientTest.java +++ b/src/test/java/com/mindee/MindeeClientTest.java @@ -11,7 +11,7 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.Job; import com.mindee.parsing.common.PredictResponse; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import com.mindee.product.custom.CustomV1; import com.mindee.product.generated.GeneratedV1; import com.mindee.product.invoice.InvoiceV4; @@ -33,6 +33,9 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + @ExtendWith(MockitoExtension.class) class MindeeClientTest { @@ -51,8 +54,6 @@ public void setUp() { void givenAClientForCustom_withFile_parse_thenShouldCallMindeeApi() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); - PredictResponse predictResponse = new PredictResponse(); predictResponse.setDocument(new Document<>()); predictResponse.setApiRequest(null); @@ -64,7 +65,7 @@ void givenAClientForCustom_withFile_parse_thenShouldCallMindeeApi() .thenReturn(predictResponse); PredictResponse document = client.parse( - new LocalInputSource(file), + new LocalInputSource(getResourcePath("file_types/pdf/blank_1.pdf")), new Endpoint("", "", "")); Assertions.assertNotNull(document); @@ -76,7 +77,6 @@ void givenAClientForCustom_withFile_parse_thenShouldCallMindeeApi() void givenAClientForCustomAndPageOptions_parse_thenShouldOperateCutOnPagesAndCallTheHttpClientCorrectly() throws IOException { - File file = new File("src/test/resources/file_types/pdf/multipage.pdf"); List pageNumberToKeep = new ArrayList<>(); pageNumberToKeep.add(1); @@ -93,7 +93,7 @@ void givenAClientForCustomAndPageOptions_parse_thenShouldOperateCutOnPagesAndCal .thenReturn(new SplitPdf(new byte[0], 0)); PredictResponse document = client.parse( - new LocalInputSource(file), + new LocalInputSource(getResourcePath("file_types/pdf/multipage.pdf")), new Endpoint("", "", ""), new PageOptions( pageNumberToKeep, PageOptionsOperation.KEEP_ONLY, 0)); @@ -109,7 +109,6 @@ void givenAClientForCustomAndPageOptions_parse_thenShouldOperateCutOnPagesAndCal void givenAClientForInvoice_withFile_parse_thenShouldCallMindeeApi() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); PredictResponse predictResponse = new PredictResponse(); predictResponse.setDocument(new Document<>()); predictResponse.setApiRequest(null); @@ -123,7 +122,7 @@ void givenAClientForInvoice_withFile_parse_thenShouldCallMindeeApi() PredictResponse document = client.parse( InvoiceV4.class, - new LocalInputSource(file)); + new LocalInputSource(getResourcePath("file_types/pdf/blank_1.pdf"))); Assertions.assertNotNull(document); Mockito.verify(mindeeApi, Mockito.times(1)) @@ -134,8 +133,6 @@ void givenAClientForInvoice_withFile_parse_thenShouldCallMindeeApi() void givenAClientForInvoice_withInputStream_parse_thenShouldCallMindeeApi() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); - PredictResponse predictResponse = new PredictResponse(); predictResponse.setDocument(new Document<>()); predictResponse.setApiRequest(null); @@ -149,7 +146,7 @@ void givenAClientForInvoice_withInputStream_parse_thenShouldCallMindeeApi() PredictResponse document = client.parse( InvoiceV4.class, new LocalInputSource( - Files.newInputStream(file.toPath()), + Files.newInputStream(getResourcePath("file_types/pdf/blank_1.pdf")), "")); Assertions.assertNotNull(document); @@ -161,7 +158,6 @@ void givenAClientForInvoice_withInputStream_parse_thenShouldCallMindeeApi() void givenAClientForInvoice_withByteArray_parse_thenShouldCallMindeeApi() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); PredictResponse predictResponse = new PredictResponse(); predictResponse.setDocument(new Document<>()); predictResponse.setApiRequest(null); @@ -175,7 +171,7 @@ void givenAClientForInvoice_withByteArray_parse_thenShouldCallMindeeApi() PredictResponse document = client.parse( InvoiceV4.class, new LocalInputSource( - Files.readAllBytes(file.toPath()), + Files.readAllBytes(getResourcePath("file_types/pdf/blank_1.pdf")), "")); Assertions.assertNotNull(document); @@ -187,7 +183,6 @@ void givenAClientForInvoice_withByteArray_parse_thenShouldCallMindeeApi() void givenAClientForInvoiceAndPageOptions_parse_thenShouldOperateCutOnPagesAndCallTheHttpClientCorrectly() throws IOException { - File file = new File("src/test/resources/file_types/pdf/multipage.pdf"); List pageNumberToKeep = new ArrayList<>(); pageNumberToKeep.add(1); PredictResponse predictResponse = new PredictResponse(); @@ -206,7 +201,7 @@ void givenAClientForInvoiceAndPageOptions_parse_thenShouldOperateCutOnPagesAndCa PredictResponse document = client.parse( InvoiceV4.class, - new LocalInputSource(file), + new LocalInputSource(getResourcePath("file_types/pdf/multipage.pdf")), new PageOptions( pageNumberToKeep, PageOptionsOperation.KEEP_ONLY, 0)); @@ -286,8 +281,9 @@ void givenACustomDocumentUrl_whenParsed_shouldCallApiWithCorrectParams() throws @Test void givenAnAsyncDoc_whenEnqueued_shouldInvokeApiCorrectly() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); - LocalInputSource localInputSource = new LocalInputSource(file); + LocalInputSource localInputSource = new LocalInputSource( + getResourcePath("file_types/pdf/blank_1.pdf") + ); Job job = new Job(LocalDateTime.now(), "someid", LocalDateTime.now(), "Completed", null); AsyncPredictResponse predictResponse = new AsyncPredictResponse(); @@ -326,8 +322,9 @@ void givenAnAsyncDoc_whenEnqueued_shouldInvokeApiCorrectly() throws IOException @Test void givenAnAsyncDoc_whenEnqueuedNoParams_shouldInvokeApiCorrectly() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); - LocalInputSource localInputSource = new LocalInputSource(file); + LocalInputSource localInputSource = new LocalInputSource( + getResourcePath("file_types/pdf/blank_1.pdf") + ); Job job = new Job(LocalDateTime.now(), "someid", LocalDateTime.now(), "Completed", null); AsyncPredictResponse predictResponse = new AsyncPredictResponse(); @@ -399,9 +396,9 @@ void givenAnAsyncUrl_whenEnqueued_shouldInvokeApiCorrectly() throws IOException @Test void givenAnAsyncGeneratedDoc_whenEnqueuedNoParams_shouldInvokeApiCorrectly() throws IOException, InterruptedException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); - LocalInputSource localInputSource = new LocalInputSource(file); - + LocalInputSource localInputSource = new LocalInputSource( + getResourcePath("file_types/pdf/blank_1.pdf") + ); Job job = new Job(LocalDateTime.now(), "someid", LocalDateTime.now(), "Completed", null); Endpoint endpoint = new Endpoint("dsddw", "dcsdcd", "dsfdd"); AsyncPredictResponse predictResponse = new AsyncPredictResponse(); @@ -438,26 +435,26 @@ void givenAnAsyncGeneratedDoc_whenEnqueuedNoParams_shouldInvokeApiCorrectly() th @Test void givenJsonInput_whenSync_shouldDeserializeCorrectly() throws IOException { - File file = new File("src/test/resources/products/invoices/response_v4/complete.json"); + File file = new File(getV1ResourcePathString("products/invoices/response_v4/complete.json")); LocalResponse localResponse = new LocalResponse(file); AsyncPredictResponse predictResponse = client.loadPrediction(InvoiceV4.class, localResponse); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( predictResponse.getDocumentObj().toString(), - "src/test/resources/products/invoices/response_v4/summary_full.rst" + getV1ResourcePathString("/products/invoices/response_v4/summary_full.rst") ); } @Test void givenJsonInput_whenAsync_shouldDeserializeCorrectly() throws IOException { - File file = new File("src/test/resources/products/international_id/response_v2/complete.json"); + File file = new File(getV1ResourcePathString("products/international_id/response_v2/complete.json")); LocalResponse localResponse = new LocalResponse(file); AsyncPredictResponse predictResponse = client.loadPrediction( InternationalIdV2.class, localResponse ); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( predictResponse.getDocumentObj().toString(), - "src/test/resources/products/international_id/response_v2/summary_full.rst" + getV1ResourcePathString("products/international_id/response_v2/summary_full.rst") ); } } diff --git a/src/test/java/com/mindee/MindeeClientV2IT.java b/src/test/java/com/mindee/MindeeClientV2IT.java index 0a816dc5c..c34e1bf74 100644 --- a/src/test/java/com/mindee/MindeeClientV2IT.java +++ b/src/test/java/com/mindee/MindeeClientV2IT.java @@ -11,9 +11,11 @@ import com.mindee.parsing.v2.RawText; import com.mindee.parsing.v2.field.InferenceFields; import com.mindee.parsing.v2.field.SimpleField; -import java.io.File; import java.io.IOException; import org.junit.jupiter.api.*; + +import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; import static org.junit.jupiter.api.Assertions.*; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -35,8 +37,8 @@ void setUp() { @DisplayName("Empty, multi-page PDF – enqueue & parse must succeed") void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedException { LocalInputSource source = new LocalInputSource( - new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf")); - + getResourcePath("file_types/pdf/multipage_cut-2.pdf") + ); InferenceParameters params = InferenceParameters .builder(modelId) .rag(false) @@ -87,7 +89,7 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep @DisplayName("Filled, single-page image – enqueue & parse must succeed") void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedException { LocalInputSource source = new LocalInputSource( - new File("src/test/resources/products/financial_document/default_sample.jpg")); + getV1ResourcePathString("products/financial_document/default_sample.jpg")); InferenceParameters params = InferenceParameters .builder(modelId) @@ -134,8 +136,8 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc @DisplayName("Invalid model ID – enqueue must raise 422") void invalidModel_mustThrowError() throws IOException { LocalInputSource source = new LocalInputSource( - new File("src/test/resources/file_types/pdf/blank_1.pdf")); - + getResourcePath("file_types/pdf/blank_1.pdf") + ); InferenceParameters params = InferenceParameters .builder("INVALID_MODEL_ID") .build(); @@ -151,8 +153,8 @@ void invalidModel_mustThrowError() throws IOException { @DisplayName("Invalid webhook ID – enqueue must raise 422") void invalidWebhook_mustThrowError() throws IOException { LocalInputSource source = new LocalInputSource( - new File("src/test/resources/file_types/pdf/blank_1.pdf")); - + getResourcePath("file_types/pdf/blank_1.pdf") + ); InferenceParameters params = InferenceParameters .builder(modelId) .webhookIds(new String[]{"INVALID_WEBHOOK_ID"}) diff --git a/src/test/java/com/mindee/MindeeClientV2Test.java b/src/test/java/com/mindee/MindeeClientV2Test.java index 67940ec61..eb4531e64 100644 --- a/src/test/java/com/mindee/MindeeClientV2Test.java +++ b/src/test/java/com/mindee/MindeeClientV2Test.java @@ -7,7 +7,6 @@ import com.mindee.input.LocalResponse; import com.mindee.parsing.v2.InferenceResponse; import com.mindee.parsing.v2.JobResponse; -import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.DisplayName; @@ -15,6 +14,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import static com.mindee.TestingUtilities.getResourcePath; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -41,7 +41,7 @@ void enqueue_post_async() throws IOException { MindeeClientV2 mindeeClient = makeClientWithMockedApi(predictable); LocalInputSource input = - new LocalInputSource(new File("src/test/resources/file_types/pdf/blank_1.pdf")); + new LocalInputSource(getResourcePath("file_types/pdf/blank_1.pdf")); JobResponse response = mindeeClient.enqueueInference( input, InferenceParameters.builder("dummy-model-id").build() @@ -86,7 +86,9 @@ class GetInference { void document_getInference_async() throws IOException { MindeeApiV2 predictable = Mockito.mock(MindeeApiV2.class); - String json = FileUtils.readFileToString(new File("src/test/resources/v2/products/financial_document/complete.json")); + String json = FileUtils.readFileToString( + getResourcePath("v2/products/financial_document/complete.json").toFile() + ); ObjectMapper mapper = new ObjectMapper(); mapper.findAndRegisterModules(); @@ -120,10 +122,9 @@ class DeserializeResponse { @Test @DisplayName("parses local JSON and exposes correct field values") void inference_loadsLocally() throws IOException { - File jsonFile = - new File("src/test/resources/v2/products/financial_document/complete.json"); - LocalResponse localResponse = new LocalResponse(jsonFile); - + LocalResponse localResponse = new LocalResponse( + getResourcePath("v2/products/financial_document/complete.json") + ); InferenceResponse loaded = localResponse.deserializeResponse(InferenceResponse.class); assertNotNull(loaded, "Loaded InferenceResponse must not be null"); diff --git a/src/test/java/com/mindee/TestingUtilities.java b/src/test/java/com/mindee/TestingUtilities.java index dc22f2088..eec90e651 100644 --- a/src/test/java/com/mindee/TestingUtilities.java +++ b/src/test/java/com/mindee/TestingUtilities.java @@ -1,8 +1,36 @@ package com.mindee; +import org.junit.jupiter.api.Assertions; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; import java.util.Objects; public class TestingUtilities { + public static Path getResourcePath(String filePath) { + return Paths.get("src/test/resources/" + filePath); + } + + public static Path getV1ResourcePath(String filePath) { + return Paths.get("src/test/resources/v1/" + filePath); + } + + public static String getV1ResourcePathString(String filePath) { + return getV1ResourcePath(filePath).toString(); + } + + public static void assertStringEqualsFile(String expected, String filePath) throws IOException { + String[] actualLines = expected.split(System.lineSeparator()); + List expectedLines = Files.readAllLines(Paths.get(filePath)); + String expectedSummary = String.join(String.format("%n"), expectedLines); + String actualSummary = String.join(String.format("%n"), actualLines); + + Assertions.assertEquals(expectedSummary, actualSummary); + } + /** * Retrieves the version from an RST prediction output. * diff --git a/src/test/java/com/mindee/extraction/ImageExtractorTest.java b/src/test/java/com/mindee/extraction/ImageExtractorTest.java index 6e8e97c47..bb8df9ad0 100644 --- a/src/test/java/com/mindee/extraction/ImageExtractorTest.java +++ b/src/test/java/com/mindee/extraction/ImageExtractorTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.mindee.MindeeException; import com.mindee.input.LocalInputSource; import com.mindee.parsing.common.Page; import com.mindee.parsing.common.PredictResponse; @@ -12,10 +11,13 @@ import com.mindee.product.multireceiptsdetector.MultiReceiptsDetectorV1Document; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.File; import java.io.IOException; import java.util.List; +import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + public class ImageExtractorTest { @@ -28,7 +30,7 @@ protected PredictResponse getMultiReceiptsPrediction(St MultiReceiptsDetectorV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/multi_receipts_detector/response_v1/" + name + ".json"), + getV1ResourcePath("products/multi_receipts_detector/response_v1/" + name + ".json").toFile(), type ); } @@ -42,7 +44,7 @@ protected PredictResponse getBarcodeReaderPrediction(String nam BarcodeReaderV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/barcode_reader/response_v1/" + name + ".json"), + getV1ResourcePath("products/barcode_reader/response_v1/" + name + ".json").toFile(), type ); } @@ -50,7 +52,7 @@ protected PredictResponse getBarcodeReaderPrediction(String nam @Test public void givenAnImage_shouldExtractPositionFields() throws IOException { LocalInputSource image = new LocalInputSource( - "src/test/resources/products/multi_receipts_detector/default_sample.jpg" + getV1ResourcePath("products/multi_receipts_detector/default_sample.jpg") ); PredictResponse response = getMultiReceiptsPrediction("complete"); MultiReceiptsDetectorV1 inference = response.getDocument().getInference(); @@ -78,11 +80,12 @@ public void givenAnImage_shouldExtractPositionFields() throws IOException { @Test public void givenAnImage_shouldExtractValueFields() throws IOException { - String imagePath = "src/test/resources/products/barcode_reader/default_sample.jpg"; PredictResponse response = getBarcodeReaderPrediction("complete"); BarcodeReaderV1 inference = response.getDocument().getInference(); - ImageExtractor extractor = new ImageExtractor(imagePath); + ImageExtractor extractor = new ImageExtractor( + getV1ResourcePathString("products/barcode_reader/default_sample.jpg") + ); Assertions.assertEquals(1, extractor.getPageCount()); for (Page page : inference.getPages()) { @@ -97,14 +100,14 @@ public void givenAnImage_shouldExtractValueFields() throws IOException { String.format("barcodes_1D_page-001_%3s.png", i + 1).replace(" ", "0"), source.getFilename() ); - extractedImage.writeToFile("src/test/resources/output/"); + extractedImage.writeToFile(getResourcePath("output/")); } List codes2D = extractor.extractImagesFromPage( page.getPrediction().getCodes2D(), page.getPageId(),"barcodes_2D.png" ); for (ExtractedImage extractedImage : codes2D) { Assertions.assertNotNull(extractedImage.getImage()); - extractedImage.writeToFile("src/test/resources/output/"); + extractedImage.writeToFile(getResourcePath("output/")); } } } @@ -112,7 +115,7 @@ public void givenAnImage_shouldExtractValueFields() throws IOException { @Test public void givenAPdf_shouldExtractPositionFields() throws IOException { LocalInputSource image = new LocalInputSource( - "src/test/resources/products/multi_receipts_detector/multipage_sample.pdf" + getV1ResourcePath("products/multi_receipts_detector/multipage_sample.pdf") ); PredictResponse response = getMultiReceiptsPrediction("multipage_sample"); MultiReceiptsDetectorV1 inference = response.getDocument().getInference(); @@ -129,7 +132,7 @@ public void givenAPdf_shouldExtractPositionFields() throws IOException { for (int i = 0; i < subImages.size(); i++) { ExtractedImage extractedImage = subImages.get(i); Assertions.assertNotNull(extractedImage.getImage()); - extractedImage.writeToFile("src/test/resources/output/"); + extractedImage.writeToFile(getResourcePath("output/")); LocalInputSource source = extractedImage.asInputSource(); Assertions.assertEquals( diff --git a/src/test/java/com/mindee/extraction/InvoiceSplitterAutoExtractionIT.java b/src/test/java/com/mindee/extraction/InvoiceSplitterAutoExtractionIT.java index c84936d0a..d8e5ac61f 100644 --- a/src/test/java/com/mindee/extraction/InvoiceSplitterAutoExtractionIT.java +++ b/src/test/java/com/mindee/extraction/InvoiceSplitterAutoExtractionIT.java @@ -1,5 +1,6 @@ package com.mindee.extraction; +import static com.mindee.TestingUtilities.getV1ResourcePath; import static com.mindee.TestingUtilities.levenshteinRatio; import com.mindee.MindeeClient; @@ -13,7 +14,7 @@ import com.mindee.product.invoicesplitter.InvoiceSplitterV1; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -28,7 +29,7 @@ public class InvoiceSplitterAutoExtractionIT { static void clientSetUp() throws IOException { client = new MindeeClient(); invoiceSplitterInputSource = new LocalInputSource( - "src/test/resources/products/invoice_splitter/default_sample.pdf" + getV1ResourcePath("products/invoice_splitter/default_sample.pdf") ); } @@ -44,9 +45,9 @@ protected PredictResponse getInvoicePrediction(LocalInputSource invoi return client.parse(InvoiceV4.class, invoicePDF); } - protected String prepareInvoiceReturn(String rstFilePath, Document invoicePrediction) + protected String prepareInvoiceReturn(Path rstFilePath, Document invoicePrediction) throws IOException { - List rstRefLines = Files.readAllLines(Paths.get(rstFilePath)); + List rstRefLines = Files.readAllLines(rstFilePath); String parsingVersion = invoicePrediction.getInference().getProduct().getVersion(); String parsingId = invoicePrediction.getId(); String rstRefString = String.join(String.format("%n"), rstRefLines); @@ -74,7 +75,7 @@ public void givenAPDF_shouldExtractInvoices() throws IOException, InterruptedExc extractedPDFsStrict.get(0).asInputSource() ); String testStringRSTInvoice0 = prepareInvoiceReturn( - "src/test/resources/products/invoices/response_v4/summary_full_invoice_p1.rst", + getV1ResourcePath("products/invoices/response_v4/summary_full_invoice_p1.rst"), invoice0.getDocument() ); double invoice0Ratio = levenshteinRatio( @@ -90,7 +91,7 @@ public void givenAPDF_shouldExtractInvoices() throws IOException, InterruptedExc extractedPDFsStrict.get(1).asInputSource() ); String testStringRSTInvoice1 = prepareInvoiceReturn( - "src/test/resources/products/invoices/response_v4/summary_full_invoice_p2.rst", + getV1ResourcePath("products/invoices/response_v4/summary_full_invoice_p2.rst"), invoice1.getDocument() ); double invoice1Ratio = levenshteinRatio( diff --git a/src/test/java/com/mindee/extraction/PDFExtractorTest.java b/src/test/java/com/mindee/extraction/PDFExtractorTest.java index 44d3abe69..846b55919 100644 --- a/src/test/java/com/mindee/extraction/PDFExtractorTest.java +++ b/src/test/java/com/mindee/extraction/PDFExtractorTest.java @@ -5,12 +5,13 @@ import com.mindee.input.LocalInputSource; import com.mindee.parsing.common.PredictResponse; import com.mindee.product.invoicesplitter.InvoiceSplitterV1; -import java.io.File; import java.io.IOException; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class PDFExtractorTest { protected PredictResponse getInvoiceSplitterPrediction() throws @@ -23,7 +24,7 @@ protected PredictResponse getInvoiceSplitterPrediction() thro InvoiceSplitterV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/invoice_splitter/response_v1/complete.json"), + getV1ResourcePath("products/invoice_splitter/response_v1/complete.json").toFile(), type ); } @@ -32,7 +33,7 @@ protected PredictResponse getInvoiceSplitterPrediction() thro @Test public void givenAPDF_shouldExtractInvoicesNoStrict() throws IOException { LocalInputSource pdf = new LocalInputSource( - "src/test/resources/products/invoice_splitter/invoice_5p.pdf" + getV1ResourcePath("products/invoice_splitter/invoice_5p.pdf") ); PredictResponse response = getInvoiceSplitterPrediction(); InvoiceSplitterV1 inference = response.getDocument().getInference(); @@ -50,7 +51,7 @@ public void givenAPDF_shouldExtractInvoicesNoStrict() throws IOException { @Test public void givenAPDF_shouldExtractInvoicesStrict() throws IOException { LocalInputSource pdf = new LocalInputSource( - "src/test/resources/products/invoice_splitter/invoice_5p.pdf" + getV1ResourcePath("products/invoice_splitter/invoice_5p.pdf") ); PredictResponse response = getInvoiceSplitterPrediction(); InvoiceSplitterV1 inference = response.getDocument().getInference(); diff --git a/src/test/java/com/mindee/http/MindeeHttpApiTest.java b/src/test/java/com/mindee/http/MindeeHttpApiTest.java index b3e90155a..c18b5be42 100644 --- a/src/test/java/com/mindee/http/MindeeHttpApiTest.java +++ b/src/test/java/com/mindee/http/MindeeHttpApiTest.java @@ -6,6 +6,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.mindee.TestingUtilities.getV1ResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; import static org.hamcrest.MatcherAssert.assertThat; import com.fasterxml.jackson.core.type.TypeReference; @@ -23,7 +25,6 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Objects; @@ -72,8 +73,7 @@ private MindeeHttpApi getClientForResponse(Path filePath, int statusCode) throws } private MindeeHttpApi getClientForResponse(String filePath, int statusCode) throws IOException { - Path path = Paths.get("src/test/resources/" + filePath); - return getClientForResponse(path, statusCode); + return getClientForResponse(getV1ResourcePath(filePath), statusCode); } @Test @@ -81,14 +81,14 @@ void givenAResponseFromTheEndpoint_whenDeserialized_mustHaveValidSummary() throws IOException { MindeeHttpApi client = getClientForResponse("products/invoices/response_v4/complete.json", 200); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); + Path filePath = getV1ResourcePath("products/invoices/invoice.pdf"); Document document = client.predictPost( InvoiceV4.class, new Endpoint("", ""), RequestParameters.builder() - .file(Files.readAllBytes(file.toPath())) - .fileName(file.getName()) + .file(Files.readAllBytes(filePath)) + .fileName(filePath.getFileName().toString()) .build() ) .getDocument(); @@ -97,9 +97,9 @@ void givenAResponseFromTheEndpoint_whenDeserialized_mustHaveValidSummary() String[] actualLines = document.toString().split(System.lineSeparator()); String actualSummary = String.join(String.format("%n"), actualLines); - List expectedLines = Files - .readAllLines( - Paths.get("src/test/resources/products/invoices/response_v4/summary_full.rst")); + List expectedLines = Files.readAllLines( + getV1ResourcePath("products/invoices/response_v4/summary_full.rst") + ); String expectedSummary = String.join(String.format("%n"), expectedLines); Assertions.assertNotNull(document); @@ -109,16 +109,17 @@ void givenAResponseFromTheEndpoint_whenDeserialized_mustHaveValidSummary() @Test void givenParseParametersWithFile_whenParsed_shouldBuildRequestCorrectly() throws IOException, InterruptedException { - MindeeHttpApi client = getClientForResponse("products/invoices/response_v4/complete.json", 200); - - File file = new File("src/test/resources/products/invoices/invoice.pdf"); - byte[] fileBytes = Files.readAllBytes(file.toPath()); + MindeeHttpApi client = getClientForResponse( + "products/invoices/response_v4/complete.json", 200 + ); + Path filePath = getV1ResourcePath("products/invoices/invoice.pdf"); + byte[] fileBytes = Files.readAllBytes(filePath); Document document = client.predictPost( InvoiceV4.class, new Endpoint("", ""), RequestParameters.builder() .file(fileBytes) - .fileName(file.getName()) + .fileName(filePath.getFileName().toString()) .build() ) .getDocument(); @@ -135,10 +136,11 @@ void givenParseParametersWithFile_whenParsed_shouldBuildRequestCorrectly() @Test void givenPredictOptions_whenParsed_shouldBuildRequestCorrectly() throws IOException, InterruptedException { - MindeeHttpApi client = getClientForResponse("products/invoices/response_v4/complete.json", 200); - - File file = new File("src/test/resources/products/invoices/invoice.pdf"); - byte[] fileBytes = Files.readAllBytes(file.toPath()); + MindeeHttpApi client = getClientForResponse( + "products/invoices/response_v4/complete.json", 200 + ); + Path filePath = getV1ResourcePath("products/invoices/invoice.pdf"); + byte[] fileBytes = Files.readAllBytes(filePath); PredictOptions predictOptions = PredictOptions.builder() .cropper(true) .allWords(true) @@ -148,7 +150,7 @@ void givenPredictOptions_whenParsed_shouldBuildRequestCorrectly() new Endpoint("", ""), RequestParameters.builder() .file(fileBytes) - .fileName(file.getName()) + .fileName(filePath.getFileName().toString()) .predictOptions(predictOptions) .build() ) @@ -189,7 +191,9 @@ void givenParseParametersWithFileUrl_whenParsed_shouldBuildRequestCorrectly() Long.toString(recordedRequest.getBodySize()), recordedRequest.getHeader("Content-Length") ); - Assertions.assertTrue(Objects.requireNonNull(recordedRequest.getHeader("Content-Type")).contains("application/json")); + Assertions.assertTrue( + Objects.requireNonNull(recordedRequest.getHeader("Content-Type")).contains("application/json") + ); Map requestMap = objectMapper.readValue( recordedRequest.getBody().readUtf8(), new TypeReference>() {} @@ -202,7 +206,7 @@ void givenAnUrlBuilderFunction_whenParsed_callsTheCorrectUrl() throws IOException, InterruptedException { String url = String.format("http://localhost:%s", mockWebServer.getPort()); String mockPath = "/testinvoice/v2/test"; - Path path = Paths.get("src/test/resources/products/invoices/response_v4/complete.json"); + Path path = getV1ResourcePath("products/invoices/response_v4/complete.json"); mockWebServer.enqueue(new MockResponse() .setResponseCode(200) .setBody(new String(Files.readAllBytes(path))) @@ -218,7 +222,7 @@ void givenAnUrlBuilderFunction_whenParsed_callsTheCorrectUrl() endpoint -> String.format("http://localhost:%s%s", mockWebServer.getPort(), mockPath)) .build(); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); + File file = new File(getV1ResourcePathString("products/invoices/invoice.pdf")); Document document = client.predictPost( InvoiceV4.class, new Endpoint("", ""), @@ -233,9 +237,9 @@ void givenAnUrlBuilderFunction_whenParsed_callsTheCorrectUrl() String[] actualLines = document.toString().split(System.lineSeparator()); String actualSummary = String.join(String.format("%n"), actualLines); - List expectedLines = Files - .readAllLines( - Paths.get("src/test/resources/products/invoices/response_v4/summary_full.rst")); + List expectedLines = Files.readAllLines( + getV1ResourcePath("products/invoices/response_v4/summary_full.rst") + ); String expectedSummary = String.join(String.format("%n"), expectedLines); Assertions.assertNotNull(document); @@ -252,11 +256,11 @@ void givenAHttpClientBuilder_whenParseCalled_usesClientBuilderToMakeHttpClient() String url = String.format("http://localhost:%s", mockWebServer.getPort()); proxyMock.stubFor(post(urlMatching(".*")) .willReturn(aResponse().proxiedFrom(url))); - Path path = Paths.get("src/test/resources/products/invoices/response_v4/complete.json"); + Path path = getV1ResourcePath("products/invoices/response_v4/complete.json"); mockWebServer.enqueue(new MockResponse() .setResponseCode(200) .setBody(new String(Files.readAllBytes(path)))); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); + File file = new File(getV1ResourcePathString("products/invoices/invoice.pdf")); HttpHost proxy = new HttpHost("localhost", proxyPort); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); @@ -286,9 +290,9 @@ void givenAHttpClientBuilder_whenParseCalled_usesClientBuilderToMakeHttpClient() String[] actualLines = response.getDocument().toString().split(System.lineSeparator()); String actualSummary = String.join(String.format("%n"), actualLines); - List expectedLines = Files - .readAllLines( - Paths.get("src/test/resources/products/invoices/response_v4/summary_full.rst")); + List expectedLines = Files.readAllLines( + getV1ResourcePath("products/invoices/response_v4/summary_full.rst") + ); String expectedSummary = String.join(String.format("%n"), expectedLines); proxyMock.verify(postRequestedFor(urlEqualTo("/products/mindee/invoices/v4/predict")) @@ -298,14 +302,13 @@ void givenAHttpClientBuilder_whenParseCalled_usesClientBuilderToMakeHttpClient() proxyMock.shutdown(); } - @Test void givenAnAsncResponse_whenDeserialized_mustHaveValidJob() throws IOException, InterruptedException { - Path path = Paths.get("src/test/resources/async/post_success.json"); + Path path = getV1ResourcePath("async/post_success.json"); MindeeHttpApi client = getClientForResponse(path, 200); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); + File file = new File(getV1ResourcePathString("products/invoices/invoice.pdf")); AsyncPredictResponse response = client.predictAsyncPost( InvoiceV4.class, new Endpoint(InvoiceV4.class), @@ -337,7 +340,7 @@ void givenAnAsncResponse_whenDeserialized_mustHaveValidJob() @Test void givenAResponseFromTheJobEndpoint_whenDeserialized_mustHaveValidJobAndDocument() throws IOException, InterruptedException { - Path path = Paths.get("src/test/resources/async/get_completed.json"); + Path path = getV1ResourcePath("async/get_completed.json"); MindeeHttpApi client = getClientForResponse(path, 200); AsyncPredictResponse response = client.documentQueueGet( @@ -370,7 +373,7 @@ void givenError401_noToken_mustThrowMindeeHttpException() throws IOException { MindeeHttpApi client = getClientForResponse("errors/error_401_no_token.json", 401); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); + File file = new File(getV1ResourcePathString("products/invoices/invoice.pdf")); byte[] fileInBytes = Files.readAllBytes(file.toPath()); RequestParameters parseParameter = RequestParameters.builder() @@ -398,7 +401,7 @@ void givenError429_mustThrowMindeeHttpException() { MindeeHttpApi client = getClientForResponse("errors/error_429_too_many_requests.json", 429); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); + File file = new File(getV1ResourcePathString("products/invoices/invoice.pdf")); byte[] fileInBytes = Files.readAllBytes(file.toPath()); RequestParameters parseParameter = RequestParameters.builder() @@ -424,12 +427,12 @@ void givenError_inHtml_mustThrowMindeeHttpException() throws IOException { MindeeHttpApi client = getClientForResponse("errors/error_50x.html", 413); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); - byte[] fileInBytes = Files.readAllBytes(file.toPath()); + Path filePath = getV1ResourcePath("products/invoices/invoice.pdf"); + byte[] fileBytes = Files.readAllBytes(filePath); RequestParameters parseParameter = RequestParameters.builder() - .file(fileInBytes) - .fileName(file.getName()) + .file(fileBytes) + .fileName(filePath.getFileName().toString()) .build(); MindeeHttpException httpError = Assertions.assertThrows( @@ -452,12 +455,12 @@ void givenError400_noDetails_mustThrowMindeeHttpException() throws IOException { MindeeHttpApi client = getClientForResponse("errors/error_400_no_details.json", 400); - File file = new File("src/test/resources/products/invoices/invoice.pdf"); - byte[] fileInBytes = Files.readAllBytes(file.toPath()); + Path filePath = getV1ResourcePath("products/invoices/invoice.pdf"); + byte[] fileBytes = Files.readAllBytes(filePath); RequestParameters parseParameter = RequestParameters.builder() - .file(fileInBytes) - .fileName(file.getName()) + .file(fileBytes) + .fileName(filePath.getFileName().toString()) .build(); MindeeHttpException httpError = Assertions.assertThrows( diff --git a/src/test/java/com/mindee/input/FileCompressionTest.java b/src/test/java/com/mindee/input/FileCompressionTest.java index 0d76e8305..cda43ad8d 100644 --- a/src/test/java/com/mindee/input/FileCompressionTest.java +++ b/src/test/java/com/mindee/input/FileCompressionTest.java @@ -13,26 +13,28 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class FileCompressionTest { @Test public void fromInputSource_imageQuality_should_Compress() throws IOException { - LocalInputSource receiptInput = - new LocalInputSource("src/test/resources/file_types/receipt.jpg"); + Path testFilePath = getResourcePath("file_types/receipt.jpg"); + Path outputPath = getResourcePath("output/compress-test.jpg"); + LocalInputSource receiptInput = new LocalInputSource(testFilePath); receiptInput.compress(40); - Path outputPath = Paths.get("src/test/resources/output/compresstest.jpg"); Files.write(outputPath, receiptInput.getFile()); Assertions.assertTrue(Files.exists(outputPath)); - long initialFileSize = Files.size(Paths.get("src/test/resources/file_types/receipt.jpg")); + long initialFileSize = Files.size(testFilePath); long compressedFileSize = Files.size(outputPath); Assertions.assertTrue( @@ -44,9 +46,11 @@ public void fromInputSource_imageQuality_should_Compress() throws IOException { @Test public void testImageQualityCompressesFromCompressor() throws IOException { - Path outputDir = Paths.get("src/test/resources/output"); - LocalInputSource receiptInput = - new LocalInputSource("src/test/resources/file_types/receipt.jpg"); + Path testFilePath = getResourcePath("file_types/receipt.jpg"); + Path outputDir = getResourcePath("output"); + + LocalInputSource receiptInput = new LocalInputSource(testFilePath); + List compresses = Arrays.asList( ImageCompressor.compressImage(receiptInput.getFile(), 100), ImageCompressor.compressImage(receiptInput.getFile()), @@ -54,7 +58,6 @@ public void testImageQualityCompressesFromCompressor() throws IOException { ImageCompressor.compressImage(receiptInput.getFile(), 10), ImageCompressor.compressImage(receiptInput.getFile(), 1) ); - List outputPaths = Arrays.asList( outputDir.resolve("compress100.jpg"), outputDir.resolve("compress75.jpg"), @@ -67,7 +70,7 @@ public void testImageQualityCompressesFromCompressor() throws IOException { Files.write(outputPaths.get(i), compresses.get(i)); } - long initialFileSize = Files.size(Paths.get("src/test/resources/file_types/receipt.jpg")); + long initialFileSize = Files.size(testFilePath); List compressedFileSizes = outputPaths.stream() .map(path -> { try { @@ -106,14 +109,14 @@ public void testImageQualityCompressesFromCompressor() throws IOException { @Test public void testImageResizeFromInputSource() throws IOException { - Path outputDir = Paths.get("src/test/resources/output"); - LocalInputSource imageResizeInput = - new LocalInputSource("src/test/resources/file_types/receipt.jpg"); + Path testFilePath = getResourcePath("file_types/receipt.jpg"); + Path outputDir = getResourcePath("output"); + LocalInputSource imageResizeInput = new LocalInputSource(testFilePath); imageResizeInput.compress(75, 250, 1000); Path outputPath = outputDir.resolve("resize_indirect.jpg"); Files.write(outputPath, imageResizeInput.getFile()); - long initialFileSize = Files.size(Paths.get("src/test/resources/file_types/receipt.jpg")); + long initialFileSize = Files.size(testFilePath); long resizedFileSize = Files.size(outputPath); Assertions.assertTrue(resizedFileSize < initialFileSize); @@ -124,9 +127,9 @@ public void testImageResizeFromInputSource() throws IOException { @Test public void testImageResizeFromCompressor() throws IOException { - Path outputDir = Paths.get("src/test/resources/output"); - LocalInputSource imageResizeInput = - new LocalInputSource("src/test/resources/file_types/receipt.jpg"); + Path testFilePath = getResourcePath("file_types/receipt.jpg"); + Path outputDir = getResourcePath("output"); + LocalInputSource imageResizeInput = new LocalInputSource(testFilePath); List resizes = Arrays.asList( ImageCompressor.compressImage(imageResizeInput.getFile(), 75, 500, null), ImageCompressor.compressImage(imageResizeInput.getFile(), 75, 250, 500), @@ -145,7 +148,7 @@ public void testImageResizeFromCompressor() throws IOException { Files.write(outputPaths.get(i), resizes.get(i)); } - long initialFileSize = Files.size(Paths.get("src/test/resources/file_types/receipt.jpg")); + long initialFileSize = Files.size(testFilePath); List resizedFileSizes = outputPaths.stream() .map(path -> { try { @@ -178,8 +181,8 @@ public void testImageResizeFromCompressor() throws IOException { @Test public void testPdfResizeFromInputSource() throws IOException { - Path outputDir = Paths.get("src/test/resources/output"); - Path inputPath = Paths.get("src/test/resources/products/invoice_splitter/default_sample.pdf"); + Path outputDir = getResourcePath("output"); + Path inputPath = getV1ResourcePath("products/invoice_splitter/default_sample.pdf"); Path outputPath = outputDir.resolve("resize_indirect.pdf"); LocalInputSource pdfResizeInput = new LocalInputSource(inputPath.toString()); @@ -198,8 +201,8 @@ public void testPdfResizeFromInputSource() throws IOException { @Test public void testPdfResizeFromCompressor() throws IOException { - Path outputDir = Paths.get("src/test/resources/output"); - Path inputPath = Paths.get("src/test/resources/products/invoice_splitter/default_sample.pdf"); + Path outputDir = getResourcePath("output"); + Path inputPath = getV1ResourcePath("products/invoice_splitter/default_sample.pdf"); LocalInputSource pdfResizeInput = new LocalInputSource(inputPath.toString()); List resizes = Arrays.asList( @@ -255,7 +258,7 @@ public void testPdfResizeFromCompressor() throws IOException { @Test public void testPdfResizeWithTextKeepsText() throws IOException { - Path inputPath = Paths.get("src/test/resources/file_types/pdf/multipage.pdf"); + Path inputPath = getResourcePath("file_types/pdf/multipage.pdf"); LocalInputSource initialWithText = new LocalInputSource(inputPath.toString()); byte[] compressedWithText = PdfCompressor.compressPdf(initialWithText.getFile(), 100, true, false); diff --git a/src/test/java/com/mindee/input/LocalInputSourceTest.java b/src/test/java/com/mindee/input/LocalInputSourceTest.java index c72de8475..3daa237d1 100644 --- a/src/test/java/com/mindee/input/LocalInputSourceTest.java +++ b/src/test/java/com/mindee/input/LocalInputSourceTest.java @@ -4,12 +4,17 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; + import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class LocalInputSourceTest { - void assertMultipagePDF(LocalInputSource inputSource, File file) throws IOException { + void assertMultipagePDF(LocalInputSource inputSource, Path filePath) throws IOException { Assertions.assertNotNull(inputSource); String filename = inputSource.getFilename(); @@ -21,51 +26,51 @@ void assertMultipagePDF(LocalInputSource inputSource, File file) throws IOExcept Assertions.assertTrue(hasSourceText); Assertions.assertEquals(3, numberOfPages); Assertions.assertEquals("multipage_cut-3.pdf", filename); - Assertions.assertArrayEquals(inputSource.getFile(), Files.readAllBytes(file.toPath())); + Assertions.assertArrayEquals(inputSource.getFile(), Files.readAllBytes(filePath)); } @Test void loadPDF_withFile_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/pdf/multipage_cut-3.pdf"); + File file = getResourcePath("file_types/pdf/multipage_cut-3.pdf").toFile(); LocalInputSource localInputSource = new LocalInputSource(file); - assertMultipagePDF(localInputSource, file); + assertMultipagePDF(localInputSource, file.toPath()); } @Test void loadPDF_withInputStream_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/pdf/multipage_cut-3.pdf"); + Path filePath = getResourcePath("file_types/pdf/multipage_cut-3.pdf"); LocalInputSource localInputSource = new LocalInputSource( - Files.newInputStream(file.toPath()), + Files.newInputStream(filePath), "multipage_cut-3.pdf" ); - assertMultipagePDF(localInputSource, file); + assertMultipagePDF(localInputSource, filePath); } @Test void loadPDF_withByteArray_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/pdf/multipage_cut-3.pdf"); + Path filePath = getResourcePath("file_types/pdf/multipage_cut-3.pdf"); LocalInputSource localInputSource = new LocalInputSource( - Files.readAllBytes(file.toPath()), + Files.readAllBytes(filePath), "multipage_cut-3.pdf" ); - assertMultipagePDF(localInputSource, file); + assertMultipagePDF(localInputSource, filePath); } @Test void loadPDF_withBase64Encoded_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/pdf/multipage_cut-3.pdf"); - String encodedFile = Base64.encodeBase64String(Files.readAllBytes(file.toPath())); + Path filePath = getResourcePath("file_types/pdf/multipage_cut-3.pdf"); + String encodedFile = Base64.encodeBase64String(Files.readAllBytes(filePath)); LocalInputSource localInputSource = new LocalInputSource( encodedFile, "multipage_cut-3.pdf" ); - assertMultipagePDF(localInputSource, file); + assertMultipagePDF(localInputSource, filePath); } @Test void loadPDF__withoutText_mustNotDetectSourceText() throws MindeeException, IOException { - File file = new File("src/test/resources/products/invoice_splitter/default_sample.pdf"); - String encodedFile = Base64.encodeBase64String(Files.readAllBytes(file.toPath())); + Path filePath = getV1ResourcePath("products/invoice_splitter/default_sample.pdf"); + String encodedFile = Base64.encodeBase64String(Files.readAllBytes(filePath)); LocalInputSource localInputSource = new LocalInputSource( encodedFile, "default_sample.pdf" @@ -75,7 +80,7 @@ void loadPDF__withoutText_mustNotDetectSourceText() throws MindeeException, IOEx Assertions.assertFalse(localInputSource.hasSourceText()); } - void assertImage(LocalInputSource inputSource, File file) throws IOException { + void assertImage(LocalInputSource inputSource, Path filePath) throws IOException { Assertions.assertNotNull(inputSource); String filename = inputSource.getFilename(); @@ -87,45 +92,45 @@ void assertImage(LocalInputSource inputSource, File file) throws IOException { Assertions.assertFalse(hasSourceText); Assertions.assertEquals(1, numberOfPages); Assertions.assertEquals("receipt.jpg", filename); - Assertions.assertArrayEquals(inputSource.getFile(), Files.readAllBytes(file.toPath())); + Assertions.assertArrayEquals(inputSource.getFile(), Files.readAllBytes(filePath)); } @Test void loadImage_withFile_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/receipt.jpg"); + File file = getResourcePath("file_types/receipt.jpg").toFile(); LocalInputSource localInputSource = new LocalInputSource(file); - assertImage(localInputSource, file); + assertImage(localInputSource, file.toPath()); } @Test void loadImage_withInputStream_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/receipt.jpg"); + Path filePath = getResourcePath("file_types/receipt.jpg"); LocalInputSource localInputSource = new LocalInputSource( - Files.newInputStream(file.toPath()), + Files.newInputStream(filePath), "receipt.jpg" ); - assertImage(localInputSource, file); + assertImage(localInputSource, filePath); } @Test void loadImage_withByteArray_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/receipt.jpg"); + Path filePath = getResourcePath("file_types/receipt.jpg"); LocalInputSource localInputSource = new LocalInputSource( - Files.readAllBytes(file.toPath()), + Files.readAllBytes(filePath), "receipt.jpg" ); - assertImage(localInputSource, file); + assertImage(localInputSource, filePath); } @Test void loadImage_withBase64Encoded_mustReturnAValidLocalInputSource() throws IOException { - File file = new File("src/test/resources/file_types/receipt.jpg"); - String encodedFile = Base64.encodeBase64String(Files.readAllBytes(file.toPath())); + Path filePath = getResourcePath("file_types/receipt.jpg"); + String encodedFile = Base64.encodeBase64String(Files.readAllBytes(filePath)); LocalInputSource localInputSource = new LocalInputSource( encodedFile, "receipt.jpg" ); - assertImage(localInputSource, file); + assertImage(localInputSource, filePath); } } diff --git a/src/test/java/com/mindee/input/LocalResponseTest.java b/src/test/java/com/mindee/input/LocalResponseTest.java index 98053ac3a..55557c1fa 100644 --- a/src/test/java/com/mindee/input/LocalResponseTest.java +++ b/src/test/java/com/mindee/input/LocalResponseTest.java @@ -5,8 +5,12 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; +import static com.mindee.TestingUtilities.getV1ResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + public class LocalResponseTest { /** @@ -18,15 +22,15 @@ public class LocalResponseTest { * Real signature using fake secret key. */ String signature = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"; - + /** * File which the signature applies to. */ - String filePath = "src/test/resources/async/get_completed_empty.json"; + Path filePath = getV1ResourcePath("async/get_completed_empty.json"); @Test void loadDocument_withFile_mustReturnValidLocalResponse() throws IOException { - LocalResponse localResponse = new LocalResponse(new File(this.filePath)); + LocalResponse localResponse = new LocalResponse(new File(this.filePath.toString())); Assertions.assertNotNull(localResponse.getFile()); Assertions.assertFalse(localResponse.isValidHmacSignature( this.secretKey, "invalid signature is invalid") @@ -47,7 +51,7 @@ void loadDocument_withString_mustReturnValidLocalResponse() { @Test void loadDocument_withInputStream_mustReturnValidLocalResponse() throws IOException { LocalResponse localResponse = new LocalResponse( - Files.newInputStream(Paths.get(this.filePath)) + Files.newInputStream(this.filePath) ); Assertions.assertNotNull(localResponse.getFile()); Assertions.assertFalse(localResponse.isValidHmacSignature( diff --git a/src/test/java/com/mindee/input/URLInputSourceIT.java b/src/test/java/com/mindee/input/URLInputSourceIT.java index 5f0c93f8c..9f8ac7651 100644 --- a/src/test/java/com/mindee/input/URLInputSourceIT.java +++ b/src/test/java/com/mindee/input/URLInputSourceIT.java @@ -21,7 +21,7 @@ static void clientSetUp() { @Test public void testURLInputSource_shouldSendApiCall() throws IOException { URLInputSource remoteSource = URLInputSource.builder( - "https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/invoice_5p.pdf?raw=true" + "https://github.com/mindee/client-lib-test-data/blob/main/v1/products/invoice_splitter/invoice_5p.pdf?raw=true" ).build(); remoteSource.fetchFile(); LocalInputSource localSource = remoteSource.toLocalInputSource(); diff --git a/src/test/java/com/mindee/parsing/common/AsyncPredictResponseTest.java b/src/test/java/com/mindee/parsing/common/AsyncPredictResponseTest.java index b8b787206..4f2a828db 100644 --- a/src/test/java/com/mindee/parsing/common/AsyncPredictResponseTest.java +++ b/src/test/java/com/mindee/parsing/common/AsyncPredictResponseTest.java @@ -8,10 +8,13 @@ import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import java.nio.file.Path; + +import static com.mindee.TestingUtilities.getV1ResourcePath; public class AsyncPredictResponseTest { - private AsyncPredictResponse loadAsyncResponse(String filePath) throws IOException { + private AsyncPredictResponse loadAsyncResponse(Path filePath) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); @@ -19,7 +22,7 @@ private AsyncPredictResponse loadAsyncResponse(String filePat AsyncPredictResponse.class, InvoiceSplitterV1.class ); - return objectMapper.readValue(new File(filePath), type); + return objectMapper.readValue(filePath.toFile(), type); } @Test @@ -35,7 +38,7 @@ void whenIssuedTimeNonUTC_deserialized_mustConvertToUTCLocal() throws JsonProces @Test void whenAsyncPost_returnsErrorForbidden_mustBeDeserialized() throws IOException { AsyncPredictResponse response = loadAsyncResponse( - "src/test/resources/async/post_fail_forbidden.json" + getV1ResourcePath("async/post_fail_forbidden.json") ); Assertions.assertNotNull(response); Assertions.assertEquals("failure", response.getApiRequest().getStatus()); @@ -46,7 +49,7 @@ void whenAsyncPost_returnsErrorForbidden_mustBeDeserialized() throws IOException @Test void whenAsyncPost_returnsSuccess_mustBeDeserialized() throws IOException { AsyncPredictResponse response = loadAsyncResponse( - "src/test/resources/async/post_success.json" + getV1ResourcePath("async/post_success.json") ); Assertions.assertNotNull(response); Assertions.assertEquals("success", response.getApiRequest().getStatus()); @@ -60,7 +63,7 @@ void whenAsyncPost_returnsSuccess_mustBeDeserialized() throws IOException { @Test void whenAsyncGet_returnsProcessing_mustBeDeserialized() throws IOException { AsyncPredictResponse response = loadAsyncResponse( - "src/test/resources/async/get_processing.json" + getV1ResourcePath("async/get_processing.json") ); Assertions.assertNotNull(response); Assertions.assertEquals("success", response.getApiRequest().getStatus()); @@ -73,7 +76,7 @@ void whenAsyncGet_returnsProcessing_mustBeDeserialized() throws IOException { @Test void whenAsyncGet_returnsCompleted_mustBeDeserialized() throws IOException { AsyncPredictResponse response = loadAsyncResponse( - "src/test/resources/async/get_completed.json" + getV1ResourcePath("async/get_completed.json") ); Assertions.assertNotNull(response); Assertions.assertEquals("success", response.getApiRequest().getStatus()); @@ -87,7 +90,7 @@ void whenAsyncGet_returnsCompleted_mustBeDeserialized() throws IOException { @Test void whenAsyncGet_returnsJobFailed_mustBeDeserialized() throws IOException { AsyncPredictResponse response = loadAsyncResponse( - "src/test/resources/async/get_failed_job_error.json" + getV1ResourcePath("async/get_failed_job_error.json") ); Assertions.assertNotNull(response); Assertions.assertEquals("success", response.getApiRequest().getStatus()); diff --git a/src/test/java/com/mindee/parsing/common/CropperTest.java b/src/test/java/com/mindee/parsing/common/CropperTest.java index 48b00434a..9b99bc2f0 100644 --- a/src/test/java/com/mindee/parsing/common/CropperTest.java +++ b/src/test/java/com/mindee/parsing/common/CropperTest.java @@ -7,10 +7,11 @@ import com.mindee.product.receipt.ReceiptV5Document; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.File; import java.io.IOException; import java.util.List; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class CropperTest { private List> loadResult() throws IOException { @@ -21,7 +22,7 @@ private List> loadResult() throws IOException { PredictResponse.class, ReceiptV5.class); PredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/extras/cropper/complete.json"), + getV1ResourcePath("extras/cropper/complete.json").toFile(), type); return prediction.getDocument().getInference().getPages(); diff --git a/src/test/java/com/mindee/parsing/common/ErrorTest.java b/src/test/java/com/mindee/parsing/common/ErrorTest.java index 6c0adc3bb..9462d1090 100644 --- a/src/test/java/com/mindee/parsing/common/ErrorTest.java +++ b/src/test/java/com/mindee/parsing/common/ErrorTest.java @@ -6,6 +6,8 @@ import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class ErrorTest { @Test @@ -15,7 +17,7 @@ void given_details_as_object_mustBeDeserialized() throws IOException { objectMapper.findAndRegisterModules(); Error error = objectMapper.readValue( - new File("src/test/resources/errors/with_object_response_in_detail.json"), + getV1ResourcePath("errors/with_object_response_in_detail.json").toFile(), Error.class); Assertions.assertNotNull(error); @@ -32,7 +34,7 @@ void given_details_as_string_mustBeDeserialized() throws IOException { objectMapper.findAndRegisterModules(); Error error = objectMapper.readValue( - new File("src/test/resources/errors/with_string_response_in_detail.json"), + getV1ResourcePath("errors/with_string_response_in_detail.json").toFile(), Error.class); Assertions.assertNotNull(error); diff --git a/src/test/java/com/mindee/parsing/common/FullTextOcrTest.java b/src/test/java/com/mindee/parsing/common/FullTextOcrTest.java index 7d6174ea6..94e5382fc 100644 --- a/src/test/java/com/mindee/parsing/common/FullTextOcrTest.java +++ b/src/test/java/com/mindee/parsing/common/FullTextOcrTest.java @@ -2,17 +2,16 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.mindee.parsing.standard.StringField; import com.mindee.product.internationalid.InternationalIdV2; import com.mindee.product.internationalid.InternationalIdV2Document; -import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class FullTextOcrTest { private Inference loadInference() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); @@ -22,7 +21,7 @@ private Inference loadInfe AsyncPredictResponse.class, InternationalIdV2.class); AsyncPredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/extras/full_text_ocr/complete.json"), + getV1ResourcePath("extras/full_text_ocr/complete.json").toFile(), type); return prediction.getDocumentObj().getInference(); @@ -36,7 +35,7 @@ private List> loadPages() throws IOException { AsyncPredictResponse.class, InternationalIdV2.class); AsyncPredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/extras/full_text_ocr/complete.json"), + getV1ResourcePath("extras/full_text_ocr/complete.json").toFile(), type); return prediction.getDocumentObj().getInference().getPages(); @@ -44,8 +43,9 @@ private List> loadPages() throws IOException { @Test void should_GetFullTextOcrResult() throws IOException { - List expectedText = Files - .readAllLines(Paths.get("src/test/resources/extras/full_text_ocr/full_text_ocr.txt")); + List expectedText = Files.readAllLines( + getV1ResourcePath("extras/full_text_ocr/full_text_ocr.txt") + ); List> pages = loadPages(); Inference inference = loadInference(); String fullTextOcr = inference.getExtras().getFullTextOcr(); diff --git a/src/test/java/com/mindee/parsing/common/OcrTest.java b/src/test/java/com/mindee/parsing/common/OcrTest.java index 3a9cd261a..e8b0df446 100644 --- a/src/test/java/com/mindee/parsing/common/OcrTest.java +++ b/src/test/java/com/mindee/parsing/common/OcrTest.java @@ -13,6 +13,8 @@ import java.nio.file.Paths; import java.util.List; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class OcrTest { private Ocr loadResult() throws IOException { @@ -23,7 +25,7 @@ private Ocr loadResult() throws IOException { PredictResponse.class, ReceiptV5.class); PredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/extras/ocr/complete.json"), + getV1ResourcePath("extras/ocr/complete.json").toFile(), type); return prediction.getDocument().getOcr(); @@ -51,8 +53,9 @@ void whenDeserializedToString_shouldBeOrdered() throws IOException { Ocr ocr = loadResult(); - List expectedLines = Files - .readAllLines(Paths.get("src/test/resources/extras/ocr/ocr.txt")); + List expectedLines = Files.readAllLines( + getV1ResourcePath("extras/ocr/ocr.txt") + ); String expectedSummary = String.join(String.format("%n"), expectedLines); Assertions.assertEquals(expectedSummary, ocr.toString(), "Should match expected string exactly."); diff --git a/src/test/java/com/mindee/parsing/common/WorkflowResponseTest.java b/src/test/java/com/mindee/parsing/common/WorkflowResponseTest.java deleted file mode 100644 index 6f5856f37..000000000 --- a/src/test/java/com/mindee/parsing/common/WorkflowResponseTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mindee.parsing.common; - -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mindee.product.invoicesplitter.InvoiceSplitterV1; -import java.io.File; -import java.io.IOException; - -public class WorkflowResponseTest { - private WorkflowResponse loadWorkflowResponse(String filePath) throws - IOException { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.findAndRegisterModules(); - - JavaType type = objectMapper.getTypeFactory().constructParametricType( - WorkflowResponse.class, - InvoiceSplitterV1.class - ); - return objectMapper.readValue(new File(filePath), type); - } -} diff --git a/src/test/java/com/mindee/parsing/v2/InferenceTest.java b/src/test/java/com/mindee/parsing/v2/InferenceTest.java index 456239d29..fa448a88d 100644 --- a/src/test/java/com/mindee/parsing/v2/InferenceTest.java +++ b/src/test/java/com/mindee/parsing/v2/InferenceTest.java @@ -27,7 +27,9 @@ class InferenceTest { private InferenceResponse loadFromResource(String resourcePath) throws IOException { - LocalResponse localResponse = new LocalResponse(InferenceTest.class.getClassLoader().getResourceAsStream(resourcePath)); + LocalResponse localResponse = new LocalResponse( + InferenceTest.class.getClassLoader().getResourceAsStream(resourcePath) + ); return localResponse.deserializeResponse(InferenceResponse.class); } diff --git a/src/test/java/com/mindee/pdf/PDFUtilsTest.java b/src/test/java/com/mindee/pdf/PDFUtilsTest.java index 62f52f397..433d3d371 100644 --- a/src/test/java/com/mindee/pdf/PDFUtilsTest.java +++ b/src/test/java/com/mindee/pdf/PDFUtilsTest.java @@ -17,6 +17,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static com.mindee.TestingUtilities.getResourcePath; + public class PDFUtilsTest { @@ -30,7 +32,7 @@ public void givenADocument_whenPageCounted_thenReturnsCorrectPageCount() throws } document.save("src/test/resources/output/test.pdf"); document.close(); - File file = new File("src/test/resources/output/test.pdf"); + File file = getResourcePath("output/test.pdf").toFile(); LocalInputSource source = new LocalInputSource(file); Assertions.assertEquals(random, PDFUtils.getNumberOfPages(source)); file.delete(); @@ -42,7 +44,7 @@ public void givenADocumentAndListOfPages_whenMerged_thenReturnsCorrectDocument() Path original = Paths.get("src/test/resources/file_types/pdf/multipage.pdf"); Path copied = Paths.get("src/test/resources/output/fileToTest.pdf"); Files.copy(original, copied, StandardCopyOption.REPLACE_EXISTING); - File file = new File("src/test/resources/output/fileToTest.pdf"); + File file = getResourcePath("output/fileToTest.pdf").toFile(); List pageList = Arrays.asList(0, 2, 3, 1, 10, 2, 1); byte[] newPdf = PDFUtils.mergePdfPages(file, pageList); PDDocument document = Loader.loadPDF(newPdf); @@ -54,7 +56,7 @@ public void givenADocumentAndListOfPages_whenMerged_thenReturnsCorrectDocument() @Test public void givenANonEmptyDocument_whenEmptyChecked_shouldReturnFalse() throws IOException { - File pdfFile = new File("src/test/resources/file_types/pdf/multipage.pdf"); + File pdfFile = getResourcePath("file_types/pdf/multipage.pdf").toFile(); Assertions.assertFalse(PDFUtils.isPdfEmpty(pdfFile)); } @@ -68,7 +70,7 @@ public void givenAnEmptyDocument_whenEmptyChecked_shouldReturnTrue() throws IOEx } document.save("src/test/resources/output/test.pdf"); document.close(); - File file = new File("src/test/resources/output/test.pdf"); + File file = getResourcePath("output/test.pdf").toFile(); Assertions.assertTrue(PDFUtils.isPdfEmpty(file)); file.delete(); } diff --git a/src/test/java/com/mindee/pdf/PdfOperationTest.java b/src/test/java/com/mindee/pdf/PdfOperationTest.java index e8027f546..0d4ad8e2b 100644 --- a/src/test/java/com/mindee/pdf/PdfOperationTest.java +++ b/src/test/java/com/mindee/pdf/PdfOperationTest.java @@ -6,12 +6,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import static com.mindee.TestingUtilities.getResourcePath; + public class PdfOperationTest { @@ -27,8 +28,8 @@ public void givenADocumentAndPageToKeep_whenSplit_thenReturnsOnlyKeptPage() .build(); byte[] fileBytes = Files.readAllBytes( - new File("src/test/resources/file_types/pdf/multipage.pdf").toPath()); - + getResourcePath("file_types/pdf/multipage.pdf") + ); SplitQuery splitQuery = new SplitQuery(fileBytes, pageOptions); SplitPdf splitPdf = pdfOperation.split(splitQuery); @@ -51,7 +52,7 @@ public void givenADocumentAndListOfPagesToKeep_whenSplit_thenReturnsOnlyKeptPage .build(); SplitQuery splitQuery = new SplitQuery( - Files.readAllBytes(new File("src/test/resources/file_types/pdf/multipage.pdf").toPath()), + Files.readAllBytes(getResourcePath("file_types/pdf/multipage.pdf")), pageOptions ); SplitPdf splitPdf = pdfOperation.split(splitQuery); @@ -71,7 +72,7 @@ public void givenADocumentAndListOfPagesToRemove_whenSplit_thenReturnsOnlyNotRem .build(); SplitQuery splitQuery = new SplitQuery( - Files.readAllBytes(new File("src/test/resources/file_types/pdf/multipage.pdf").toPath()), + Files.readAllBytes(getResourcePath("file_types/pdf/multipage.pdf")), pageOptions ); SplitPdf splitPdf = pdfOperation.split(splitQuery); @@ -91,7 +92,7 @@ public void givenADocumentOtherThantAPdf_whenSplit_mustFail() .build(); SplitQuery splitQuery = new SplitQuery( - Files.readAllBytes(new File("src/test/resources/file_types/receipt.jpg").toPath()), + Files.readAllBytes(getResourcePath("file_types/receipt.jpg")), pageOptions ); @@ -111,7 +112,7 @@ public void givenADocumentAndListPagesToRemoveAndMinPagesCondition_whenSplit_mus .build(); SplitQuery splitQuery = new SplitQuery( - Files.readAllBytes(new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf").toPath()), + Files.readAllBytes(getResourcePath("file_types/pdf/multipage_cut-2.pdf")), pageOptions ); SplitPdf splitPdf = pdfOperation.split(splitQuery); @@ -131,7 +132,7 @@ public void givenADocumentAndNegativeListPagesToKeep_whenSplit_thenReturnsOnlyKe .build(); SplitQuery splitQuery = new SplitQuery( - Files.readAllBytes(new File("src/test/resources/file_types/pdf/multipage.pdf").toPath()), + Files.readAllBytes(getResourcePath("file_types/pdf/multipage.pdf")), pageOptions ); SplitPdf splitPdf = pdfOperation.split(splitQuery); diff --git a/src/test/java/com/mindee/product/ProductTestHelper.java b/src/test/java/com/mindee/product/ProductTestHelper.java deleted file mode 100644 index 2ad8c761e..000000000 --- a/src/test/java/com/mindee/product/ProductTestHelper.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mindee.product; - -import org.junit.jupiter.api.Assertions; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; - -public class ProductTestHelper { - - public static void assertStringEqualsFile(String expected, String filePath) throws IOException { - String[] actualLines = expected.split(System.lineSeparator()); - List expectedLines = Files.readAllLines(Paths.get(filePath)); - String expectedSummary = String.join(String.format("%n"), expectedLines); - String actualSummary = String.join(String.format("%n"), actualLines); - - Assertions.assertEquals(expectedSummary, actualSummary); - } -} diff --git a/src/test/java/com/mindee/product/barcodereader/BarcodeReaderV1Test.java b/src/test/java/com/mindee/product/barcodereader/BarcodeReaderV1Test.java index 36ca30dca..bb1a005df 100644 --- a/src/test/java/com/mindee/product/barcodereader/BarcodeReaderV1Test.java +++ b/src/test/java/com/mindee/product/barcodereader/BarcodeReaderV1Test.java @@ -4,13 +4,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; -import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; +import static com.mindee.TestingUtilities.assertStringEqualsFile; + /** * Unit tests for BarcodeReaderV1. */ @@ -25,7 +26,7 @@ protected PredictResponse getPrediction(String name) throws IOE BarcodeReaderV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/barcode_reader/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/barcode_reader/response_v1/" + name + ".json")), type ); } @@ -42,9 +43,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/barcode_reader/response_v1/summary_full.rst" + getV1ResourcePathString("products/barcode_reader/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java b/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java index 44f4070b3..e7da3ec0f 100644 --- a/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java +++ b/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java @@ -4,13 +4,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; -import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for BillOfLadingV1. */ @@ -25,7 +26,7 @@ protected PredictResponse getPrediction(String name) throws IOEx BillOfLadingV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/bill_of_lading/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/bill_of_lading/response_v1/" + name + ".json")), type ); } @@ -62,9 +63,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/bill_of_lading/response_v1/summary_full.rst" + getV1ResourcePathString("products/bill_of_lading/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/businesscard/BusinessCardV1Test.java b/src/test/java/com/mindee/product/businesscard/BusinessCardV1Test.java index dca6cf157..c85a003e8 100644 --- a/src/test/java/com/mindee/product/businesscard/BusinessCardV1Test.java +++ b/src/test/java/com/mindee/product/businesscard/BusinessCardV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for BusinessCardV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOEx BusinessCardV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/business_card/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/business_card/response_v1/" + name + ".json")), type ); } @@ -51,9 +53,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/business_card/response_v1/summary_full.rst" + getV1ResourcePathString("products/business_card/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/cropper/CropperV1Test.java b/src/test/java/com/mindee/product/cropper/CropperV1Test.java index b8b309a23..35b127aed 100644 --- a/src/test/java/com/mindee/product/cropper/CropperV1Test.java +++ b/src/test/java/com/mindee/product/cropper/CropperV1Test.java @@ -6,12 +6,14 @@ import com.mindee.parsing.common.Page; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for CropperV1. */ @@ -26,7 +28,7 @@ protected PredictResponse getPrediction(String name) throws IOExcepti CropperV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/cropper/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/cropper/response_v1/" + name + ".json")), type ); } @@ -42,9 +44,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/cropper/response_v1/summary_full.rst" + getV1ResourcePathString("products/cropper/response_v1/summary_full.rst") ); } @@ -52,9 +54,9 @@ void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException { PredictResponse response = getPrediction("complete"); Page page = response.getDocument().getInference().getPages().get(0); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( page.toString(), - "src/test/resources/products/cropper/response_v1/summary_page0.rst" + getV1ResourcePathString("products/cropper/response_v1/summary_page0.rst") ); } } diff --git a/src/test/java/com/mindee/product/custom/CustomV1Test.java b/src/test/java/com/mindee/product/custom/CustomV1Test.java index ec984a901..04c1e6d11 100644 --- a/src/test/java/com/mindee/product/custom/CustomV1Test.java +++ b/src/test/java/com/mindee/product/custom/CustomV1Test.java @@ -7,13 +7,15 @@ import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.custom.ListField; import com.mindee.parsing.custom.ListFieldValue; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; import java.util.Map; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + class CustomV1Test { protected PredictResponse getPrediction(String name) throws IOException { @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExceptio CustomV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/custom/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/custom/response_v1/" + name + ".json")), type ); } @@ -74,9 +76,9 @@ void whenCompleteDeserialized_mustHaveValidPageId() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/custom/response_v1/summary_full.rst" + getV1ResourcePathString("products/custom/response_v1/summary_full.rst") ); } @@ -84,9 +86,9 @@ void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException { PredictResponse response = getPrediction("complete"); Page page = response.getDocument().getInference().getPages().get(0); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( page.toString(), - "src/test/resources/products/custom/response_v1/summary_page0.rst" + getV1ResourcePathString("products/custom/response_v1/summary_page0.rst") ); } } diff --git a/src/test/java/com/mindee/product/custom/CustomV1WithLineItemsTest.java b/src/test/java/com/mindee/product/custom/CustomV1WithLineItemsTest.java index 8bf3dfcba..685026da5 100644 --- a/src/test/java/com/mindee/product/custom/CustomV1WithLineItemsTest.java +++ b/src/test/java/com/mindee/product/custom/CustomV1WithLineItemsTest.java @@ -14,6 +14,8 @@ import java.io.IOException; import java.util.Arrays; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + class CustomV1WithLineItemsTest { @Test @@ -25,7 +27,7 @@ void givenACustomDocument_expected_3_lines() throws IOException { JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, CustomV1.class); PredictResponse response = objectMapper.readValue( - new File("src/test/resources/products/custom/response_v1/line_items/single_table_01.json"), + new File(getV1ResourcePathString("products/custom/response_v1/line_items/single_table_01.json")), type); LineItems lineItems = LineItemsGenerator.generate( diff --git a/src/test/java/com/mindee/product/deliverynote/DeliveryNoteV1Test.java b/src/test/java/com/mindee/product/deliverynote/DeliveryNoteV1Test.java index 8653d2160..21ecd105a 100644 --- a/src/test/java/com/mindee/product/deliverynote/DeliveryNoteV1Test.java +++ b/src/test/java/com/mindee/product/deliverynote/DeliveryNoteV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for DeliveryNoteV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOEx DeliveryNoteV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/delivery_notes/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/delivery_notes/response_v1/" + name + ".json")), type ); } @@ -47,9 +49,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/delivery_notes/response_v1/summary_full.rst" + getV1ResourcePathString("products/delivery_notes/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/driverlicense/DriverLicenseV1Test.java b/src/test/java/com/mindee/product/driverlicense/DriverLicenseV1Test.java index ae0de6f70..2b06b50b5 100644 --- a/src/test/java/com/mindee/product/driverlicense/DriverLicenseV1Test.java +++ b/src/test/java/com/mindee/product/driverlicense/DriverLicenseV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for DriverLicenseV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOE DriverLicenseV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/driver_license/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/driver_license/response_v1/" + name + ".json")), type ); } @@ -53,9 +55,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/driver_license/response_v1/summary_full.rst" + getV1ResourcePathString("products/driver_license/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/financialdocument/FinancialDocumentV1Test.java b/src/test/java/com/mindee/product/financialdocument/FinancialDocumentV1Test.java index cd27c6fb7..7a377a51c 100644 --- a/src/test/java/com/mindee/product/financialdocument/FinancialDocumentV1Test.java +++ b/src/test/java/com/mindee/product/financialdocument/FinancialDocumentV1Test.java @@ -12,6 +12,9 @@ import java.nio.file.Paths; import java.util.List; +import static com.mindee.TestingUtilities.getV1ResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + class FinancialDocumentV1Test { @Test @@ -23,12 +26,12 @@ void givenFinancialV1_withInvoice_whenDeserialized_MustHaveAValidSummary() throw JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, FinancialDocumentV1.class); PredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/products/financial_document/response_v1/complete_invoice.json"), + new File(getV1ResourcePathString("products/financial_document/response_v1/complete_invoice.json")), type); String[] actualLines = prediction.getDocument().toString().split(System.lineSeparator()); List expectedLines = Files - .readAllLines(Paths.get("src/test/resources/products/financial_document/response_v1/summary_full_invoice.rst")); + .readAllLines(getV1ResourcePath("products/financial_document/response_v1/summary_full_invoice.rst")); String expectedSummary = String.join(String.format("%n"), expectedLines); String actualSummary = String.join(String.format("%n"), actualLines); @@ -44,14 +47,15 @@ void givenFinancialV1_withInvoice_firstPage_MustHaveAValidSummary() throws IOExc JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, FinancialDocumentV1.class); PredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/products/financial_document/response_v1/complete_invoice.json"), + new File(getV1ResourcePathString("products/financial_document/response_v1/complete_invoice.json")), type); String[] actualLines = prediction.getDocument().getInference() .getPages() .get(0).toString().split(System.lineSeparator()); - List expectedLines = Files - .readAllLines(Paths.get("src/test/resources/products/financial_document/response_v1/summary_page0_invoice.rst")); + List expectedLines = Files.readAllLines( + getV1ResourcePath("products/financial_document/response_v1/summary_page0_invoice.rst") + ); String expectedSummary = String.join(String.format("%n"), expectedLines); String actualSummary = String.join(String.format("%n"), actualLines); @@ -67,12 +71,12 @@ void givenFinancialV1_withReceipt_whenDeserialized_MustHaveAValidSummary() throw JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, FinancialDocumentV1.class); PredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/products/financial_document/response_v1/complete_receipt.json"), + new File(getV1ResourcePathString("products/financial_document/response_v1/complete_receipt.json")), type); String[] actualLines = prediction.getDocument().toString().split(System.lineSeparator()); List expectedLines = Files - .readAllLines(Paths.get("src/test/resources/products/financial_document/response_v1/summary_full_receipt.rst")); + .readAllLines(getV1ResourcePath("products/financial_document/response_v1/summary_full_receipt.rst")); String expectedSummary = String.join(String.format("%n"), expectedLines); String actualSummary = String.join(String.format("%n"), actualLines); @@ -88,14 +92,14 @@ void givenFinancialV1_withReceipt_firstPage_MustHaveAValidSummary() throws IOExc JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, FinancialDocumentV1.class); PredictResponse prediction = objectMapper.readValue( - new File("src/test/resources/products/financial_document/response_v1/complete_receipt.json"), + new File(getV1ResourcePathString("products/financial_document/response_v1/complete_receipt.json")), type); String[] actualLines = prediction.getDocument().getInference() .getPages() .get(0).toString().split(System.lineSeparator()); List expectedLines = Files - .readAllLines(Paths.get("src/test/resources/products/financial_document/response_v1/summary_page0_receipt.rst")); + .readAllLines(getV1ResourcePath("products/financial_document/response_v1/summary_page0_receipt.rst")); String expectedSummary = String.join(String.format("%n"), expectedLines); String actualSummary = String.join(String.format("%n"), actualLines); @@ -109,7 +113,7 @@ void givenFinancialV1_withEmptyDocument_whenDeserialized_MustHaveExpectedValues( JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, FinancialDocumentV1.class); PredictResponse response = objectMapper.readValue( - new File("src/test/resources/products/financial_document/response_v1/empty.json"), + new File(getV1ResourcePathString("products/financial_document/response_v1/empty.json")), type); Document doc = response.getDocument(); diff --git a/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV1Test.java b/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV1Test.java index 5a21996af..056121529 100644 --- a/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV1Test.java +++ b/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for BankAccountDetailsV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throw BankAccountDetailsV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/bank_account_details/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/bank_account_details/response_v1/" + name + ".json")), type ); } @@ -43,9 +45,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/bank_account_details/response_v1/summary_full.rst" + getV1ResourcePathString("products/bank_account_details/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV2Test.java b/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV2Test.java index ed2b5730e..792977c69 100644 --- a/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV2Test.java +++ b/src/test/java/com/mindee/product/fr/bankaccountdetails/BankAccountDetailsV2Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for BankAccountDetailsV2. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throw BankAccountDetailsV2.class ); return objectMapper.readValue( - new File("src/test/resources/products/bank_account_details/response_v2/" + name + ".json"), + new File(getV1ResourcePathString("products/bank_account_details/response_v2/" + name + ".json")), type ); } @@ -47,9 +49,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/bank_account_details/response_v2/summary_full.rst" + getV1ResourcePathString("products/bank_account_details/response_v2/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/fr/cartegrise/CarteGriseV1Test.java b/src/test/java/com/mindee/product/fr/cartegrise/CarteGriseV1Test.java index eac2bacbd..cadb3bf57 100644 --- a/src/test/java/com/mindee/product/fr/cartegrise/CarteGriseV1Test.java +++ b/src/test/java/com/mindee/product/fr/cartegrise/CarteGriseV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for CarteGriseV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExce CarteGriseV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/carte_grise/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/carte_grise/response_v1/" + name + ".json")), type ); } @@ -81,9 +83,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/carte_grise/response_v1/summary_full.rst" + getV1ResourcePathString("products/carte_grise/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java b/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java index 4ab08dc63..b7ee102db 100644 --- a/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java +++ b/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for EnergyBillV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExce EnergyBillV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/energy_bill_fra/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/energy_bill_fra/response_v1/" + name + ".json")), type ); } @@ -58,9 +60,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/energy_bill_fra/response_v1/summary_full.rst" + getV1ResourcePathString("products/energy_bill_fra/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/fr/healthcard/HealthCardV1Test.java b/src/test/java/com/mindee/product/fr/healthcard/HealthCardV1Test.java index 014049a06..1171d1c41 100644 --- a/src/test/java/com/mindee/product/fr/healthcard/HealthCardV1Test.java +++ b/src/test/java/com/mindee/product/fr/healthcard/HealthCardV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for HealthCardV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExce HealthCardV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/french_healthcard/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/french_healthcard/response_v1/" + name + ".json")), type ); } @@ -44,9 +46,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/french_healthcard/response_v1/summary_full.rst" + getV1ResourcePathString("products/french_healthcard/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/fr/idcard/IdCardV1Test.java b/src/test/java/com/mindee/product/fr/idcard/IdCardV1Test.java index 2c530249f..66bdd7493 100644 --- a/src/test/java/com/mindee/product/fr/idcard/IdCardV1Test.java +++ b/src/test/java/com/mindee/product/fr/idcard/IdCardV1Test.java @@ -6,12 +6,14 @@ import com.mindee.parsing.common.Page; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for IdCardV1. */ @@ -26,7 +28,7 @@ protected PredictResponse getPrediction(String name) throws IOExceptio IdCardV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/idcard_fr/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/idcard_fr/response_v1/" + name + ".json")), type ); } @@ -53,9 +55,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/idcard_fr/response_v1/summary_full.rst" + getV1ResourcePathString("products/idcard_fr/response_v1/summary_full.rst") ); } @@ -63,9 +65,9 @@ void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException { PredictResponse response = getPrediction("complete"); Page page = response.getDocument().getInference().getPages().get(0); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( page.toString(), - "src/test/resources/products/idcard_fr/response_v1/summary_page0.rst" + getV1ResourcePathString("products/idcard_fr/response_v1/summary_page0.rst") ); } } diff --git a/src/test/java/com/mindee/product/fr/idcard/IdCardV2Test.java b/src/test/java/com/mindee/product/fr/idcard/IdCardV2Test.java index 2b71ee578..473ed7eb2 100644 --- a/src/test/java/com/mindee/product/fr/idcard/IdCardV2Test.java +++ b/src/test/java/com/mindee/product/fr/idcard/IdCardV2Test.java @@ -6,12 +6,14 @@ import com.mindee.parsing.common.Page; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for IdCardV2. */ @@ -26,7 +28,7 @@ protected PredictResponse getPrediction(String name) throws IOExceptio IdCardV2.class ); return objectMapper.readValue( - new File("src/test/resources/products/idcard_fr/response_v2/" + name + ".json"), + new File(getV1ResourcePathString("products/idcard_fr/response_v2/" + name + ".json")), type ); } @@ -59,9 +61,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/idcard_fr/response_v2/summary_full.rst" + getV1ResourcePathString("products/idcard_fr/response_v2/summary_full.rst") ); } @@ -69,9 +71,9 @@ void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException { PredictResponse response = getPrediction("complete"); Page page = response.getDocument().getInference().getPages().get(0); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( page.toString(), - "src/test/resources/products/idcard_fr/response_v2/summary_page0.rst" + getV1ResourcePathString("products/idcard_fr/response_v2/summary_page0.rst") ); } } diff --git a/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java b/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java index c751eb46d..fe88d2608 100644 --- a/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java +++ b/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for PayslipV2. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExcepti PayslipV2.class ); return objectMapper.readValue( - new File("src/test/resources/products/payslip_fra/response_v2/" + name + ".json"), + new File(getV1ResourcePathString("products/payslip_fra/response_v2/" + name + ".json")), type ); } @@ -82,9 +84,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/payslip_fra/response_v2/summary_full.rst" + getV1ResourcePathString("products/payslip_fra/response_v2/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/fr/payslip/PayslipV3Test.java b/src/test/java/com/mindee/product/fr/payslip/PayslipV3Test.java index 76c1c34b5..8a4c973d8 100644 --- a/src/test/java/com/mindee/product/fr/payslip/PayslipV3Test.java +++ b/src/test/java/com/mindee/product/fr/payslip/PayslipV3Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for PayslipV3. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExcepti PayslipV3.class ); return objectMapper.readValue( - new File("src/test/resources/products/payslip_fra/response_v3/" + name + ".json"), + new File(getV1ResourcePathString("products/payslip_fra/response_v3/" + name + ".json")), type ); } @@ -81,9 +83,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/payslip_fra/response_v3/summary_full.rst" + getV1ResourcePathString("products/payslip_fra/response_v3/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/generated/GeneratedV1Test.java b/src/test/java/com/mindee/product/generated/GeneratedV1Test.java index eb2e46d79..da28e1f46 100644 --- a/src/test/java/com/mindee/product/generated/GeneratedV1Test.java +++ b/src/test/java/com/mindee/product/generated/GeneratedV1Test.java @@ -19,6 +19,8 @@ import java.util.Map; import java.util.Objects; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + public class GeneratedV1Test { protected AsyncPredictResponse getAsyncPrediction(String name) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); @@ -29,7 +31,7 @@ protected AsyncPredictResponse getAsyncPrediction(String name) thro GeneratedV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/generated/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/generated/response_v1/" + name + ".json")), type ); } @@ -43,7 +45,7 @@ protected AsyncPredictResponse getUsMailPrediction() throws IOExcep GeneratedV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/us_mail/response_v3/complete.json"), + new File(getV1ResourcePathString("products/us_mail/response_v3/complete.json")), type ); } @@ -57,7 +59,7 @@ protected PredictResponse getSyncPrediction(String name) throws IOE GeneratedV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/generated/response_v1/" + name + "_invoice_v4.json"), + new File(getV1ResourcePathString("products/generated/response_v1/" + name + "_invoice_v4.json")), type ); } diff --git a/src/test/java/com/mindee/product/ind/indianpassport/IndianPassportV1Test.java b/src/test/java/com/mindee/product/ind/indianpassport/IndianPassportV1Test.java index 0383bd699..6c11bd93e 100644 --- a/src/test/java/com/mindee/product/ind/indianpassport/IndianPassportV1Test.java +++ b/src/test/java/com/mindee/product/ind/indianpassport/IndianPassportV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for IndianPassportV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IO IndianPassportV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/ind_passport/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/ind_passport/response_v1/" + name + ".json")), type ); } @@ -63,9 +65,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/ind_passport/response_v1/summary_full.rst" + getV1ResourcePathString("products/ind_passport/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/internationalid/InternationalIdV2Test.java b/src/test/java/com/mindee/product/internationalid/InternationalIdV2Test.java index faedd2527..b6998950b 100644 --- a/src/test/java/com/mindee/product/internationalid/InternationalIdV2Test.java +++ b/src/test/java/com/mindee/product/internationalid/InternationalIdV2Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for InternationalIdV2. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws I InternationalIdV2.class ); return objectMapper.readValue( - new File("src/test/resources/products/international_id/response_v2/" + name + ".json"), + new File(getV1ResourcePathString("products/international_id/response_v2/" + name + ".json")), type ); } @@ -57,9 +59,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/international_id/response_v2/summary_full.rst" + getV1ResourcePathString("products/international_id/response_v2/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/invoice/InvoiceV4Test.java b/src/test/java/com/mindee/product/invoice/InvoiceV4Test.java index 16a789870..27b0482ca 100644 --- a/src/test/java/com/mindee/product/invoice/InvoiceV4Test.java +++ b/src/test/java/com/mindee/product/invoice/InvoiceV4Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for InvoiceV4. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExcepti InvoiceV4.class ); return objectMapper.readValue( - new File("src/test/resources/products/invoices/response_v4/" + name + ".json"), + new File(getV1ResourcePathString("products/invoices/response_v4/" + name + ".json")), type ); } @@ -69,9 +71,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/invoices/response_v4/summary_full.rst" + getV1ResourcePathString("products/invoices/response_v4/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/invoicesplitter/InvoiceSplitterV1Test.java b/src/test/java/com/mindee/product/invoicesplitter/InvoiceSplitterV1Test.java index 3d0a1759e..ec601e93b 100644 --- a/src/test/java/com/mindee/product/invoicesplitter/InvoiceSplitterV1Test.java +++ b/src/test/java/com/mindee/product/invoicesplitter/InvoiceSplitterV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for InvoiceSplitterV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws I InvoiceSplitterV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/invoice_splitter/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/invoice_splitter/response_v1/" + name + ".json")), type ); } @@ -41,9 +43,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/invoice_splitter/response_v1/summary_full.rst" + getV1ResourcePathString("products/invoice_splitter/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/multireceiptsdetector/MultiReceiptsDetectorV1Test.java b/src/test/java/com/mindee/product/multireceiptsdetector/MultiReceiptsDetectorV1Test.java index 41d39f1aa..8dd6174fa 100644 --- a/src/test/java/com/mindee/product/multireceiptsdetector/MultiReceiptsDetectorV1Test.java +++ b/src/test/java/com/mindee/product/multireceiptsdetector/MultiReceiptsDetectorV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for MultiReceiptsDetectorV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) th MultiReceiptsDetectorV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/multi_receipts_detector/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/multi_receipts_detector/response_v1/" + name + ".json")), type ); } @@ -41,9 +43,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/multi_receipts_detector/response_v1/summary_full.rst" + getV1ResourcePathString("products/multi_receipts_detector/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java b/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java index 784d332f9..fca4db33c 100644 --- a/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java +++ b/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for NutritionFactsLabelV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) thro NutritionFactsLabelV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/nutrition_facts/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/nutrition_facts/response_v1/" + name + ".json")), type ); } @@ -78,9 +80,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/nutrition_facts/response_v1/summary_full.rst" + getV1ResourcePathString("products/nutrition_facts/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/passport/PassportV1Test.java b/src/test/java/com/mindee/product/passport/PassportV1Test.java index 9acce0ce6..d2f0befc5 100644 --- a/src/test/java/com/mindee/product/passport/PassportV1Test.java +++ b/src/test/java/com/mindee/product/passport/PassportV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for PassportV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExcept PassportV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/passport/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/passport/response_v1/" + name + ".json")), type ); } @@ -51,9 +53,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/passport/response_v1/summary_full.rst" + getV1ResourcePathString("products/passport/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/receipt/ReceiptV5Test.java b/src/test/java/com/mindee/product/receipt/ReceiptV5Test.java index 4b35f6494..ba8ba24e6 100644 --- a/src/test/java/com/mindee/product/receipt/ReceiptV5Test.java +++ b/src/test/java/com/mindee/product/receipt/ReceiptV5Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for ReceiptV5. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExcepti ReceiptV5.class ); return objectMapper.readValue( - new File("src/test/resources/products/expense_receipts/response_v5/" + name + ".json"), + new File(getV1ResourcePathString("products/expense_receipts/response_v5/" + name + ".json")), type ); } @@ -57,9 +59,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/expense_receipts/response_v5/summary_full.rst" + getV1ResourcePathString("products/expense_receipts/response_v5/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/resume/ResumeV1Test.java b/src/test/java/com/mindee/product/resume/ResumeV1Test.java index 9be4ac18a..9df0abf02 100644 --- a/src/test/java/com/mindee/product/resume/ResumeV1Test.java +++ b/src/test/java/com/mindee/product/resume/ResumeV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for ResumeV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExceptio ResumeV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/resume/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/resume/response_v1/" + name + ".json")), type ); } @@ -57,9 +59,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/resume/response_v1/summary_full.rst" + getV1ResourcePathString("products/resume/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/us/bankcheck/BankCheckV1Test.java b/src/test/java/com/mindee/product/us/bankcheck/BankCheckV1Test.java index 6a9556a78..8a39a8296 100644 --- a/src/test/java/com/mindee/product/us/bankcheck/BankCheckV1Test.java +++ b/src/test/java/com/mindee/product/us/bankcheck/BankCheckV1Test.java @@ -6,12 +6,14 @@ import com.mindee.parsing.common.Page; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for BankCheckV1. */ @@ -26,7 +28,7 @@ protected PredictResponse getPrediction(String name) throws IOExcep BankCheckV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/bank_check/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/bank_check/response_v1/" + name + ".json")), type ); } @@ -50,9 +52,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/bank_check/response_v1/summary_full.rst" + getV1ResourcePathString("products/bank_check/response_v1/summary_full.rst") ); } @@ -60,9 +62,9 @@ void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException { PredictResponse response = getPrediction("complete"); Page page = response.getDocument().getInference().getPages().get(0); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( page.toString(), - "src/test/resources/products/bank_check/response_v1/summary_page0.rst" + getV1ResourcePathString("products/bank_check/response_v1/summary_page0.rst") ); } } diff --git a/src/test/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Test.java b/src/test/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Test.java index 613225f61..3c15f9097 100644 --- a/src/test/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Test.java +++ b/src/test/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for HealthcareCardV1. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IO HealthcareCardV1.class ); return objectMapper.readValue( - new File("src/test/resources/products/us_healthcare_cards/response_v1/" + name + ".json"), + new File(getV1ResourcePathString("products/us_healthcare_cards/response_v1/" + name + ".json")), type ); } @@ -54,9 +56,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/us_healthcare_cards/response_v1/summary_full.rst" + getV1ResourcePathString("products/us_healthcare_cards/response_v1/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/product/us/usmail/UsMailV3Test.java b/src/test/java/com/mindee/product/us/usmail/UsMailV3Test.java index 5a6168b48..67e772dc4 100644 --- a/src/test/java/com/mindee/product/us/usmail/UsMailV3Test.java +++ b/src/test/java/com/mindee/product/us/usmail/UsMailV3Test.java @@ -5,12 +5,14 @@ import com.mindee.parsing.common.Document; import com.mindee.parsing.common.PredictResponse; import com.mindee.parsing.standard.ClassificationField; -import com.mindee.product.ProductTestHelper; +import static com.mindee.TestingUtilities.assertStringEqualsFile; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; +import static com.mindee.TestingUtilities.getV1ResourcePathString; + /** * Unit tests for UsMailV3. */ @@ -25,7 +27,7 @@ protected PredictResponse getPrediction(String name) throws IOExceptio UsMailV3.class ); return objectMapper.readValue( - new File("src/test/resources/products/us_mail/response_v3/" + name + ".json"), + new File(getV1ResourcePathString("products/us_mail/response_v3/" + name + ".json")), type ); } @@ -49,9 +51,9 @@ void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { PredictResponse response = getPrediction("complete"); Document doc = response.getDocument(); - ProductTestHelper.assertStringEqualsFile( + assertStringEqualsFile( doc.toString(), - "src/test/resources/products/us_mail/response_v3/summary_full.rst" + getV1ResourcePathString("products/us_mail/response_v3/summary_full.rst") ); } diff --git a/src/test/java/com/mindee/workflow/WorkflowIT.java b/src/test/java/com/mindee/workflow/WorkflowIT.java index 5cf866eda..6190f9a01 100644 --- a/src/test/java/com/mindee/workflow/WorkflowIT.java +++ b/src/test/java/com/mindee/workflow/WorkflowIT.java @@ -4,7 +4,6 @@ import com.mindee.PredictOptions; import com.mindee.WorkflowOptions; import com.mindee.input.LocalInputSource; -import com.mindee.input.PageOptions; import com.mindee.parsing.common.AsyncPredictResponse; import com.mindee.parsing.common.Execution; import com.mindee.parsing.common.ExecutionPriority; @@ -18,6 +17,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import static com.mindee.TestingUtilities.getV1ResourcePath; + public class WorkflowIT { private static MindeeClient client; private static LocalInputSource financialDocumentInputSource; @@ -32,7 +33,7 @@ static void clientSetUp() throws IOException { client = new MindeeClient(); workflowId = System.getenv("WORKFLOW_ID"); financialDocumentInputSource = new LocalInputSource( - "src/test/resources/products/financial_document/default_sample.jpg" + getV1ResourcePath("products/financial_document/default_sample.jpg") ); } diff --git a/src/test/java/com/mindee/workflow/WorkflowTest.java b/src/test/java/com/mindee/workflow/WorkflowTest.java index 331fa57e6..24fdb039f 100644 --- a/src/test/java/com/mindee/workflow/WorkflowTest.java +++ b/src/test/java/com/mindee/workflow/WorkflowTest.java @@ -1,5 +1,8 @@ package com.mindee.workflow; +import static com.mindee.TestingUtilities.getResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePath; +import static com.mindee.TestingUtilities.getV1ResourcePathString; import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; @@ -45,8 +48,6 @@ public void setUp() { void givenAWorkflowMockFileShouldReturnAValidWorkflowObject() throws IOException { - File file = new File("src/test/resources/file_types/pdf/blank_1.pdf"); - WorkflowResponse workflowResponse = new WorkflowResponse(); workflowResponse.setExecution(new Execution()); workflowResponse.setApiRequest(null); @@ -60,7 +61,7 @@ void givenAWorkflowMockFileShouldReturnAValidWorkflowObject() WorkflowResponse execution = client.executeWorkflow( "", - new LocalInputSource(file) + new LocalInputSource(getResourcePath("file_types/pdf/blank_1.pdf")) ); Assertions.assertNotNull(execution); @@ -70,9 +71,10 @@ void givenAWorkflowMockFileShouldReturnAValidWorkflowObject() @Test void sendingADocumentToAnExecutionShouldDeserializeResponseCorrectly() throws IOException { - File jsonFile = new File("src/test/resources/workflows/success.json"); - WorkflowResponse.Default mockResponse = - objectMapper.readValue(jsonFile, WorkflowResponse.Default.class); + WorkflowResponse.Default mockResponse = objectMapper.readValue( + getV1ResourcePath("workflows/success.json").toFile(), + WorkflowResponse.Default.class + ); when(mockedClient.executeWorkflow(Mockito.anyString(), Mockito.any(LocalInputSource.class) @@ -80,8 +82,9 @@ void sendingADocumentToAnExecutionShouldDeserializeResponseCorrectly() throws IO .thenReturn(mockResponse); String workflowId = "07ebf237-ff27-4eee-b6a2-425df4a5cca6"; - String filePath = "src/test/resources/products/financial_document/default_sample.jpg"; - LocalInputSource inputSource = new LocalInputSource(filePath); + LocalInputSource inputSource = new LocalInputSource( + getV1ResourcePath("products/financial_document/default_sample.jpg") + ); WorkflowResponse response = mockedClient.executeWorkflow(workflowId, inputSource); @@ -112,9 +115,10 @@ void sendingADocumentToAnExecutionShouldDeserializeResponseCorrectly() throws IO @Test void sendingADocumentToAnExecutionWithPriorityAndAliasShouldDeserializeResponseCorrectly() throws IOException { - File jsonFile = new File("src/test/resources/workflows/success_low_priority.json"); - WorkflowResponse.Default mockResponse = - objectMapper.readValue(jsonFile, WorkflowResponse.Default.class); + WorkflowResponse.Default mockResponse = objectMapper.readValue( + getV1ResourcePath("workflows/success_low_priority.json").toFile(), + WorkflowResponse.Default.class + ); when(mockedClient.executeWorkflow(Mockito.anyString(), Mockito.any(LocalInputSource.class) @@ -122,8 +126,9 @@ void sendingADocumentToAnExecutionWithPriorityAndAliasShouldDeserializeResponseC .thenReturn(mockResponse); String workflowId = "07ebf237-ff27-4eee-b6a2-425df4a5cca6"; - String filePath = "src/test/resources/products/financial_document/default_sample.jpg"; - LocalInputSource inputSource = new LocalInputSource(filePath); + LocalInputSource inputSource = new LocalInputSource( + getV1ResourcePath("products/financial_document/default_sample.jpg") + ); WorkflowResponse response = mockedClient.executeWorkflow(workflowId, inputSource); @@ -133,10 +138,12 @@ void sendingADocumentToAnExecutionWithPriorityAndAliasShouldDeserializeResponseC Assertions.assertNull(response.getExecution().getBatchName()); Assertions.assertNull(response.getExecution().getCreatedAt()); Assertions.assertEquals( - "low-priority-sample-test", response.getExecution().getFile().getAlias()); + "low-priority-sample-test", response.getExecution().getFile().getAlias() + ); Assertions.assertEquals("default_sample.jpg", response.getExecution().getFile().getName()); Assertions.assertEquals( - "b743e123-e18c-4b62-8a07-811a4f72afd3", response.getExecution().getId()); + "b743e123-e18c-4b62-8a07-811a4f72afd3", response.getExecution().getId() + ); Assertions.assertNull(response.getExecution().getInference()); Assertions.assertEquals("low", response.getExecution().getPriority()); Assertions.assertNull(response.getExecution().getReviewedAt()); diff --git a/src/test/resources b/src/test/resources index 128075122..7d843db01 160000 --- a/src/test/resources +++ b/src/test/resources @@ -1 +1 @@ -Subproject commit 1280751220ee3673a79697e1b00be494545ad5f5 +Subproject commit 7d843db01df952740d0f2d39f62fc3efb86f92bb