33
44package com .azure .ai .formrecognizer ;
55
6- import com .azure .ai .formrecognizer .implementation .models .AnalyzeResult ;
76import com .azure .ai .formrecognizer .models .CustomFormModel ;
87import com .azure .ai .formrecognizer .models .ErrorResponseException ;
98import com .azure .ai .formrecognizer .models .FormContentType ;
2019
2120import java .time .Duration ;
2221
23- import static com .azure .ai .formrecognizer .TestUtils .CUSTOM_FORM_DATA ;
2422import static com .azure .ai .formrecognizer .TestUtils .CUSTOM_FORM_FILE_LENGTH ;
25- import static com .azure .ai .formrecognizer .TestUtils .CUSTOM_FORM_LABELED_DATA ;
23+ import static com .azure .ai .formrecognizer .TestUtils .FORM_LOCAL_URL ;
2624import static com .azure .ai .formrecognizer .TestUtils .INVALID_SOURCE_URL_ERROR ;
2725import static com .azure .ai .formrecognizer .TestUtils .INVALID_URL ;
2826import static com .azure .ai .formrecognizer .TestUtils .LAYOUT_FILE_LENGTH ;
29- import static com .azure .ai .formrecognizer .TestUtils .LAYOUT_FORM_DATA ;
27+ import static com .azure .ai .formrecognizer .TestUtils .LAYOUT_LOCAL_URL ;
3028import static com .azure .ai .formrecognizer .TestUtils .RECEIPT_FILE_LENGTH ;
31- import static com .azure .ai .formrecognizer .TestUtils .RECEIPT_FORM_DATA ;
3229import static com .azure .ai .formrecognizer .TestUtils .RECEIPT_LOCAL_URL ;
33- import static com .azure .ai .formrecognizer .TestUtils .getAnalyzeRawResponse ;
3430import static com .azure .ai .formrecognizer .TestUtils .getReplayableBufferData ;
3531import static com .azure .ai .formrecognizer .implementation .Utility .toFluxByteBuffer ;
3632import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -67,7 +63,7 @@ void recognizeReceiptSourceUrl() {
6763 SyncPoller <OperationResult , IterableStream <RecognizedReceipt >> syncPoller =
6864 client .beginRecognizeReceiptsFromUrl (sourceUrl ).getSyncPoller ();
6965 syncPoller .waitForCompletion ();
70- validateReceiptResultData (syncPoller .getFinalResult (), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), false );
66+ validateReceiptResultData (syncPoller .getFinalResult (), false );
7167 });
7268 }
7369
@@ -81,7 +77,7 @@ void recognizeReceiptSourceUrlTextDetails() {
8177 SyncPoller <OperationResult , IterableStream <RecognizedReceipt >> syncPoller =
8278 client .beginRecognizeReceiptsFromUrl (sourceUrl , includeTextDetails , null ).getSyncPoller ();
8379 syncPoller .waitForCompletion ();
84- validateReceiptResultData (syncPoller .getFinalResult (), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), includeTextDetails );
80+ validateReceiptResultData (syncPoller .getFinalResult (), includeTextDetails );
8581 });
8682 }
8783
@@ -96,7 +92,7 @@ void recognizeReceiptData() {
9692 FormContentType .IMAGE_JPEG , false ,
9793 null ).getSyncPoller ();
9894 syncPoller .waitForCompletion ();
99- validateReceiptResultData (syncPoller .getFinalResult (), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), false );
95+ validateReceiptResultData (syncPoller .getFinalResult (), false );
10096 });
10197 }
10298
@@ -120,7 +116,7 @@ void recognizeReceiptDataWithContentTypeAutoDetection() {
120116 client .beginRecognizeReceipts (getReplayableBufferData (RECEIPT_LOCAL_URL ), RECEIPT_FILE_LENGTH , null ,
121117 false , null ).getSyncPoller ();
122118 syncPoller .waitForCompletion ();
123- validateReceiptResultData (syncPoller .getFinalResult (), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), false );
119+ validateReceiptResultData (syncPoller .getFinalResult (), false );
124120 }
125121
126122 /**
@@ -134,7 +130,7 @@ void recognizeReceiptDataTextDetails() {
134130 FormContentType .IMAGE_JPEG , includeTextDetails ,
135131 null ).getSyncPoller ();
136132 syncPoller .waitForCompletion ();
137- validateReceiptResultData (syncPoller .getFinalResult (), getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), true );
133+ validateReceiptResultData (syncPoller .getFinalResult (), true );
138134 });
139135 }
140136
@@ -160,7 +156,7 @@ void recognizeReceiptAsUSReceipt() {
160156 syncPoller .waitForCompletion ();
161157 syncPoller .getFinalResult ().forEach (recognizedReceipt ->
162158 validateUSReceiptData (ReceiptExtensions .asUSReceipt (recognizedReceipt ),
163- getAnalyzeRawResponse ( RECEIPT_FORM_DATA ). getAnalyzeResult (), includeTextDetails ));
159+ includeTextDetails ));
164160 });
165161 }
166162
@@ -174,8 +170,7 @@ void recognizeLayoutData() {
174170 = client .beginRecognizeContent (toFluxByteBuffer (data ),
175171 LAYOUT_FILE_LENGTH , FormContentType .IMAGE_JPEG , null ).getSyncPoller ();
176172 syncPoller .waitForCompletion ();
177- final AnalyzeResult rawResponse = getAnalyzeRawResponse (LAYOUT_FORM_DATA ).getAnalyzeResult ();
178- validateLayoutDataResults (syncPoller .getFinalResult (), rawResponse .getReadResults (), rawResponse .getPageResults (), false );
173+ validateLayoutDataResults (syncPoller .getFinalResult (), false );
179174 });
180175 }
181176
@@ -204,11 +199,10 @@ void recognizeLayoutDataWithNullData() {
204199 void recognizeLayoutDataWithContentTypeAutoDetection () {
205200 layoutDataRunner ((data ) -> {
206201 SyncPoller <OperationResult , IterableStream <FormPage >> syncPoller
207- = client .beginRecognizeContent (toFluxByteBuffer ( data ),
202+ = client .beginRecognizeContent (getReplayableBufferData ( LAYOUT_LOCAL_URL ),
208203 LAYOUT_FILE_LENGTH , null , null ).getSyncPoller ();
209204 syncPoller .waitForCompletion ();
210- final AnalyzeResult rawResponse = getAnalyzeRawResponse (LAYOUT_FORM_DATA ).getAnalyzeResult ();
211- validateLayoutDataResults (syncPoller .getFinalResult (), rawResponse .getReadResults (), rawResponse .getPageResults (), false );
205+ validateLayoutDataResults (syncPoller .getFinalResult (), false );
212206 });
213207 }
214208
@@ -221,8 +215,7 @@ void recognizeLayoutSourceUrl() {
221215 SyncPoller <OperationResult , IterableStream <FormPage >> syncPoller
222216 = client .beginRecognizeContentFromUrl (sourceUrl ).getSyncPoller ();
223217 syncPoller .waitForCompletion ();
224- final AnalyzeResult rawResponse = getAnalyzeRawResponse (LAYOUT_FORM_DATA ).getAnalyzeResult ();
225- validateLayoutDataResults (syncPoller .getFinalResult (), rawResponse .getReadResults (), rawResponse .getPageResults (), false );
218+ validateLayoutDataResults (syncPoller .getFinalResult (), false );
226219 });
227220 }
228221
@@ -269,7 +262,7 @@ void recognizeCustomFormLabeledData() {
269262 .getSyncPoller ();
270263 syncPoller .waitForCompletion ();
271264 validateRecognizedResult (syncPoller .getFinalResult (),
272- getAnalyzeRawResponse ( CUSTOM_FORM_LABELED_DATA ). getAnalyzeResult (), true , true );
265+ true , true );
273266 }));
274267 }
275268
@@ -309,13 +302,13 @@ void recognizeCustomFormLabeledDataWithContentTypeAutoDetection() {
309302 trainingPoller .waitForCompletion ();
310303
311304 SyncPoller <OperationResult , IterableStream <RecognizedForm >> syncPoller
312- = client .beginRecognizeCustomForms (toFluxByteBuffer ( data ),
305+ = client .beginRecognizeCustomForms (getReplayableBufferData ( FORM_LOCAL_URL ),
313306 trainingPoller .getFinalResult ().getModelId (),
314307 CUSTOM_FORM_FILE_LENGTH , null , true , null )
315308 .getSyncPoller ();
316309 syncPoller .waitForCompletion ();
317310 validateRecognizedResult (syncPoller .getFinalResult (),
318- getAnalyzeRawResponse ( CUSTOM_FORM_LABELED_DATA ). getAnalyzeResult (), true , true );
311+ true , true );
319312 }));
320313 }
321314
@@ -337,7 +330,7 @@ void recognizeCustomFormUnlabeledData() {
337330 .getSyncPoller ();
338331 syncPoller .waitForCompletion ();
339332 validateRecognizedResult (syncPoller .getFinalResult (),
340- getAnalyzeRawResponse ( CUSTOM_FORM_DATA ). getAnalyzeResult (), false , false );
333+ false , false );
341334 }));
342335 }
343336}
0 commit comments