|
| 1 | +package com.mindee.v2.product; |
| 2 | + |
| 3 | +import static com.mindee.TestingUtilities.assertStringEqualsFile; |
| 4 | +import static com.mindee.TestingUtilities.getV2ResourcePath; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 7 | + |
| 8 | +import com.mindee.input.LocalResponse; |
| 9 | +import com.mindee.v2.product.crop.CropItem; |
| 10 | +import com.mindee.v2.product.crop.CropResponse; |
| 11 | +import java.io.IOException; |
| 12 | +import java.util.ArrayList; |
| 13 | +import org.junit.jupiter.api.DisplayName; |
| 14 | +import org.junit.jupiter.api.Nested; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | + |
| 17 | +@DisplayName("MindeeV2 - Crop Model Tests") |
| 18 | +public class CropTest { |
| 19 | + private CropResponse loadResponse(String filePath) throws IOException { |
| 20 | + LocalResponse localResponse = new LocalResponse(getV2ResourcePath(filePath)); |
| 21 | + return localResponse.deserializeResponse(CropResponse.class); |
| 22 | + } |
| 23 | + |
| 24 | + @Nested |
| 25 | + @DisplayName("Result with single value") |
| 26 | + class SinglePredictionTest { |
| 27 | + @Test |
| 28 | + @DisplayName("all properties must be valid") |
| 29 | + void mustHaveValidProperties() throws IOException { |
| 30 | + CropResponse response = loadResponse("products/crop/crop_single.json"); |
| 31 | + assertNotNull(response.getInference()); |
| 32 | + |
| 33 | + ArrayList<CropItem> crops = response.getInference().getResult().getCrops(); |
| 34 | + assertEquals(1, crops.size()); |
| 35 | + |
| 36 | + CropItem crop1 = crops.get(0); |
| 37 | + assertEquals("invoice", crop1.getObjectType()); |
| 38 | + assertNotNull(crop1.getLocation().getPolygon()); |
| 39 | + assertEquals(0, crop1.getLocation().getPage()); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + @DisplayName("RST output must be valid") |
| 44 | + void mustHaveValidDisplay() throws IOException { |
| 45 | + CropResponse response = loadResponse("products/crop/crop_single.json"); |
| 46 | + assertStringEqualsFile( |
| 47 | + response.getInference().toString(), |
| 48 | + getV2ResourcePath("products/crop/crop_single.rst") |
| 49 | + ); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @Nested |
| 54 | + @DisplayName("Result with multiple values") |
| 55 | + class MultiPredictionTest { |
| 56 | + @Test |
| 57 | + @DisplayName("all properties must be valid") |
| 58 | + void mustHaveValidProperties() throws IOException { |
| 59 | + CropResponse response = loadResponse("products/crop/crop_multiple.json"); |
| 60 | + assertNotNull(response.getInference()); |
| 61 | + |
| 62 | + ArrayList<CropItem> crops = response.getInference().getResult().getCrops(); |
| 63 | + assertEquals(2, crops.size()); |
| 64 | + |
| 65 | + CropItem crop1 = crops.get(0); |
| 66 | + assertEquals("invoice", crop1.getObjectType()); |
| 67 | + assertNotNull(crop1.getLocation().getPolygon()); |
| 68 | + assertEquals(0, crop1.getLocation().getPage()); |
| 69 | + |
| 70 | + CropItem crop2 = crops.get(1); |
| 71 | + assertEquals("invoice", crop2.getObjectType()); |
| 72 | + assertNotNull(crop2.getLocation().getPolygon()); |
| 73 | + assertEquals(0, crop2.getLocation().getPage()); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + @DisplayName("RST output must be valid") |
| 78 | + void mustHaveValidDisplay() throws IOException { |
| 79 | + CropResponse response = loadResponse("products/crop/crop_multiple.json"); |
| 80 | + assertStringEqualsFile( |
| 81 | + response.getInference().toString(), |
| 82 | + getV2ResourcePath("products/crop/crop_multiple.rst") |
| 83 | + ); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments