|
| 1 | +package com.mindee.v2.product; |
| 2 | + |
| 3 | +import static com.mindee.TestingUtilities.getV2ResourcePath; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 6 | + |
| 7 | +import com.mindee.input.LocalResponse; |
| 8 | +import com.mindee.v2.product.ocr.OcrPage; |
| 9 | +import com.mindee.v2.product.ocr.OcrResponse; |
| 10 | +import java.io.IOException; |
| 11 | +import java.util.ArrayList; |
| 12 | +import org.junit.jupiter.api.DisplayName; |
| 13 | +import org.junit.jupiter.api.Nested; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +@DisplayName("MindeeV2 - OCR Model Tests") |
| 17 | +public class OcrTest { |
| 18 | + private OcrResponse loadResponse(String filePath) throws IOException { |
| 19 | + LocalResponse localResponse = new LocalResponse(getV2ResourcePath(filePath)); |
| 20 | + return localResponse.deserializeResponse(OcrResponse.class); |
| 21 | + } |
| 22 | + |
| 23 | + @Nested |
| 24 | + @DisplayName("Result with single value") |
| 25 | + class SinglePredictionTest { |
| 26 | + @Test |
| 27 | + @DisplayName("all properties must be valid") |
| 28 | + void mustHaveValidProperties() throws IOException { |
| 29 | + OcrResponse response = loadResponse("products/ocr/ocr_single.json"); |
| 30 | + assertNotNull(response.getInference()); |
| 31 | + |
| 32 | + ArrayList<OcrPage> pages = response.getInference().getResult().getPages(); |
| 33 | + assertEquals(1, pages.size()); |
| 34 | + assertEquals(305, pages.get(0).getWords().size()); |
| 35 | + assertEquals("Shipper:", pages.get(0).getWords().get(0).getContent()); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Nested |
| 40 | + @DisplayName("Result with multiple values") |
| 41 | + class MultiPredictionTest { |
| 42 | + @Test |
| 43 | + @DisplayName("all properties must be valid") |
| 44 | + void mustHaveValidProperties() throws IOException { |
| 45 | + OcrResponse response = loadResponse("products/ocr/ocr_multiple.json"); |
| 46 | + assertNotNull(response.getInference()); |
| 47 | + |
| 48 | + ArrayList<OcrPage> pages = response.getInference().getResult().getPages(); |
| 49 | + assertEquals(3, pages.size()); |
| 50 | + |
| 51 | + OcrPage page1 = pages.get(0); |
| 52 | + assertNotNull(page1.getContent()); |
| 53 | + assertEquals(295, page1.getWords().size()); |
| 54 | + assertEquals("FICTIOCORP", page1.getWords().get(0).getContent()); |
| 55 | + |
| 56 | + OcrPage page2 = pages.get(1); |
| 57 | + assertNotNull(page2.getContent()); |
| 58 | + assertEquals(450, page2.getWords().size()); |
| 59 | + assertEquals("KEOLIO", page2.getWords().get(0).getContent()); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments