3
3
4
4
package com .azure .ai .formrecognizer ;
5
5
6
+ import com .azure .ai .formrecognizer .implementation .models .AnalyzeResult ;
6
7
import com .azure .ai .formrecognizer .models .CustomFormModel ;
7
8
import com .azure .ai .formrecognizer .models .ErrorResponseException ;
8
9
import com .azure .ai .formrecognizer .models .FormContentType ;
19
20
20
21
import java .time .Duration ;
21
22
23
+ import static com .azure .ai .formrecognizer .TestUtils .CUSTOM_FORM_DATA ;
22
24
import static com .azure .ai .formrecognizer .TestUtils .CUSTOM_FORM_FILE_LENGTH ;
25
+ import static com .azure .ai .formrecognizer .TestUtils .CUSTOM_FORM_LABELED_DATA ;
23
26
import static com .azure .ai .formrecognizer .TestUtils .INVALID_SOURCE_URL_ERROR ;
24
27
import static com .azure .ai .formrecognizer .TestUtils .INVALID_URL ;
25
28
import static com .azure .ai .formrecognizer .TestUtils .LAYOUT_FILE_LENGTH ;
29
+ import static com .azure .ai .formrecognizer .TestUtils .LAYOUT_FORM_DATA ;
26
30
import static com .azure .ai .formrecognizer .TestUtils .RECEIPT_FILE_LENGTH ;
31
+ import static com .azure .ai .formrecognizer .TestUtils .RECEIPT_FORM_DATA ;
27
32
import static com .azure .ai .formrecognizer .TestUtils .RECEIPT_LOCAL_URL ;
28
- import static com .azure .ai .formrecognizer .TestUtils .getExpectedFormPages ;
29
- import static com .azure .ai .formrecognizer .TestUtils .getExpectedReceipts ;
30
- import static com .azure .ai .formrecognizer .TestUtils .getExpectedRecognizedForms ;
31
- import static com .azure .ai .formrecognizer .TestUtils .getExpectedRecognizedLabeledForms ;
32
- import static com .azure .ai .formrecognizer .TestUtils .getExpectedUSReceipt ;
33
+ import static com .azure .ai .formrecognizer .TestUtils .getAnalyzeRawResponse ;
33
34
import static com .azure .ai .formrecognizer .TestUtils .getReplayableBufferData ;
34
35
import static com .azure .ai .formrecognizer .implementation .Utility .toFluxByteBuffer ;
35
36
import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -66,7 +67,7 @@ void recognizeReceiptSourceUrl() {
66
67
SyncPoller <OperationResult , IterableStream <RecognizedReceipt >> syncPoller =
67
68
client .beginRecognizeReceiptsFromUrl (sourceUrl ).getSyncPoller ();
68
69
syncPoller .waitForCompletion ();
69
- validateReceiptResult ( getExpectedReceipts ( false ), syncPoller . getFinalResult () );
70
+ validateReceiptResultData ( syncPoller . getFinalResult ( ), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), false );
70
71
});
71
72
}
72
73
@@ -80,7 +81,7 @@ void recognizeReceiptSourceUrlTextDetails() {
80
81
SyncPoller <OperationResult , IterableStream <RecognizedReceipt >> syncPoller =
81
82
client .beginRecognizeReceiptsFromUrl (sourceUrl , includeTextDetails , null ).getSyncPoller ();
82
83
syncPoller .waitForCompletion ();
83
- validateReceiptResult ( getExpectedReceipts ( includeTextDetails ), syncPoller . getFinalResult () );
84
+ validateReceiptResultData ( syncPoller . getFinalResult ( ), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), includeTextDetails );
84
85
});
85
86
}
86
87
@@ -95,7 +96,7 @@ void recognizeReceiptData() {
95
96
FormContentType .IMAGE_JPEG , false ,
96
97
null ).getSyncPoller ();
97
98
syncPoller .waitForCompletion ();
98
- validateReceiptResult ( getExpectedReceipts ( false ), syncPoller . getFinalResult () );
99
+ validateReceiptResultData ( syncPoller . getFinalResult ( ), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), false );
99
100
});
100
101
}
101
102
@@ -119,7 +120,7 @@ void recognizeReceiptDataWithContentTypeAutoDetection() {
119
120
client .beginRecognizeReceipts (getReplayableBufferData (RECEIPT_LOCAL_URL ), RECEIPT_FILE_LENGTH , null ,
120
121
false , null ).getSyncPoller ();
121
122
syncPoller .waitForCompletion ();
122
- validateReceiptResult ( getExpectedReceipts ( false ), syncPoller . getFinalResult () );
123
+ validateReceiptResultData ( syncPoller . getFinalResult ( ), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), false );
123
124
}
124
125
125
126
/**
@@ -133,8 +134,7 @@ void recognizeReceiptDataTextDetails() {
133
134
FormContentType .IMAGE_JPEG , includeTextDetails ,
134
135
null ).getSyncPoller ();
135
136
syncPoller .waitForCompletion ();
136
- validateReceiptResult (getExpectedReceipts (true ),
137
- syncPoller .getFinalResult ());
137
+ validateReceiptResultData (syncPoller .getFinalResult (), getAnalyzeRawResponse (RECEIPT_FORM_DATA ).getAnalyzeResult (), true );
138
138
});
139
139
}
140
140
@@ -158,8 +158,9 @@ void recognizeReceiptAsUSReceipt() {
158
158
FormContentType .IMAGE_JPEG , includeTextDetails ,
159
159
null ).getSyncPoller ();
160
160
syncPoller .waitForCompletion ();
161
- syncPoller .getFinalResult ().forEach (recognizedReceipt -> validateUSReceipt (getExpectedUSReceipt (),
162
- ReceiptExtensions .asUSReceipt (recognizedReceipt ), includeTextDetails ));
161
+ syncPoller .getFinalResult ().forEach (recognizedReceipt ->
162
+ validateUSReceiptData (ReceiptExtensions .asUSReceipt (recognizedReceipt ),
163
+ getAnalyzeRawResponse (RECEIPT_FORM_DATA ).getAnalyzeResult (), includeTextDetails ));
163
164
});
164
165
}
165
166
@@ -173,7 +174,8 @@ void recognizeLayoutData() {
173
174
= client .beginRecognizeContent (toFluxByteBuffer (data ),
174
175
LAYOUT_FILE_LENGTH , FormContentType .IMAGE_JPEG , null ).getSyncPoller ();
175
176
syncPoller .waitForCompletion ();
176
- validateLayoutResult (getExpectedFormPages (), syncPoller .getFinalResult ());
177
+ final AnalyzeResult rawResponse = getAnalyzeRawResponse (LAYOUT_FORM_DATA ).getAnalyzeResult ();
178
+ validateLayoutDataResults (syncPoller .getFinalResult (), rawResponse .getReadResults (), rawResponse .getPageResults (), false );
177
179
});
178
180
}
179
181
@@ -205,7 +207,8 @@ void recognizeLayoutDataWithContentTypeAutoDetection() {
205
207
= client .beginRecognizeContent (toFluxByteBuffer (data ),
206
208
LAYOUT_FILE_LENGTH , null , null ).getSyncPoller ();
207
209
syncPoller .waitForCompletion ();
208
- validateLayoutResult (getExpectedFormPages (), syncPoller .getFinalResult ());
210
+ final AnalyzeResult rawResponse = getAnalyzeRawResponse (LAYOUT_FORM_DATA ).getAnalyzeResult ();
211
+ validateLayoutDataResults (syncPoller .getFinalResult (), rawResponse .getReadResults (), rawResponse .getPageResults (), false );
209
212
});
210
213
}
211
214
@@ -218,7 +221,8 @@ void recognizeLayoutSourceUrl() {
218
221
SyncPoller <OperationResult , IterableStream <FormPage >> syncPoller
219
222
= client .beginRecognizeContentFromUrl (sourceUrl ).getSyncPoller ();
220
223
syncPoller .waitForCompletion ();
221
- validateLayoutResult (getExpectedFormPages (), syncPoller .getFinalResult ());
224
+ final AnalyzeResult rawResponse = getAnalyzeRawResponse (LAYOUT_FORM_DATA ).getAnalyzeResult ();
225
+ validateLayoutDataResults (syncPoller .getFinalResult (), rawResponse .getReadResults (), rawResponse .getPageResults (), false );
222
226
});
223
227
}
224
228
@@ -236,7 +240,7 @@ void recognizeLayoutInvalidSourceUrl() {
236
240
*/
237
241
@ Test
238
242
void recognizeCustomFormInvalidSourceUrl () {
239
- beginTrainingLabeledResultRunner ((storageSASUrl , useLabelFile ) -> {
243
+ beginTrainingLabeledRunner ((storageSASUrl , useLabelFile ) -> {
240
244
SyncPoller <OperationResult , CustomFormModel > syncPoller =
241
245
client .getFormTrainingAsyncClient ().beginTraining (storageSASUrl , useLabelFile ).getSyncPoller ();
242
246
syncPoller .waitForCompletion ();
@@ -252,19 +256,20 @@ void recognizeCustomFormInvalidSourceUrl() {
252
256
*/
253
257
@ Test
254
258
void recognizeCustomFormLabeledData () {
255
- customFormLabeledDataRunner (data ->
256
- beginTrainingLabeledResultRunner ((storageSASUrl , useLabelFile ) -> {
257
- SyncPoller <OperationResult , CustomFormModel > syncPoller =
259
+ customFormDataRunner (data ->
260
+ beginTrainingLabeledRunner ((storageSASUrl , useLabelFile ) -> {
261
+ SyncPoller <OperationResult , CustomFormModel > trainingPoller =
258
262
client .getFormTrainingAsyncClient ().beginTraining (storageSASUrl , useLabelFile ).getSyncPoller ();
259
- syncPoller .waitForCompletion ();
263
+ trainingPoller .waitForCompletion ();
260
264
261
- SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPollers
265
+ SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPoller
262
266
= client .beginRecognizeCustomForms (toFluxByteBuffer (data ),
263
- syncPoller .getFinalResult ().getModelId (),
267
+ trainingPoller .getFinalResult ().getModelId (),
264
268
CUSTOM_FORM_FILE_LENGTH , FormContentType .APPLICATION_PDF , true , null )
265
269
.getSyncPoller ();
266
270
syncPoller .waitForCompletion ();
267
- validateRecognizedFormResult (getExpectedRecognizedLabeledForms (), syncPollers .getFinalResult ());
271
+ validateRecognizedResult (syncPoller .getFinalResult (),
272
+ getAnalyzeRawResponse (CUSTOM_FORM_LABELED_DATA ).getAnalyzeResult (), true , true );
268
273
}));
269
274
}
270
275
@@ -273,8 +278,8 @@ void recognizeCustomFormLabeledData() {
273
278
*/
274
279
@ Test
275
280
void recognizeCustomFormLabeledDataWithNullValues () {
276
- customFormLabeledDataRunner (data ->
277
- beginTrainingLabeledResultRunner ((storageSASUrl , useLabelFile ) -> {
281
+ customFormDataRunner (data ->
282
+ beginTrainingLabeledRunner ((storageSASUrl , useLabelFile ) -> {
278
283
SyncPoller <OperationResult , CustomFormModel > syncPoller =
279
284
client .getFormTrainingAsyncClient ().beginTraining (storageSASUrl , useLabelFile ).getSyncPoller ();
280
285
syncPoller .waitForCompletion ();
@@ -297,19 +302,20 @@ void recognizeCustomFormLabeledDataWithNullValues() {
297
302
*/
298
303
@ Test
299
304
void recognizeCustomFormLabeledDataWithContentTypeAutoDetection () {
300
- customFormLabeledDataRunner (data ->
301
- beginTrainingLabeledResultRunner ((storageSASUrl , useLabelFile ) -> {
302
- SyncPoller <OperationResult , CustomFormModel > syncPoller =
305
+ customFormDataRunner (data ->
306
+ beginTrainingLabeledRunner ((storageSASUrl , useLabelFile ) -> {
307
+ SyncPoller <OperationResult , CustomFormModel > trainingPoller =
303
308
client .getFormTrainingAsyncClient ().beginTraining (storageSASUrl , useLabelFile ).getSyncPoller ();
304
- syncPoller .waitForCompletion ();
309
+ trainingPoller .waitForCompletion ();
305
310
306
- SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPollers
311
+ SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPoller
307
312
= client .beginRecognizeCustomForms (toFluxByteBuffer (data ),
308
- syncPoller .getFinalResult ().getModelId (),
313
+ trainingPoller .getFinalResult ().getModelId (),
309
314
CUSTOM_FORM_FILE_LENGTH , null , true , null )
310
315
.getSyncPoller ();
311
316
syncPoller .waitForCompletion ();
312
- validateRecognizedFormResult (getExpectedRecognizedLabeledForms (), syncPollers .getFinalResult ());
317
+ validateRecognizedResult (syncPoller .getFinalResult (),
318
+ getAnalyzeRawResponse (CUSTOM_FORM_LABELED_DATA ).getAnalyzeResult (), true , true );
313
319
}));
314
320
}
315
321
@@ -318,19 +324,20 @@ void recognizeCustomFormLabeledDataWithContentTypeAutoDetection() {
318
324
*/
319
325
@ Test
320
326
void recognizeCustomFormUnlabeledData () {
321
- customFormLabeledDataRunner (data ->
322
- beginTrainingUnlabeledResultRunner ((storageSASUrl , useLabelFile ) -> {
323
- SyncPoller <OperationResult , CustomFormModel > syncPoller =
327
+ customFormDataRunner (data ->
328
+ beginTrainingUnlabeledRunner ((storageSASUrl , useLabelFile ) -> {
329
+ SyncPoller <OperationResult , CustomFormModel > trainingPoller =
324
330
client .getFormTrainingAsyncClient ().beginTraining (storageSASUrl , useLabelFile ).getSyncPoller ();
325
- syncPoller .waitForCompletion ();
331
+ trainingPoller .waitForCompletion ();
326
332
327
- SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPollers
333
+ SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPoller
328
334
= client .beginRecognizeCustomForms (toFluxByteBuffer (data ),
329
- syncPoller .getFinalResult ().getModelId (),
335
+ trainingPoller .getFinalResult ().getModelId (),
330
336
CUSTOM_FORM_FILE_LENGTH , FormContentType .APPLICATION_PDF , false , null )
331
337
.getSyncPoller ();
332
338
syncPoller .waitForCompletion ();
333
- validateRecognizedFormResult (getExpectedRecognizedForms (), syncPollers .getFinalResult ());
339
+ validateRecognizedResult (syncPoller .getFinalResult (),
340
+ getAnalyzeRawResponse (CUSTOM_FORM_DATA ).getAnalyzeResult (), false , false );
334
341
}));
335
342
}
336
343
}
0 commit comments