1717
1818@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
1919@ Tag ("integration" )
20- @ DisplayName ("MindeeV2 –Integration Tests - Crop" )
20+ @ DisplayName ("MindeeV2 – Integration Tests - Crop" )
2121class CropIT {
2222
2323 private MindeeClient mindeeClient ;
24- private String modelId ;
24+ private String cropModelId ;
25+ private String cropExtractionModelId ;
2526
2627 @ BeforeAll
2728 void setUp () {
2829 var apiKey = System .getenv ("MINDEE_V2_API_KEY" );
29- modelId = System .getenv ("MINDEE_V2_SE_TESTS_CROP_MODEL_ID" );
30+ cropModelId = System .getenv ("MINDEE_V2_SE_TESTS_CROP_MODEL_ID" );
31+ cropExtractionModelId = System .getenv ("MINDEE_V2_SE_TESTS_CROP_EXTRACTION_MODEL_ID" );
3032 mindeeClient = new MindeeClient (apiKey );
3133 }
3234
3335 @ Test
34- @ DisplayName ("Empty , multi-page PDF – enqueue & parse must succeed" )
35- void parseFile_FilledMultiPage_mustSucceed () throws IOException , InterruptedException {
36+ @ DisplayName ("Filled , multi-page PDF – crop must succeed" )
37+ void filledMultiPage_cropMustSucceed () throws IOException , InterruptedException {
3638 var source = new LocalInputSource (getV2ResourcePath ("products/crop/multipage_sample.pdf" ));
3739 var params = CropParameters
38- .builder (modelId )
40+ .builder (cropModelId )
3941 .alias ("java_integration-test_crop_multipage" )
4042 .build ();
4143 var pollingOptions = PollingOptions
@@ -58,11 +60,64 @@ void parseFile_FilledMultiPage_mustSucceed() throws IOException, InterruptedExce
5860 assertEquals (2 , file .getPageCount ());
5961
6062 assertNotNull (inference .getModel ());
61- assertEquals (modelId , inference .getModel ().getId ());
63+ assertEquals (cropModelId , inference .getModel ().getId ());
6264
6365 var result = inference .getResult ();
6466 assertNotNull (result );
6567 assertEquals (5 , result .getCrops ().size ());
66- assertEquals ("receipt" , result .getCrops ().get (0 ).getObjectType ());
68+ var crop0 = result .getCrops ().get (0 );
69+ assertEquals ("receipt" , crop0 .getObjectType ());
70+ assertNotNull (crop0 .getLocation ().getPolygon ());
71+ assertEquals (0 , crop0 .getLocation ().getPage ());
72+ }
73+
74+ @ Test
75+ @ DisplayName ("Filled image – crop and extraction must succeed" )
76+ void filledSinglePage_extractionMustSucceed () throws IOException , InterruptedException {
77+ var source = new LocalInputSource (getV2ResourcePath ("products/crop/default_sample.jpg" ));
78+ var params = CropParameters
79+ .builder (cropExtractionModelId )
80+ .alias ("java_integration-test_crop_multipage" )
81+ .build ();
82+ var pollingOptions = PollingOptions
83+ .builder ()
84+ .initialDelaySec (5.0 )
85+ .intervalSec (1.5 )
86+ .maxRetries (80 )
87+ .build ();
88+
89+ CropResponse response = mindeeClient
90+ .enqueueAndGetResult (CropResponse .class , source , params , pollingOptions );
91+ assertNotNull (response );
92+
93+ var inference = response .getInference ();
94+ assertNotNull (inference );
95+
96+ var file = inference .getFile ();
97+ assertNotNull (file );
98+ assertEquals ("default_sample.jpg" , file .getName ());
99+ assertEquals (1 , file .getPageCount ());
100+
101+ assertNotNull (inference .getModel ());
102+ assertEquals (cropExtractionModelId , inference .getModel ().getId ());
103+
104+ var result = inference .getResult ();
105+ assertNotNull (result );
106+ assertEquals (2 , result .getCrops ().size ());
107+ var crop0 = result .getCrops ().get (0 );
108+ assertEquals ("receipt" , crop0 .getObjectType ());
109+ assertNotNull (crop0 .getLocation ().getPolygon ());
110+ assertEquals (0 , crop0 .getLocation ().getPage ());
111+ var extractionResponse0 = crop0 .getExtractionResponse ();
112+ assertNotNull (extractionResponse0 );
113+ assertEquals (
114+ "CHEZ ALAIN MIAM MIAM" ,
115+ extractionResponse0
116+ .getInference ()
117+ .getResult ()
118+ .getFields ()
119+ .getSimpleField ("supplier_name" )
120+ .getValue ()
121+ );
67122 }
68123}
0 commit comments