diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml
index 38439df9a500d..13a45f8b996ed 100644
--- a/eng/jacoco-test-coverage/pom.xml
+++ b/eng/jacoco-test-coverage/pom.xml
@@ -39,7 +39,7 @@
com.azure
azure-ai-formrecognizer
- 3.0.0-beta.2
+ 3.0.0
com.azure
diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt
index c421c460f72ae..1b6d3301a1ca1 100644
--- a/eng/versioning/version_client.txt
+++ b/eng/versioning/version_client.txt
@@ -4,7 +4,7 @@
com.azure:azure-sdk-all;1.0.0;1.0.0
com.azure:azure-sdk-parent;1.6.0;1.6.0
com.azure:azure-client-sdk-parent;1.7.0;1.7.0
-com.azure:azure-ai-formrecognizer;3.0.0-beta.1;3.0.0-beta.2
+com.azure:azure-ai-formrecognizer;3.0.0-beta.1;3.0.0
com.azure:azure-ai-textanalytics;5.0.0;5.1.0-beta.1
com.azure:azure-core;1.7.0;1.8.0-beta.1
com.azure:azure-core-amqp;1.4.0;1.5.0-beta.1
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
index b66d86506b193..035729d11d2c0 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
@@ -1,7 +1,10 @@
# Release History
-## 3.0.0-beta.2 (Unreleased)
+## 3.0.0 (2020-08-20)
+First stable release of the azure-ai-formrecognizer client library supporting Azure Form Recognizer service API version v2.0.
+### Breaking Changes
+- Renamed `BoundingBox` model to `FieldBoundingBox`
## 3.0.0-beta.1 (2020-08-11)
This beta version targets Azure Form Recognizer service API version v2.0.
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/README.md b/sdk/formrecognizer/azure-ai-formrecognizer/README.md
index 21fe14511d86e..f9fada8961531 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/README.md
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/README.md
@@ -23,7 +23,7 @@ from form documents. It includes the following main functionalities:
com.azure
azure-ai-formrecognizer
- 3.0.0-beta.1
+ 3.0.0
```
[//]: # ({x-version-update-end})
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/pom.xml b/sdk/formrecognizer/azure-ai-formrecognizer/pom.xml
index 151849f9e030e..94662a789e725 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/pom.xml
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/pom.xml
@@ -13,7 +13,7 @@
com.azure
azure-ai-formrecognizer
- 3.0.0-beta.2
+ 3.0.0
Microsoft Azure client library for Form Recognizer
This package contains the Microsoft Azure Cognitive Services Form Recognizer SDK.
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java
index 75051037bb94b..26f7613b89e8e 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java
@@ -11,7 +11,7 @@
import com.azure.ai.formrecognizer.implementation.models.ReadResult;
import com.azure.ai.formrecognizer.implementation.models.TextLine;
import com.azure.ai.formrecognizer.implementation.models.TextWord;
-import com.azure.ai.formrecognizer.models.BoundingBox;
+import com.azure.ai.formrecognizer.models.FieldBoundingBox;
import com.azure.ai.formrecognizer.models.FieldData;
import com.azure.ai.formrecognizer.models.FieldValueType;
import com.azure.ai.formrecognizer.models.FormElement;
@@ -456,13 +456,13 @@ private static List toWords(List words, int pageNumber) {
/**
* Helper method to convert the service level modeled eight numbers representing the four points to SDK level
- * {@link BoundingBox}.
+ * {@link FieldBoundingBox}.
*
* @param serviceBoundingBox A list of eight numbers representing the four points of a box.
*
- * @return A {@link BoundingBox}.
+ * @return A {@link FieldBoundingBox}.
*/
- private static BoundingBox toBoundingBox(List serviceBoundingBox) {
+ private static FieldBoundingBox toBoundingBox(List serviceBoundingBox) {
if (CoreUtils.isNullOrEmpty(serviceBoundingBox) || (serviceBoundingBox.size() % 2) != 0) {
return null;
}
@@ -470,6 +470,6 @@ private static BoundingBox toBoundingBox(List serviceBoundingBox) {
for (int i = 0; i < serviceBoundingBox.size(); i++) {
pointList.add(new Point(serviceBoundingBox.get(i), serviceBoundingBox.get(++i)));
}
- return new BoundingBox(pointList);
+ return new FieldBoundingBox(pointList);
}
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/BoundingBox.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldBoundingBox.java
similarity index 70%
rename from sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/BoundingBox.java
rename to sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldBoundingBox.java
index e017f03a50179..bd97c80fcf3f8 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/BoundingBox.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldBoundingBox.java
@@ -13,19 +13,19 @@
* Quadrangle bounding box, with coordinates specified relative to the top-left of the original image
*/
@Immutable
-public final class BoundingBox {
+public final class FieldBoundingBox {
/**
- * The list of coordinates of the Bounding box.
+ * The list of coordinates of the field's bounding box.
*/
private final List points;
/**
- * Constructs a Bounding box object.
+ * Constructs a Field Bounding box object.
*
- * @param points The list of coordinates of the Bounding box.
+ * @param points The list of coordinates of the field's bounding box.
*/
- public BoundingBox(final List points) {
+ public FieldBoundingBox(final List points) {
if (points == null) {
this.points = null;
} else {
@@ -36,16 +36,16 @@ public BoundingBox(final List points) {
/**
* Gets the list of all point coordinates of the bounding box.
*
- * @return The unmodifiable list of all point coordinates of the Bounding box.
+ * @return The unmodifiable list of all point coordinates of the field's bounding box.
*/
public List getPoints() {
return this.points;
}
/**
- * Returns a string representation of the {@link BoundingBox}.
+ * Returns a string representation of the {@link FieldBoundingBox}.
*
- * @return the string representation of the {@link BoundingBox}.
+ * @return the string representation of the {@link FieldBoundingBox}.
*/
@Override
public String toString() {
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldData.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldData.java
index d4258f54533e8..5dded60527e5e 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldData.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldData.java
@@ -23,11 +23,11 @@ public final class FieldData extends FormElement {
* Creates raw OCR FieldData item.
*
* @param text The text content of ExtractedField.
- * @param boundingBox The BoundingBox of ExtractedField.
+ * @param boundingBox The Bounding Box of the recognized field.
* @param pageNumber the 1 based page number.
* @param fieldElements The list of element references when includeFieldElements is set to true.
*/
- public FieldData(String text, BoundingBox boundingBox, int pageNumber,
+ public FieldData(String text, FieldBoundingBox boundingBox, int pageNumber,
final List fieldElements) {
super(text, boundingBox, pageNumber);
this.fieldElements = fieldElements == null ? null : Collections.unmodifiableList(fieldElements);
@@ -37,7 +37,7 @@ public FieldData(String text, BoundingBox boundingBox, int pageNumber,
* {@inheritDoc}
*/
@Override
- public BoundingBox getBoundingBox() {
+ public FieldBoundingBox getBoundingBox() {
return super.getBoundingBox();
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormElement.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormElement.java
index f1d62571cb3e9..7d324f140d66e 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormElement.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormElement.java
@@ -24,7 +24,7 @@ public abstract class FormElement {
/*
* BoundingBox specifying relative coordinates of the element.
*/
- private final BoundingBox boundingBox;
+ private final FieldBoundingBox boundingBox;
/**
* Creates raw OCR item.
@@ -32,7 +32,7 @@ public abstract class FormElement {
* @param boundingBox The BoundingBox specifying relative coordinates of the element.
* @param pageNumber the 1 based page number.
*/
- FormElement(final String text, final BoundingBox boundingBox, final int pageNumber) {
+ FormElement(final String text, final FieldBoundingBox boundingBox, final int pageNumber) {
this.text = text;
this.boundingBox = boundingBox;
this.pageNumber = pageNumber;
@@ -43,7 +43,7 @@ public abstract class FormElement {
*
* @return the bounding box of the element.
*/
- public BoundingBox getBoundingBox() {
+ public FieldBoundingBox getBoundingBox() {
return boundingBox;
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormLine.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormLine.java
index 2cd890162e6a6..483cc19e76437 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormLine.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormLine.java
@@ -28,7 +28,7 @@ public final class FormLine extends FormElement {
* @param pageNumber the page number.
* @param words The list of word element references.
*/
- public FormLine(String text, BoundingBox boundingBox, Integer pageNumber,
+ public FormLine(String text, FieldBoundingBox boundingBox, Integer pageNumber,
final List words) {
super(text, boundingBox, pageNumber);
this.words = words == null ? null : Collections.unmodifiableList(words);
@@ -47,7 +47,7 @@ public List getWords() {
* {@inheritDoc}
*/
@Override
- public BoundingBox getBoundingBox() {
+ public FieldBoundingBox getBoundingBox() {
return super.getBoundingBox();
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormTableCell.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormTableCell.java
index aec0a0d0242e5..e34f6614fb2b3 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormTableCell.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormTableCell.java
@@ -71,7 +71,7 @@ public final class FormTableCell extends FormElement {
* @param fieldElements a list of references to the elements constituting this table cell.
*/
public FormTableCell(final int rowIndex, final int columnIndex, final int rowSpan,
- final int columnSpan, final String text, final BoundingBox boundingBox,
+ final int columnSpan, final String text, final FieldBoundingBox boundingBox,
final float confidence, final boolean isHeader, final boolean isFooter, final int pageNumber,
final List fieldElements) {
super(text, boundingBox, pageNumber);
@@ -106,7 +106,7 @@ public int getPageNumber() {
* {@inheritDoc}
*/
@Override
- public BoundingBox getBoundingBox() {
+ public FieldBoundingBox getBoundingBox() {
return super.getBoundingBox();
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormWord.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormWord.java
index 750d16f66f13e..3ed05c179d9a1 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormWord.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormWord.java
@@ -24,7 +24,7 @@ public final class FormWord extends FormElement {
* @param pageNumber the 1 based page number.
* @param confidence the confidence property of the Form Word.
*/
- public FormWord(String text, BoundingBox boundingBox, int pageNumber, final float confidence) {
+ public FormWord(String text, FieldBoundingBox boundingBox, int pageNumber, final float confidence) {
super(text, boundingBox, pageNumber);
this.confidence = confidence;
}
@@ -42,7 +42,7 @@ public float getConfidence() {
* {@inheritDoc}
*/
@Override
- public BoundingBox getBoundingBox() {
+ public FieldBoundingBox getBoundingBox() {
return super.getBoundingBox();
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java
index aba900e5fe40b..e6483c8b043bd 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java
@@ -56,7 +56,7 @@ public static void main(String[] args) {
final List pages = recognizedForm.getPages();
for (int i1 = 0; i1 < pages.size(); i1++) {
final FormPage formPage = pages.get(i1);
- System.out.printf("------- Recognizing info on page %s of Form -------%n", i1);
+ System.out.printf("------- Recognizing info on page %s of Form ------- %n", i1);
System.out.printf("Has width: %f, angle: %.2f, height: %f %n", formPage.getWidth(),
formPage.getTextAngle(), formPage.getHeight());
// Table information
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java
index 8f534bb79f921..1b3b7cc437eed 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java
@@ -27,21 +27,21 @@
import java.time.Duration;
import java.util.List;
+import static com.azure.ai.formrecognizer.TestUtils.BLANK_PDF;
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.ai.formrecognizer.TestUtils.FAILED_TO_DOWNLOAD_IMAGE_CODE;
import static com.azure.ai.formrecognizer.TestUtils.FAILED_TO_DOWNLOAD_IMAGE_ERROR_MESSAGE;
import static com.azure.ai.formrecognizer.TestUtils.FORM_JPG;
-import static com.azure.ai.formrecognizer.TestUtils.FORM_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.IMAGE_URL_IS_BADLY_FORMATTED_ERROR_MESSAGE;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_IMAGE_URL_ERROR_CODE;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_SOURCE_URL_ERROR;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_URL;
+import static com.azure.ai.formrecognizer.TestUtils.INVOICE_6_PDF_LOCAL_URL;
+import static com.azure.ai.formrecognizer.TestUtils.LAYOUT_1_JPG;
import static com.azure.ai.formrecognizer.TestUtils.LAYOUT_FILE_LENGTH;
-import static com.azure.ai.formrecognizer.TestUtils.LAYOUT_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.NON_EXIST_MODEL_ID;
import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_FILE_LENGTH;
-import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_LOCAL_URL;
-import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_PNG_FILE_LENGTH;
+import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_JPG_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.getReplayableBufferData;
import static com.azure.ai.formrecognizer.TestUtils.validateExceptionSource;
import static com.azure.ai.formrecognizer.implementation.Utility.toFluxByteBuffer;
@@ -83,14 +83,14 @@ private FormTrainingAsyncClient getFormTrainingAsyncClient(HttpClient httpClient
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- receiptDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
client.beginRecognizeReceipts(toFluxByteBuffer(data), dataLength, new RecognizeReceiptsOptions()
.setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateReceiptResultData(syncPoller.getFinalResult(), false);
- });
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -115,7 +115,7 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
SyncPoller> syncPoller = client.beginRecognizeReceipts(
- getReplayableBufferData(RECEIPT_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions()
+ getReplayableBufferData(RECEIPT_JPG_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions()
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
@@ -129,14 +129,14 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptDataIncludeFieldElements(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- receiptDataRunnerFieldElements((data, includeFieldElements) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeReceipts(
- toFluxByteBuffer(data), RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions()
- .setContentType(FormContentType.IMAGE_JPEG).setFieldElementsIncluded(includeFieldElements)
+ toFluxByteBuffer(data), dataLength, new RecognizeReceiptsOptions()
+ .setContentType(FormContentType.IMAGE_JPEG).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -147,14 +147,14 @@ public void recognizeReceiptDataIncludeFieldElements(HttpClient httpClient, Form
public void recognizeReceiptDataWithPngFile(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- receiptPngDataRunnerFieldElements((data, includeFieldElements) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
- client.beginRecognizeReceipts(toFluxByteBuffer(data), RECEIPT_PNG_FILE_LENGTH, new RecognizeReceiptsOptions()
- .setContentType(FormContentType.IMAGE_PNG).setFieldElementsIncluded(includeFieldElements)
+ client.beginRecognizeReceipts(toFluxByteBuffer(data), dataLength, new RecognizeReceiptsOptions()
+ .setContentType(FormContentType.IMAGE_PNG).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateReceiptResultData(syncPoller.getFinalResult(), true);
- });
+ }, RECEIPT_CONTOSO_PNG);
}
/**
@@ -165,28 +165,28 @@ public void recognizeReceiptDataWithPngFile(HttpClient httpClient,
public void recognizeReceiptDataWithBlankPdf(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
client.beginRecognizeReceipts(toFluxByteBuffer(data), dataLength, new RecognizeReceiptsOptions()
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateBlankPdfResultData(syncPoller.getFinalResult());
- });
+ }, BLANK_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptFromDataMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeReceipts(
toFluxByteBuffer(data), dataLength, new RecognizeReceiptsOptions()
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateMultipageReceiptData(syncPoller.getFinalResult());
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
/**
@@ -216,12 +216,12 @@ public void recognizeReceiptFromDamagedPdf(HttpClient httpClient, FormRecognizer
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptSourceUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- receiptSourceUrlRunner(sourceUrl -> {
+ urlRunner(sourceUrl -> {
SyncPoller> syncPoller =
client.beginRecognizeReceiptsFromUrl(sourceUrl).getSyncPoller();
syncPoller.waitForCompletion();
validateReceiptResultData(syncPoller.getFinalResult(), false);
- });
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -269,13 +269,13 @@ public void recognizeReceiptInvalidSourceUrl(HttpClient httpClient, FormRecogniz
public void recognizeReceiptFromUrlIncludeFieldElements(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- receiptSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> {
+ urlRunner(sourceUrl -> {
SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(
- sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(includeFieldElements)
+ sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(true)
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -287,26 +287,27 @@ sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(includeFieldE
public void recognizeReceiptSourceUrlWithPngFile(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- receiptPngSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> {
- SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(
- sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(includeFieldElements)
- .setPollInterval(durationTestMode))
- .getSyncPoller();
+ urlRunner(sourceUrl -> {
+ SyncPoller> syncPoller =
+ client.beginRecognizeReceiptsFromUrl(sourceUrl,
+ new RecognizeReceiptsOptions().setFieldElementsIncluded(true)
+ .setPollInterval(durationTestMode))
+ .getSyncPoller();
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_PNG);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> {
+ urlRunner(fileUrl -> {
SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(
fileUrl, new RecognizeReceiptsOptions().setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateMultipageReceiptData(syncPoller.getFinalResult());
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
// Content Recognition
@@ -320,14 +321,14 @@ public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecogniz
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContent(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- contentFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeContent(
toFluxByteBuffer(data), dataLength, new RecognizeContentOptions()
.setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, FORM_JPG);
}
/**
@@ -348,13 +349,13 @@ public void recognizeContentResultWithNullData(HttpClient httpClient, FormRecogn
public void recognizeContentResultWithContentTypeAutoDetection(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- contentFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeContent(
- getReplayableBufferData(LAYOUT_LOCAL_URL), dataLength, new RecognizeContentOptions()
+ getReplayableBufferData(LOCAL_FILE_PATH + LAYOUT_1_JPG), dataLength, new RecognizeContentOptions()
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, FORM_JPG);
}
/**
@@ -364,28 +365,28 @@ public void recognizeContentResultWithContentTypeAutoDetection(HttpClient httpCl
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentResultWithBlankPdf(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeContent(
toFluxByteBuffer(data), dataLength, new RecognizeContentOptions()
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, BLANK_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromDataMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeContent(
toFluxByteBuffer(data), dataLength, new RecognizeContentOptions()
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
/**
@@ -416,12 +417,13 @@ public void recognizeContentFromDamagedPdf(HttpClient httpClient,
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- contentFromUrlRunner(sourceUrl -> {
+ urlRunner(sourceUrl -> {
SyncPoller> syncPoller =
- client.beginRecognizeContentFromUrl(sourceUrl).getSyncPoller();
+ client.beginRecognizeContentFromUrl(sourceUrl, new RecognizeContentOptions()
+ .setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, FORM_JPG);
}
/**
@@ -450,13 +452,13 @@ public void recognizeContentFromUrlWithEncodedBlankSpaceSourceUrl(HttpClient htt
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromUrlWithPdf(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- pdfContentFromUrlRunner(sourceUrl -> {
+ urlRunner(sourceUrl -> {
SyncPoller> syncPoller =
client.beginRecognizeContentFromUrl(sourceUrl, new RecognizeContentOptions().setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, INVOICE_6_PDF);
}
/**
@@ -480,12 +482,12 @@ public void recognizeContentInvalidSourceUrl(HttpClient httpClient, FormRecogniz
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromUrlMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromUrlRunner((formUrl) -> {
+ urlRunner((formUrl) -> {
SyncPoller> syncPoller = client.beginRecognizeContentFromUrl(
formUrl, new RecognizeContentOptions().setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
// Custom form recognition
@@ -499,7 +501,7 @@ public void recognizeContentFromUrlMultiPage(HttpClient httpClient, FormRecogniz
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -514,7 +516,7 @@ dataLength, new RecognizeCustomFormsOptions()
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), true, true);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -525,7 +527,7 @@ dataLength, new RecognizeCustomFormsOptions()
public void recognizeCustomFormLabeledDataWithJpgContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormJpgDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -540,7 +542,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, true);
- }));
+ }), FORM_JPG);
}
/**
@@ -551,7 +553,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormLabeledDataWithBlankPdfContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -566,7 +568,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, true);
- }));
+ }), BLANK_PDF);
}
/**
@@ -578,7 +580,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormLabeledDataExcludeFieldElements(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -593,7 +595,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, true);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -604,7 +606,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormLabeledDataWithNullFormData(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller syncPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -617,7 +619,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
new RecognizeCustomFormsOptions()
.setContentType(FormContentType.APPLICATION_PDF)
.setFieldElementsIncluded(true).setPollInterval(durationTestMode)).getSyncPoller());
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -628,13 +630,13 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormLabeledDataWithNullModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms(
null, toFluxByteBuffer(data), dataLength,
new RecognizeCustomFormsOptions().setContentType(FormContentType.APPLICATION_PDF).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode)).getSyncPoller());
assertEquals(EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, INVOICE_6_PDF);
}
/**
@@ -645,13 +647,13 @@ null, toFluxByteBuffer(data), dataLength,
public void recognizeCustomFormLabeledDataWithEmptyModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms(
"", toFluxByteBuffer(data), dataLength, new RecognizeCustomFormsOptions()
.setContentType(FormContentType.APPLICATION_PDF).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode)).getSyncPoller());
assertEquals(EXPECTED_INVALID_UUID_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, INVOICE_6_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@@ -683,7 +685,7 @@ public void recognizeCustomFormInvalidStatus(HttpClient httpClient, FormRecogniz
public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -691,13 +693,14 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.getSyncPoller();
trainingPoller.waitForCompletion();
- SyncPoller> syncPoller = client.beginRecognizeCustomForms(
- trainingPoller.getFinalResult().getModelId(), getReplayableBufferData(FORM_LOCAL_URL), dataLength,
- new RecognizeCustomFormsOptions()
- .setFieldElementsIncluded(true).setPollInterval(durationTestMode)).getSyncPoller();
+ SyncPoller> syncPoller =
+ client.beginRecognizeCustomForms(trainingPoller.getFinalResult().getModelId(),
+ getReplayableBufferData(INVOICE_6_PDF_LOCAL_URL), dataLength,
+ new RecognizeCustomFormsOptions()
+ .setFieldElementsIncluded(true).setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), true, true);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -708,7 +711,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -722,7 +725,7 @@ public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient,
.getSyncPoller();
syncPoller.waitForCompletion();
validateMultiPageDataLabeled(syncPoller.getFinalResult());
- }));
+ }), MULTIPAGE_INVOICE_PDF);
}
// Custom form - non-URL - unlabeled data
@@ -734,7 +737,7 @@ public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient,
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeCustomFormUnlabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -749,7 +752,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, false);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -760,7 +763,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormUnlabeledDataIncludeFieldElements(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -775,8 +778,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.setFieldElementsIncluded(true).setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), true, false);
- })
- );
+ }), INVOICE_6_PDF);
}
/**
@@ -787,7 +789,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion)
@@ -803,8 +805,7 @@ public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient,
.getSyncPoller();
syncPoller.waitForCompletion();
validateMultiPageDataUnlabeled(syncPoller.getFinalResult());
- })
- );
+ }), MULTIPAGE_INVOICE_PDF);
}
/**
@@ -815,7 +816,7 @@ public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient,
public void recognizeCustomFormUnlabeledDataWithJpgContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- customFormJpgDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -830,7 +831,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, false);
- }));
+ }), FORM_JPG);
}
/**
@@ -841,7 +842,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormUnlabeledDataWithBlankPdfContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -856,7 +857,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
.getSyncPoller();
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, false);
- }));
+ }), BLANK_PDF);
}
// Custom form - URL - unlabeled data
@@ -918,16 +919,17 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormUrlMultiPageUnlabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl ->
+ urlPdfUnlabeledRunner(fileUrl ->
beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
false, new TrainingOptions().setPollInterval(durationTestMode)).getSyncPoller();
trainingPoller.waitForCompletion();
- SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl(
- trainingPoller.getFinalResult().getModelId(), fileUrl, new RecognizeCustomFormsOptions()
- .setPollInterval(durationTestMode)).getSyncPoller();
+ SyncPoller> syncPoller =
+ client.beginRecognizeCustomFormsFromUrl(trainingPoller.getFinalResult().getModelId(), fileUrl,
+ new RecognizeCustomFormsOptions().setPollInterval(durationTestMode))
+ .getSyncPoller();
syncPoller.waitForCompletion();
validateMultiPageDataUnlabeled(syncPoller.getFinalResult());
}));
@@ -962,12 +964,12 @@ public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient,
public void recognizeCustomFormFromUrlLabeledDataWithNullModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> {
+ urlRunner(fileUrl -> {
Exception ex = assertThrows(RuntimeException.class, () ->
client.beginRecognizeCustomFormsFromUrl(null, fileUrl, new RecognizeCustomFormsOptions()
.setPollInterval(durationTestMode)).getSyncPoller());
assertEquals(EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
/**
@@ -978,12 +980,12 @@ public void recognizeCustomFormFromUrlLabeledDataWithNullModelId(HttpClient http
public void recognizeCustomFormFromUrlLabeledDataWithEmptyModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> {
+ urlRunner(fileUrl -> {
Exception ex = assertThrows(RuntimeException.class, () ->
client.beginRecognizeCustomFormsFromUrl("", fileUrl, new RecognizeCustomFormsOptions()
.setPollInterval(durationTestMode)).getSyncPoller());
assertEquals(EXPECTED_INVALID_UUID_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
/**
@@ -1041,7 +1043,7 @@ useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode))
public void recognizeCustomFormUrlMultiPageLabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerAsyncClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl ->
+ urlRunner(fileUrl ->
beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingAsyncClient(httpClient, serviceVersion)
@@ -1054,7 +1056,7 @@ public void recognizeCustomFormUrlMultiPageLabeled(HttpClient httpClient,
.setPollInterval(durationTestMode)).getSyncPoller();
syncPoller.waitForCompletion();
validateMultiPageDataLabeled(syncPoller.getFinalResult());
- }));
+ }), MULTIPAGE_INVOICE_PDF);
}
/**
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientBuilderTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientBuilderTest.java
index cbca6e76a9b94..731c784be3803 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientBuilderTest.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientBuilderTest.java
@@ -22,10 +22,10 @@
import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.INVALID_ENDPOINT;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_API_KEY;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_ENDPOINT;
-import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL;
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.ai.formrecognizer.TestUtils.FORM_JPG;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_KEY;
+import static com.azure.ai.formrecognizer.TestUtils.URL_TEST_FILE_FORMAT;
import static com.azure.ai.formrecognizer.TestUtils.VALID_HTTP_LOCALHOST;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -144,7 +144,7 @@ void clientBuilderWithRotateToValidKeyRunner(HttpClient httpClient, FormRecogniz
getEndpoint(), credential);
// Update to valid key
credential.update(getApiKey());
- testRunner.apply(clientBuilder).accept(getTestingSasUri(FORM_JPG));
+ testRunner.apply(clientBuilder).accept(URL_TEST_FILE_FORMAT + FORM_JPG);
}
void clientBuilderWithNullServiceVersionRunner(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion,
@@ -153,7 +153,7 @@ void clientBuilderWithNullServiceVersionRunner(HttpClient httpClient, FormRecogn
createClientBuilder(httpClient, serviceVersion, getEndpoint(), new AzureKeyCredential(getApiKey()))
.retryPolicy(new RetryPolicy())
.serviceVersion(null);
- testRunner.apply(clientBuilder).accept(getTestingSasUri(FORM_JPG));
+ testRunner.apply(clientBuilder).accept(URL_TEST_FILE_FORMAT + FORM_JPG);
}
void clientBuilderWithDefaultPipelineRunner(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion,
@@ -162,7 +162,7 @@ void clientBuilderWithDefaultPipelineRunner(HttpClient httpClient, FormRecognize
createClientBuilder(httpClient, serviceVersion, getEndpoint(), new AzureKeyCredential(getApiKey()))
.configuration(Configuration.getGlobalConfiguration())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));
- testRunner.apply(clientBuilder).accept(getTestingSasUri(FORM_JPG));
+ testRunner.apply(clientBuilder).accept(URL_TEST_FILE_FORMAT + FORM_JPG);
}
/**
@@ -197,15 +197,4 @@ String getApiKey() {
return interceptorManager.isPlaybackMode() ? "apiKeyInPlayback"
: Configuration.getGlobalConfiguration().get(AZURE_FORM_RECOGNIZER_API_KEY);
}
-
- private String getTestingSasUri(String fileName) {
- if (interceptorManager.isPlaybackMode()) {
- return "https://isPlaybackmode";
- }
-
- final String testingFileUrl =
- Configuration.getGlobalConfiguration().get(FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL);
- final String[] urlParts = testingFileUrl.split("\\?");
- return urlParts[0] + "/" + fileName + "?" + urlParts[1];
- }
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java
index 7094117ecc649..5a39c26acd714 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java
@@ -25,18 +25,18 @@
import java.io.InputStream;
import java.util.List;
+import static com.azure.ai.formrecognizer.TestUtils.BLANK_PDF;
import static com.azure.ai.formrecognizer.TestUtils.CUSTOM_FORM_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.ai.formrecognizer.TestUtils.FORM_JPG;
-import static com.azure.ai.formrecognizer.TestUtils.FORM_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_SOURCE_URL_ERROR;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_URL;
+import static com.azure.ai.formrecognizer.TestUtils.INVOICE_6_PDF_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.LAYOUT_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.LAYOUT_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.NON_EXIST_MODEL_ID;
import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_FILE_LENGTH;
-import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_LOCAL_URL;
-import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_PNG_FILE_LENGTH;
+import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_JPG_LOCAL_URL;
import static com.azure.ai.formrecognizer.TestUtils.getContentDetectionFileData;
import static com.azure.ai.formrecognizer.TestUtils.validateExceptionSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -67,13 +67,13 @@ private FormTrainingClient getFormTrainingClient(HttpClient httpClient,
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- receiptDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
client.beginRecognizeReceipts(data, dataLength, new RecognizeReceiptsOptions()
.setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateReceiptResultData(syncPoller.getFinalResult(), false);
- });
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -97,7 +97,7 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
SyncPoller> syncPoller = client.beginRecognizeReceipts(
- getContentDetectionFileData(RECEIPT_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions()
+ getContentDetectionFileData(RECEIPT_JPG_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions()
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateReceiptResultData(syncPoller.getFinalResult(), false);
@@ -111,13 +111,13 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptDataIncludeFieldElements(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- receiptDataRunnerFieldElements((data, includeFieldElements) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeReceipts(
data, RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions().setContentType(FormContentType.IMAGE_JPEG)
- .setFieldElementsIncluded(includeFieldElements).setPollInterval(durationTestMode), Context.NONE);
+ .setFieldElementsIncluded(true).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -128,14 +128,14 @@ data, RECEIPT_FILE_LENGTH, new RecognizeReceiptsOptions().setContentType(FormCo
public void recognizeReceiptDataWithPngFile(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- receiptPngDataRunnerFieldElements((data, includeFieldElements) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
- client.beginRecognizeReceipts(data, RECEIPT_PNG_FILE_LENGTH, new RecognizeReceiptsOptions().setContentType(
- FormContentType.IMAGE_PNG).setFieldElementsIncluded(includeFieldElements)
+ client.beginRecognizeReceipts(data, dataLength, new RecognizeReceiptsOptions().setContentType(
+ FormContentType.IMAGE_PNG).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_PNG);
}
/**
@@ -146,26 +146,26 @@ public void recognizeReceiptDataWithPngFile(HttpClient httpClient,
public void recognizeReceiptDataWithBlankPdf(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeReceipts(
data, dataLength, new RecognizeReceiptsOptions().setContentType(FormContentType.APPLICATION_PDF)
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateBlankPdfResultData(syncPoller.getFinalResult());
- });
+ }, BLANK_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptFromDataMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller = client.beginRecognizeReceipts(
data, dataLength, new RecognizeReceiptsOptions().setContentType(FormContentType.APPLICATION_PDF)
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateMultipageReceiptData(syncPoller.getFinalResult());
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
/**
@@ -195,12 +195,12 @@ public void recognizeReceiptFromDamagedPdf(HttpClient httpClient, FormRecognizer
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptSourceUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- receiptSourceUrlRunner((sourceUrl) -> {
+ urlRunner((sourceUrl) -> {
SyncPoller> syncPoller =
client.beginRecognizeReceiptsFromUrl(sourceUrl);
syncPoller.waitForCompletion();
validateReceiptResultData(syncPoller.getFinalResult(), false);
- });
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -241,13 +241,13 @@ public void recognizeReceiptInvalidSourceUrl(HttpClient httpClient, FormRecogniz
public void recognizeReceiptFromUrlIncludeFieldElements(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- receiptSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> {
- SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(
- sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(includeFieldElements)
+ urlRunner(sourceUrl -> {
+ SyncPoller> syncPoller =
+ client.beginRecognizeReceiptsFromUrl(sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(true)
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_JPG);
}
/**
@@ -259,26 +259,26 @@ sourceUrl, new RecognizeReceiptsOptions().setFieldElementsIncluded(includeFieldE
public void recognizeReceiptSourceUrlWithPngFile(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- receiptPngSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> {
- SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(
- sourceUrl,
- new RecognizeReceiptsOptions().setFieldElementsIncluded(includeFieldElements)
+ urlRunner(sourceUrl -> {
+ SyncPoller> syncPoller =
+ client.beginRecognizeReceiptsFromUrl(sourceUrl,
+ new RecognizeReceiptsOptions().setFieldElementsIncluded(true)
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
- validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements);
- });
+ validateReceiptResultData(syncPoller.getFinalResult(), true);
+ }, RECEIPT_CONTOSO_PNG);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromUrlRunner(receiptUrl -> {
+ urlRunner(receiptUrl -> {
SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(
receiptUrl, new RecognizeReceiptsOptions().setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateMultipageReceiptData(syncPoller.getFinalResult());
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
// Content Recognition
@@ -292,13 +292,13 @@ public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecogniz
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContent(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- contentFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
client.beginRecognizeContent(data, dataLength, new RecognizeContentOptions()
.setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, FORM_JPG);
}
/**
@@ -337,26 +337,26 @@ public void recognizeContentResultWithContentTypeAutoDetection(HttpClient httpCl
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentResultWithBlankPdf(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
client.beginRecognizeContent(data, dataLength, new RecognizeContentOptions()
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, BLANK_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromDataMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
client.beginRecognizeContent(data, dataLength, new RecognizeContentOptions()
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
/**
@@ -384,11 +384,13 @@ public void recognizeContentFromDamagedPdf(HttpClient httpClient,
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- contentFromUrlRunner(sourceUrl -> {
- SyncPoller> syncPoller = client.beginRecognizeContentFromUrl(sourceUrl);
+ urlRunner(sourceUrl -> {
+ SyncPoller> syncPoller =
+ client.beginRecognizeContentFromUrl(sourceUrl, new RecognizeContentOptions()
+ .setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, FORM_JPG);
}
/**
@@ -416,12 +418,12 @@ public void recognizeContentFromUrlWithEncodedBlankSpaceSourceUrl(HttpClient htt
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromUrlWithPdf(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- pdfContentFromUrlRunner(sourceUrl -> {
+ urlRunner(sourceUrl -> {
SyncPoller> syncPoller = client.beginRecognizeContentFromUrl(sourceUrl,
new RecognizeContentOptions().setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, INVOICE_6_PDF);
}
/**
@@ -441,13 +443,13 @@ public void recognizeContentInvalidSourceUrl(HttpClient httpClient, FormRecogniz
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeContentFromUrlMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromUrlRunner((formUrl) -> {
+ urlRunner((formUrl) -> {
SyncPoller> syncPoller =
client.beginRecognizeContentFromUrl(formUrl, new RecognizeContentOptions().setPollInterval(durationTestMode),
Context.NONE);
syncPoller.waitForCompletion();
validateContentResultData(syncPoller.getFinalResult(), false);
- });
+ }, MULTIPAGE_INVOICE_PDF);
}
// Custom form recognition
@@ -461,7 +463,7 @@ public void recognizeContentFromUrlMultiPage(HttpClient httpClient, FormRecogniz
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -474,7 +476,7 @@ public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizer
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), true, true);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -485,7 +487,7 @@ public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizer
public void recognizeCustomFormLabeledDataWithJpgContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormJpgDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels,
@@ -497,7 +499,7 @@ public void recognizeCustomFormLabeledDataWithJpgContentType(HttpClient httpClie
.setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, true);
- }));
+ }), FORM_JPG);
}
/**
@@ -508,7 +510,7 @@ public void recognizeCustomFormLabeledDataWithJpgContentType(HttpClient httpClie
public void recognizeCustomFormLabeledDataWithBlankPdfContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
+ dataRunner((data, dataLength) -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels,
new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -519,7 +521,7 @@ public void recognizeCustomFormLabeledDataWithBlankPdfContentType(HttpClient htt
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, true);
- }));
+ }), BLANK_PDF);
}
/**
@@ -531,7 +533,7 @@ public void recognizeCustomFormLabeledDataWithBlankPdfContentType(HttpClient htt
public void recognizeCustomFormLabeledDataExcludeFieldElements(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
+ dataRunner((data, dataLength) -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels,
new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -542,7 +544,7 @@ public void recognizeCustomFormLabeledDataExcludeFieldElements(HttpClient httpCl
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, true);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -553,7 +555,7 @@ public void recognizeCustomFormLabeledDataExcludeFieldElements(HttpClient httpCl
public void recognizeCustomFormLabeledDataWithNullFormData(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller syncPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -564,7 +566,7 @@ public void recognizeCustomFormLabeledDataWithNullFormData(HttpClient httpClient
syncPoller.getFinalResult().getModelId(), (InputStream) null, dataLength, new RecognizeCustomFormsOptions()
.setContentType(FormContentType.APPLICATION_PDF).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode), Context.NONE));
- })
+ }), INVOICE_6_PDF
);
}
@@ -576,13 +578,13 @@ public void recognizeCustomFormLabeledDataWithNullFormData(HttpClient httpClient
public void recognizeCustomFormLabeledDataWithNullModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms(
null, data, dataLength, new RecognizeCustomFormsOptions()
.setContentType(FormContentType.APPLICATION_PDF).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode), Context.NONE));
assertEquals(EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, INVOICE_6_PDF);
}
/**
@@ -594,13 +596,13 @@ public void recognizeCustomFormLabeledDataWithEmptyModelId(HttpClient httpClient
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) -> {
+ dataRunner((data, dataLength) -> {
Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms(
"", data, dataLength, new RecognizeCustomFormsOptions()
.setContentType(FormContentType.APPLICATION_PDF).setFieldElementsIncluded(true)
.setPollInterval(durationTestMode), Context.NONE));
assertEquals(EXPECTED_INVALID_UUID_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, INVOICE_6_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@@ -639,7 +641,7 @@ public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClien
trainingPoller.waitForCompletion();
SyncPoller> syncPoller = client.beginRecognizeCustomForms(
- trainingPoller.getFinalResult().getModelId(), getContentDetectionFileData(FORM_LOCAL_URL),
+ trainingPoller.getFinalResult().getModelId(), getContentDetectionFileData(INVOICE_6_PDF_LOCAL_URL),
CUSTOM_FORM_FILE_LENGTH, new RecognizeCustomFormsOptions()
.setFieldElementsIncluded(true).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
@@ -652,7 +654,7 @@ CUSTOM_FORM_FILE_LENGTH, new RecognizeCustomFormsOptions()
public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
+ dataRunner((data, dataLength) -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, true,
new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -663,7 +665,7 @@ public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient,
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateMultiPageDataLabeled(syncPoller.getFinalResult());
- }));
+ }), MULTIPAGE_INVOICE_PDF);
}
// Custom form - non-URL - unlabeled data
@@ -675,7 +677,7 @@ public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient,
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
public void recognizeCustomFormUnlabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -687,7 +689,7 @@ public void recognizeCustomFormUnlabeledData(HttpClient httpClient, FormRecogniz
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, false);
- }));
+ }), INVOICE_6_PDF);
}
/**
@@ -699,7 +701,7 @@ public void recognizeCustomFormUnlabeledDataIncludeFieldElements(HttpClient http
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormDataRunner((data, dataLength) -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
+ dataRunner((data, dataLength) -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -711,7 +713,7 @@ public void recognizeCustomFormUnlabeledDataIncludeFieldElements(HttpClient http
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), true, false);
- }));
+ }), INVOICE_6_PDF);
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@@ -719,7 +721,7 @@ public void recognizeCustomFormUnlabeledDataIncludeFieldElements(HttpClient http
public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromDataRunner((data, dataLength) -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
+ dataRunner((data, dataLength) -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, false,
new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -730,7 +732,7 @@ public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient,
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateMultiPageDataUnlabeled(syncPoller.getFinalResult());
- }));
+ }), MULTIPAGE_INVOICE_PDF);
}
/**
@@ -741,7 +743,7 @@ public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient,
public void recognizeCustomFormUnlabeledDataWithJpgContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- customFormJpgDataRunner((data, dataLength) ->
+ dataRunner((data, dataLength) ->
beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
@@ -753,7 +755,7 @@ public void recognizeCustomFormUnlabeledDataWithJpgContentType(HttpClient httpCl
.setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, false);
- }));
+ }), FORM_JPG);
}
/**
@@ -764,7 +766,7 @@ public void recognizeCustomFormUnlabeledDataWithJpgContentType(HttpClient httpCl
public void recognizeCustomFormUnlabeledDataWithBlankPdfContentType(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- blankPdfDataRunner((data, dataLength) -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
+ dataRunner((data, dataLength) -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl,
useTrainingLabels, new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -775,7 +777,7 @@ public void recognizeCustomFormUnlabeledDataWithBlankPdfContentType(HttpClient h
.setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateRecognizedResult(syncPoller.getFinalResult(), false, false);
- }));
+ }), BLANK_PDF);
}
// Custom form - URL - unlabeled data
@@ -829,7 +831,7 @@ public void recognizeCustomFormUrlUnlabeledDataIncludeFieldElements(HttpClient h
public void recognizeCustomFormUrlMultiPageUnlabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
+ urlPdfUnlabeledRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, false,
new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -875,11 +877,11 @@ public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient,
public void recognizeCustomFormFromUrlLabeledDataWithNullModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> {
+ urlRunner(fileUrl -> {
Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomFormsFromUrl(
null, fileUrl, new RecognizeCustomFormsOptions().setPollInterval(durationTestMode), Context.NONE));
assertEquals(EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE, ex.getMessage());
- });
+ }, FORM_JPG);
}
/**
@@ -890,11 +892,11 @@ public void recognizeCustomFormFromUrlLabeledDataWithNullModelId(HttpClient http
public void recognizeCustomFormFromUrlLabeledDataWithEmptyModelId(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
+ urlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomFormsFromUrl(
"", fileUrl, new RecognizeCustomFormsOptions().setPollInterval(durationTestMode), Context.NONE));
assertEquals(EXPECTED_INVALID_UUID_EXCEPTION_MESSAGE, ex.getMessage());
- }));
+ }), FORM_JPG);
}
/**
@@ -950,7 +952,7 @@ public void recognizeCustomFormUrlLabeledData(HttpClient httpClient, FormRecogni
public void recognizeCustomFormUrlMultiPageLabeled(HttpClient httpClient,
FormRecognizerServiceVersion serviceVersion) {
client = getFormRecognizerClient(httpClient, serviceVersion);
- multipageFromUrlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
+ urlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> {
SyncPoller trainingPoller =
getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, true,
new TrainingOptions().setPollInterval(durationTestMode), Context.NONE);
@@ -961,7 +963,7 @@ public void recognizeCustomFormUrlMultiPageLabeled(HttpClient httpClient,
.setPollInterval(durationTestMode), Context.NONE);
syncPoller.waitForCompletion();
validateMultiPageDataLabeled(syncPoller.getFinalResult());
- }));
+ }), MULTIPAGE_INVOICE_PDF);
}
/**
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java
index f5b42898ceb32..a8f5b8b55a5fb 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java
@@ -15,7 +15,7 @@
import com.azure.ai.formrecognizer.implementation.models.ReadResult;
import com.azure.ai.formrecognizer.implementation.models.TextLine;
import com.azure.ai.formrecognizer.implementation.models.TextWord;
-import com.azure.ai.formrecognizer.models.BoundingBox;
+import com.azure.ai.formrecognizer.models.FieldBoundingBox;
import com.azure.ai.formrecognizer.models.FormElement;
import com.azure.ai.formrecognizer.models.FormField;
import com.azure.ai.formrecognizer.models.FormLine;
@@ -40,6 +40,9 @@
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@@ -53,24 +56,14 @@
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_ENDPOINT;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.FORM_RECOGNIZER_MULTIPAGE_TRAINING_BLOB_CONTAINER_SAS_URL;
-import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.FORM_RECOGNIZER_TRAINING_BLOB_CONTAINER_SAS_URL;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.deserializeRawResponse;
-import static com.azure.ai.formrecognizer.TestUtils.BLANK_FORM_FILE_LENGTH;
-import static com.azure.ai.formrecognizer.TestUtils.BLANK_PDF;
-import static com.azure.ai.formrecognizer.TestUtils.CUSTOM_FORM_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.DEFAULT_DURATION;
import static com.azure.ai.formrecognizer.TestUtils.FAKE_ENCODED_EMPTY_SPACE_URL;
-import static com.azure.ai.formrecognizer.TestUtils.FORM_1_JPG_FILE_LENGTH;
-import static com.azure.ai.formrecognizer.TestUtils.FORM_JPG;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_KEY;
-import static com.azure.ai.formrecognizer.TestUtils.INVOICE_1_PDF;
-import static com.azure.ai.formrecognizer.TestUtils.LAYOUT_FILE_LENGTH;
-import static com.azure.ai.formrecognizer.TestUtils.MULTIPAGE_INVOICE_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.ONE_NANO_DURATION;
-import static com.azure.ai.formrecognizer.TestUtils.RECEIPT_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.TEST_DATA_PNG;
-import static com.azure.ai.formrecognizer.TestUtils.getFileData;
+import static com.azure.ai.formrecognizer.TestUtils.URL_TEST_FILE_FORMAT;
import static com.azure.ai.formrecognizer.TestUtils.getSerializerAdapter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -79,17 +72,16 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
public abstract class FormRecognizerClientTestBase extends TestBase {
- private static final String RECEIPT_CONTOSO_JPG = "contoso-allinone.jpg";
- private static final String RECEIPT_CONTOSO_PNG = "contoso-receipt.png";
- private static final String INVOICE_PDF = "Invoice_6.pdf";
- private static final String MULTIPAGE_INVOICE_PDF = "multipage_invoice1.pdf";
+
private static final Pattern NON_DIGIT_PATTERN = Pattern.compile("[^0-9]+");
private static final String EXPECTED_MULTIPAGE_ADDRESS_VALUE = "123 Hobbit Lane 567 Main St. Redmond, WA Redmond,"
+ " WA";
private static final String EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE = "+15555555555";
private static final String ITEMIZED_RECEIPT_VALUE = "Itemized";
- private static final String IS_PLAYBACK_MODE = "isPlaybackMode";
-
+ static final String RECEIPT_CONTOSO_JPG = "contoso-allinone.jpg";
+ static final String RECEIPT_CONTOSO_PNG = "contoso-receipt.png";
+ static final String INVOICE_6_PDF = "Invoice_6.pdf";
+ static final String MULTIPAGE_INVOICE_PDF = "multipage_invoice1.pdf";
static final String EXPECTED_MODEL_ID_NOT_FOUND_ERROR_CODE = "1022";
static final String EXPECTED_URL_BADLY_FORMATTED_ERROR_CODE = "2001";
static final String INVALID_ENDPOINT = "https://notreal.azure.com";
@@ -107,9 +99,9 @@ public abstract class FormRecognizerClientTestBase extends TestBase {
static final String EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE = "'modelId' is required and cannot be null.";
static final String EXPECTED_UNABLE_TO_READ_FILE = "Analyze operation failed, errorCode: [2005], message: Unable "
+ "to read file.";
+ static final String LOCAL_FILE_PATH = "src/test/resources/sample_files/Test/";
static final String ENCODED_EMPTY_SPACE = "{\"source\":\"https://fakeuri.com/blank%20space\"}";
-
Duration durationTestMode;
/**
@@ -259,10 +251,10 @@ private static void validateFormWordData(List expectedFormWords,
}
}
- private static void validateBoundingBoxData(List expectedBoundingBox, BoundingBox actualBoundingBox) {
- if (actualBoundingBox != null && actualBoundingBox.getPoints() != null) {
+ private static void validateBoundingBoxData(List expectedBoundingBox, FieldBoundingBox actualFieldBoundingBox) {
+ if (actualFieldBoundingBox != null && actualFieldBoundingBox.getPoints() != null) {
int i = 0;
- for (Point point : actualBoundingBox.getPoints()) {
+ for (Point point : actualFieldBoundingBox.getPoints()) {
assertEquals(expectedBoundingBox.get(i), point.getX());
assertEquals(expectedBoundingBox.get(++i), point.getY());
i++;
@@ -607,110 +599,33 @@ void validateRecognizedResult(List actualFormList, boolean inclu
}
}
- void receiptSourceUrlRunner(Consumer testRunner) {
- testRunner.accept(getStorageTestingFileUrl(RECEIPT_CONTOSO_JPG));
- }
-
- void receiptSourceUrlRunnerFieldElements(BiConsumer testRunner) {
- testRunner.accept(getStorageTestingFileUrl(RECEIPT_CONTOSO_JPG), true);
- }
-
- void receiptPngSourceUrlRunnerFieldElements(BiConsumer testRunner) {
- testRunner.accept(getStorageTestingFileUrl(RECEIPT_CONTOSO_PNG), true);
- }
-
- void receiptDataRunner(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(IS_PLAYBACK_MODE.getBytes(StandardCharsets.UTF_8)),
- RECEIPT_FILE_LENGTH);
- } else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(RECEIPT_CONTOSO_JPG)), RECEIPT_FILE_LENGTH);
- }
- }
-
- void receiptDataRunnerFieldElements(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(IS_PLAYBACK_MODE.getBytes(StandardCharsets.UTF_8)), true);
- } else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(RECEIPT_CONTOSO_JPG)), true);
- }
- }
-
- void receiptPngDataRunnerFieldElements(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(IS_PLAYBACK_MODE.getBytes(StandardCharsets.UTF_8)), true);
- } else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(RECEIPT_CONTOSO_PNG)), true);
- }
- }
-
void invalidSourceUrlRunner(Consumer testRunner) {
testRunner.accept(TestUtils.INVALID_RECEIPT_URL);
}
- void contentFromDataRunner(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(IS_PLAYBACK_MODE.getBytes(StandardCharsets.UTF_8)),
- LAYOUT_FILE_LENGTH);
- } else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(FORM_JPG)), LAYOUT_FILE_LENGTH);
- }
- }
-
- void multipageFromDataRunner(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(IS_PLAYBACK_MODE.getBytes(StandardCharsets.UTF_8)),
- MULTIPAGE_INVOICE_FILE_LENGTH);
- } else {
- testRunner.accept(
- getFileData(getStorageTestingFileUrl(MULTIPAGE_INVOICE_PDF)), MULTIPAGE_INVOICE_FILE_LENGTH);
- }
- }
-
- void multipageFromUrlRunner(Consumer testRunner) {
- testRunner.accept(getStorageTestingFileUrl(MULTIPAGE_INVOICE_PDF));
- }
-
- void contentFromUrlRunner(Consumer testRunner) {
- testRunner.accept(getStorageTestingFileUrl(FORM_JPG));
- }
-
- void pdfContentFromUrlRunner(Consumer testRunner) {
- testRunner.accept(getStorageTestingFileUrl(INVOICE_1_PDF));
- }
-
void encodedBlankSpaceSourceUrlRunner(Consumer testRunner) {
testRunner.accept(FAKE_ENCODED_EMPTY_SPACE_URL);
}
- void customFormDataRunner(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(TEST_DATA_PNG.getBytes(StandardCharsets.UTF_8)),
- CUSTOM_FORM_FILE_LENGTH);
- } else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(INVOICE_PDF)), CUSTOM_FORM_FILE_LENGTH);
- }
+ void urlRunner(Consumer testRunner, String fileName) {
+ testRunner.accept(URL_TEST_FILE_FORMAT + fileName);
}
- void customFormJpgDataRunner(BiConsumer testRunner) {
- if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(TEST_DATA_PNG.getBytes(StandardCharsets.UTF_8)),
- FORM_1_JPG_FILE_LENGTH);
- } else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(FORM_JPG)), FORM_1_JPG_FILE_LENGTH);
- }
+ void urlPdfUnlabeledRunner(Consumer testRunner) {
+ testRunner.accept(getStorageTestingFileUrl(MULTIPAGE_INVOICE_PDF));
}
- void urlRunner(Consumer testRunner, String formData) {
- testRunner.accept(getStorageTestingFileUrl(formData));
- }
+ void dataRunner(BiConsumer testRunner, String fileName) {
+ final long fileLength = new File(LOCAL_FILE_PATH + fileName).length();
- void blankPdfDataRunner(BiConsumer testRunner) {
if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(TEST_DATA_PNG.getBytes(StandardCharsets.UTF_8)),
- BLANK_FORM_FILE_LENGTH);
+ testRunner.accept(new ByteArrayInputStream(TEST_DATA_PNG.getBytes(StandardCharsets.UTF_8)), fileLength);
} else {
- testRunner.accept(getFileData(getStorageTestingFileUrl(BLANK_PDF)), BLANK_FORM_FILE_LENGTH);
+ try {
+ testRunner.accept(new FileInputStream(LOCAL_FILE_PATH + fileName), fileLength);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("Local file not found.", e);
+ }
}
}
@@ -884,7 +799,7 @@ private String getTestingSasUri() {
if (interceptorManager.isPlaybackMode()) {
return "https://isPlaybackmode?SASToken";
} else {
- return Configuration.getGlobalConfiguration().get(FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL);
+ return Configuration.getGlobalConfiguration().get("FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL");
}
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java
index 61502111fbd6f..968430618e7e6 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java
@@ -32,7 +32,6 @@
import java.util.List;
import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.EXPECTED_MODEL_ID_NOT_FOUND_ERROR_CODE;
-import static com.azure.ai.formrecognizer.TestUtils.BLANK_FORM_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_MODEL_ID;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_MODEL_ID_ERROR;
@@ -71,9 +70,9 @@ private FormTrainingAsyncClient getFormTrainingAsyncClient(HttpClient httpClient
void getFormRecognizerClientAndValidate(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
FormRecognizerAsyncClient formRecognizerClient = getFormTrainingAsyncClient(httpClient, serviceVersion)
.getFormRecognizerAsyncClient();
- blankPdfDataRunner(data -> {
+ blankPdfDataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
- formRecognizerClient.beginRecognizeReceipts(toFluxByteBuffer(data), BLANK_FORM_FILE_LENGTH,
+ formRecognizerClient.beginRecognizeReceipts(toFluxByteBuffer(data), dataLength,
new RecognizeReceiptsOptions()
.setContentType(FormContentType.APPLICATION_PDF)
.setPollInterval(durationTestMode))
@@ -257,8 +256,7 @@ public void deleteModelValidModelIdWithResponseWithoutTrainingLabels(HttpClient
public void listCustomModels(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
client = getFormTrainingAsyncClient(httpClient, serviceVersion);
StepVerifier.create(client.listCustomModels())
- .thenConsumeWhile(customFormModelInfo ->
- customFormModelInfo.getModelId() != null && customFormModelInfo.getTrainingStartedOn() != null
+ .thenConsumeWhile(customFormModelInfo -> customFormModelInfo.getModelId() != null && customFormModelInfo.getTrainingStartedOn() != null
&& customFormModelInfo.getTrainingCompletedOn() != null && customFormModelInfo.getStatus() != null)
.verifyComplete();
}
@@ -301,7 +299,7 @@ public void beginCopy(HttpClient httpClient, FormRecognizerServiceVersion servic
}
PollerFlux copyPoller =
- client.beginCopyModel(actualModel.getModelId(), target);
+ client.beginCopyModel(actualModel.getModelId(), target, durationTestMode);
CustomFormModelInfo copyModel = copyPoller.getSyncPoller().getFinalResult();
assertNotNull(target.getModelId(), copyModel.getModelId());
assertNotNull(actualModel.getTrainingStartedOn());
@@ -367,10 +365,11 @@ public void beginCopyIncorrectRegion(HttpClient httpClient, FormRecognizerServic
return;
}
FormRecognizerException formRecognizerException = assertThrows(FormRecognizerException.class,
- () -> client.beginCopyModel(actualModel.getModelId(), target)
+ () -> client.beginCopyModel(actualModel.getModelId(), target, durationTestMode)
.getSyncPoller().getFinalResult());
FormRecognizerErrorInformation errorInformation = formRecognizerException.getErrorInformation().get(0);
// TODO: Service bug https://github.com/Azure/azure-sdk-for-java/issues/12046
+ // Should return resource resolve error instead locally returning Authorization error
// assertEquals(RESOURCE_RESOLVER_ERROR, errorInformation.getCode());
// assertTrue(formRecognizerException.getMessage().startsWith(COPY_OPERATION_FAILED_STATUS_MESSAGE));
});
@@ -401,7 +400,10 @@ public void beginTrainingInvalidModelStatus(HttpClient httpClient, FormRecognize
client = getFormTrainingAsyncClient(httpClient, serviceVersion);
beginTrainingInvalidModelStatusRunner((invalidTrainingFilesUrl, useTrainingLabels) -> {
FormRecognizerException formRecognizerException = assertThrows(FormRecognizerException.class,
- () -> client.beginTraining(invalidTrainingFilesUrl, useTrainingLabels).getSyncPoller().getFinalResult());
+ () -> client.beginTraining(invalidTrainingFilesUrl, useTrainingLabels,
+ new TrainingOptions().setPollInterval(durationTestMode))
+ .getSyncPoller().getFinalResult());
+
FormRecognizerErrorInformation errorInformation = formRecognizerException.getErrorInformation().get(0);
assertEquals(EXPECTED_INVALID_MODEL_STATUS_ERROR_CODE, errorInformation.getErrorCode());
assertTrue(formRecognizerException.getMessage().contains(EXPECTED_INVALID_MODEL_STATUS_MESSAGE));
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientBuilderTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientBuilderTest.java
index 66012fe0f55bb..d6b0cb86057a2 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientBuilderTest.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientBuilderTest.java
@@ -22,9 +22,9 @@
import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.INVALID_ENDPOINT;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_API_KEY;
import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_ENDPOINT;
-import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL;
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_KEY;
+import static com.azure.ai.formrecognizer.TestUtils.URL_TEST_FILE_FORMAT;
import static com.azure.ai.formrecognizer.TestUtils.VALID_URL;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -129,7 +129,7 @@ void clientBuilderWithRotateToValidKeyRunner(HttpClient httpClient, FormRecogniz
getEndpoint(), credential);
// Update to valid key
credential.update(getApiKey());
- testRunner.apply(clientBuilder).accept(getTestingSasUri(FORM_JPG));
+ testRunner.apply(clientBuilder).accept(URL_TEST_FILE_FORMAT + FORM_JPG);
}
void clientBuilderWithNullServiceVersionRunner(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion,
@@ -138,7 +138,7 @@ void clientBuilderWithNullServiceVersionRunner(HttpClient httpClient, FormRecogn
createClientBuilder(httpClient, serviceVersion, getEndpoint(), new AzureKeyCredential(getApiKey()))
.retryPolicy(new RetryPolicy())
.serviceVersion(null);
- testRunner.apply(clientBuilder).accept(getTestingSasUri(FORM_JPG));
+ testRunner.apply(clientBuilder).accept(URL_TEST_FILE_FORMAT + FORM_JPG);
}
void clientBuilderWithDefaultPipelineRunner(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion,
@@ -147,7 +147,7 @@ void clientBuilderWithDefaultPipelineRunner(HttpClient httpClient, FormRecognize
createClientBuilder(httpClient, serviceVersion, getEndpoint(), new AzureKeyCredential(getApiKey()))
.configuration(Configuration.getGlobalConfiguration())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));
- testRunner.apply(clientBuilder).accept(getTestingSasUri(FORM_JPG));
+ testRunner.apply(clientBuilder).accept(URL_TEST_FILE_FORMAT + FORM_JPG);
}
String getEndpoint() {
@@ -188,15 +188,4 @@ String getApiKey() {
return interceptorManager.isPlaybackMode() ? "apiKeyInPlayback"
: Configuration.getGlobalConfiguration().get(AZURE_FORM_RECOGNIZER_API_KEY);
}
-
- private String getTestingSasUri(String fileName) {
- if (interceptorManager.isPlaybackMode()) {
- return "https://isPlaybackmode";
- }
-
- final String testingFileUrl =
- Configuration.getGlobalConfiguration().get(FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL);
- final String[] urlParts = testingFileUrl.split("\\?");
- return urlParts[0] + "/" + fileName + "?" + urlParts[1];
- }
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java
index 1d10f03124cd7..49dbdff451983 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java
@@ -3,20 +3,20 @@
package com.azure.ai.formrecognizer;
-import com.azure.ai.formrecognizer.models.RecognizeReceiptsOptions;
-import com.azure.ai.formrecognizer.models.FormRecognizerErrorInformation;
import com.azure.ai.formrecognizer.models.FormContentType;
+import com.azure.ai.formrecognizer.models.FormRecognizerErrorInformation;
import com.azure.ai.formrecognizer.models.FormRecognizerException;
import com.azure.ai.formrecognizer.models.FormRecognizerOperationResult;
+import com.azure.ai.formrecognizer.models.RecognizeReceiptsOptions;
import com.azure.ai.formrecognizer.models.RecognizedForm;
import com.azure.ai.formrecognizer.training.FormTrainingClient;
import com.azure.ai.formrecognizer.training.models.AccountProperties;
-import com.azure.ai.formrecognizer.training.models.TrainingFileFilter;
-import com.azure.ai.formrecognizer.training.models.TrainingOptions;
import com.azure.ai.formrecognizer.training.models.CopyAuthorization;
import com.azure.ai.formrecognizer.training.models.CustomFormModel;
import com.azure.ai.formrecognizer.training.models.CustomFormModelInfo;
import com.azure.ai.formrecognizer.training.models.CustomFormModelStatus;
+import com.azure.ai.formrecognizer.training.models.TrainingFileFilter;
+import com.azure.ai.formrecognizer.training.models.TrainingOptions;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import com.azure.core.http.rest.Response;
@@ -30,7 +30,6 @@
import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.EXPECTED_MODEL_ID_NOT_FOUND_ERROR_CODE;
import static com.azure.ai.formrecognizer.FormTrainingAsyncClientTest.EXPECTED_COPY_REQUEST_INVALID_TARGET_RESOURCE_REGION;
-import static com.azure.ai.formrecognizer.TestUtils.BLANK_FORM_FILE_LENGTH;
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_MODEL_ID;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_MODEL_ID_ERROR;
@@ -56,10 +55,13 @@ private FormTrainingClient getFormTrainingClient(HttpClient httpClient,
public void getFormRecognizerClientAndValidate(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) {
FormRecognizerClient formRecognizerClient = getFormTrainingClient(httpClient, serviceVersion)
.getFormRecognizerClient();
- blankPdfDataRunner(data -> {
+ blankPdfDataRunner((data, dataLength) -> {
SyncPoller> syncPoller =
- formRecognizerClient.beginRecognizeReceipts(data, BLANK_FORM_FILE_LENGTH, new RecognizeReceiptsOptions()
- .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE);
+ formRecognizerClient.beginRecognizeReceipts(data, dataLength,
+ new RecognizeReceiptsOptions()
+ .setContentType(FormContentType.APPLICATION_PDF)
+ .setPollInterval(durationTestMode),
+ Context.NONE);
syncPoller.waitForCompletion();
validateBlankPdfResultData(syncPoller.getFinalResult());
});
@@ -83,7 +85,7 @@ public void getCustomModelInvalidModelId(HttpClient httpClient, FormRecognizerSe
client = getFormTrainingClient(httpClient, serviceVersion);
Exception exception = assertThrows(IllegalArgumentException.class, () ->
getCustomModelInvalidModelIdRunner(invalidId -> client.getCustomModel(invalidId)));
- assertTrue(exception.getMessage().equals(INVALID_MODEL_ID_ERROR));
+ assertEquals(INVALID_MODEL_ID_ERROR, exception.getMessage());
}
/**
@@ -165,7 +167,7 @@ public void deleteModelInvalidModelId(HttpClient httpClient, FormRecognizerServi
client = getFormTrainingClient(httpClient, serviceVersion);
Exception exception = assertThrows(IllegalArgumentException.class, () ->
client.deleteModel(INVALID_MODEL_ID));
- assertTrue(exception.getMessage().equals(INVALID_MODEL_ID_ERROR));
+ assertEquals(INVALID_MODEL_ID_ERROR, exception.getMessage());
}
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@@ -264,7 +266,8 @@ public void beginCopy(HttpClient httpClient, FormRecognizerServiceVersion servic
CopyAuthorization target =
client.getCopyAuthorization(resourceId, resourceRegion);
SyncPoller copyPoller = client.beginCopyModel(actualModel.getModelId(), target);
+ CustomFormModelInfo> copyPoller = client.beginCopyModel(actualModel.getModelId(), target,
+ durationTestMode, Context.NONE);
CustomFormModelInfo copyModel = copyPoller.getFinalResult();
assertEquals(target.getModelId(), copyModel.getModelId());
assertNotNull(actualModel.getTrainingStartedOn());
@@ -315,7 +318,8 @@ public void beginCopyIncorrectRegion(HttpClient httpClient, FormRecognizerServic
beginCopyIncorrectRegionRunner((resourceId, resourceRegion) -> {
final CopyAuthorization target = client.getCopyAuthorization(resourceId, resourceRegion);
FormRecognizerException formRecognizerException = assertThrows(FormRecognizerException.class,
- () -> client.beginCopyModel(actualModel.getModelId(), target).getFinalResult());
+ () -> client.beginCopyModel(actualModel.getModelId(), target, durationTestMode, Context.NONE)
+ .getFinalResult());
FormRecognizerErrorInformation errorInformation = formRecognizerException.getErrorInformation().get(0);
// TODO: Service bug https://github.com/Azure/azure-sdk-for-java/issues/12046
// assertEquals(RESOURCE_RESOLVER_ERROR, errorInformation.getCode());
@@ -344,7 +348,9 @@ public void beginTrainingInvalidModelStatus(HttpClient httpClient, FormRecognize
client = getFormTrainingClient(httpClient, serviceVersion);
beginTrainingInvalidModelStatusRunner((invalidTrainingFilesUrl, useTrainingLabels) -> {
FormRecognizerException formRecognizerException = assertThrows(FormRecognizerException.class,
- () -> client.beginTraining(invalidTrainingFilesUrl, useTrainingLabels).getFinalResult());
+ () -> client.beginTraining(invalidTrainingFilesUrl, useTrainingLabels,
+ new TrainingOptions().setPollInterval(durationTestMode), Context.NONE)
+ .getFinalResult());
FormRecognizerErrorInformation errorInformation = formRecognizerException.getErrorInformation().get(0);
assertEquals(EXPECTED_INVALID_MODEL_STATUS_ERROR_CODE, errorInformation.getErrorCode());
assertEquals(EXPECTED_INVALID_MODEL_ERROR, errorInformation.getMessage());
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java
index 33eee605fc16d..a437399390b40 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java
@@ -28,6 +28,9 @@
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@@ -38,11 +41,11 @@
import java.util.function.Consumer;
import static com.azure.ai.formrecognizer.FormRecognizerClientBuilder.DEFAULT_DURATION;
+import static com.azure.ai.formrecognizer.TestUtils.BLANK_PDF;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_KEY;
import static com.azure.ai.formrecognizer.TestUtils.INVALID_RECEIPT_URL;
import static com.azure.ai.formrecognizer.TestUtils.ONE_NANO_DURATION;
import static com.azure.ai.formrecognizer.TestUtils.TEST_DATA_PNG;
-import static com.azure.ai.formrecognizer.TestUtils.getFileData;
import static com.azure.ai.formrecognizer.TestUtils.getSerializerAdapter;
import static com.azure.ai.formrecognizer.implementation.models.ModelStatus.READY;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -52,6 +55,7 @@
public abstract class FormTrainingClientTestBase extends TestBase {
private static final String RESOURCE_ID = "FORM_RECOGNIZER_TARGET_RESOURCE_ID";
private static final String RESOURCE_REGION = "FORM_RECOGNIZER_TARGET_RESOURCE_REGION";
+ private static final String LOCAL_FILE_PATH = "src/test/resources/sample_files/Test/";
static final String AZURE_FORM_RECOGNIZER_API_KEY = "AZURE_FORM_RECOGNIZER_API_KEY";
static final String AZURE_FORM_RECOGNIZER_ENDPOINT = "AZURE_FORM_RECOGNIZER_ENDPOINT";
@@ -62,8 +66,6 @@ public abstract class FormTrainingClientTestBase extends TestBase {
+ "message: " + EXPECTED_INVALID_MODEL_ERROR;
static final String FORM_RECOGNIZER_TRAINING_BLOB_CONTAINER_SAS_URL =
"FORM_RECOGNIZER_TRAINING_BLOB_CONTAINER_SAS_URL";
- static final String FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL =
- "FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL";
static final String FORM_RECOGNIZER_MULTIPAGE_TRAINING_BLOB_CONTAINER_SAS_URL =
"FORM_RECOGNIZER_MULTIPAGE_TRAINING_BLOB_CONTAINER_SAS_URL";
static final String NO_VALID_BLOB_FOUND = "No valid blobs found in the specified Azure blob container."
@@ -351,11 +353,17 @@ void validateBlankPdfResultData(List actualReceiptList) {
assertTrue(actualReceipt.getFields().isEmpty());
}
- void blankPdfDataRunner(Consumer testRunner) {
+ void blankPdfDataRunner(BiConsumer testRunner) {
+ final long fileLength = new File(LOCAL_FILE_PATH + BLANK_PDF).length();
+
if (interceptorManager.isPlaybackMode()) {
- testRunner.accept(new ByteArrayInputStream(TEST_DATA_PNG.getBytes(StandardCharsets.UTF_8)));
+ testRunner.accept(new ByteArrayInputStream(TEST_DATA_PNG.getBytes(StandardCharsets.UTF_8)), fileLength);
} else {
- testRunner.accept(getFileData(getBlankPDFFileUrl()));
+ try {
+ testRunner.accept(new FileInputStream(LOCAL_FILE_PATH + BLANK_PDF), fileLength);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("Local file not found.", e);
+ }
}
}
@@ -375,31 +383,4 @@ private String getMultipageTrainingFilesUrl() {
? "https://isPlaybackmode"
: Configuration.getGlobalConfiguration().get(FORM_RECOGNIZER_MULTIPAGE_TRAINING_BLOB_CONTAINER_SAS_URL);
}
-
- /**
- * Prepare the file url from the testing data set SAS Url value.
- *
- * @return the testing data specific file Url
- */
- private String getBlankPDFFileUrl() {
- if (interceptorManager.isPlaybackMode()) {
- return "https://isPlaybackmode";
- } else {
- final String[] urlParts = getTestingContainerUrl().split("\\?");
- return urlParts[0] + "/" + TestUtils.BLANK_PDF + "?" + urlParts[1];
- }
- }
-
- /**
- * Get the testing data set SAS Url value based on the test running mode.
- *
- * @return the testing data set Url
- */
- private String getTestingContainerUrl() {
- if (interceptorManager.isPlaybackMode()) {
- return "https://isPlaybackmode?SASToken";
- } else {
- return Configuration.getGlobalConfiguration().get(FORM_RECOGNIZER_TESTING_BLOB_CONTAINER_SAS_URL);
- }
- }
}
diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/TestUtils.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/TestUtils.java
index 79d4110b162cd..6c202fdc0c85d 100644
--- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/TestUtils.java
+++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/TestUtils.java
@@ -6,10 +6,6 @@
import com.azure.ai.formrecognizer.implementation.Utility;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
-import com.azure.core.http.HttpMethod;
-import com.azure.core.http.HttpRequest;
-import com.azure.core.http.HttpResponse;
-import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.FluxUtil;
@@ -20,7 +16,6 @@
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -35,6 +30,9 @@
import java.util.stream.Stream;
import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.ENCODED_EMPTY_SPACE;
+import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.INVOICE_6_PDF;
+import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.LOCAL_FILE_PATH;
+import static com.azure.ai.formrecognizer.FormRecognizerClientTestBase.RECEIPT_CONTOSO_JPG;
import static com.azure.core.test.TestBase.AZURE_TEST_SERVICE_VERSIONS_VALUE_ALL;
import static com.azure.core.test.TestBase.getHttpClients;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -43,6 +41,8 @@
* Contains helper methods for generating inputs for test methods
*/
final class TestUtils {
+ static final String URL_TEST_FILE_FORMAT = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/"
+ + "master/sdk/formrecognizer/azure-ai-formrecognizer/src/test/resources/sample_files/Test/";
static final String FAKE_ENCODED_EMPTY_SPACE_URL = "https://fakeuri.com/blank%20space";
static final String FAILED_TO_DOWNLOAD_IMAGE_CODE = "FailedToDownloadImage";
static final String FAILED_TO_DOWNLOAD_IMAGE_ERROR_MESSAGE = "Failed to download image from input URL.";
@@ -59,57 +59,24 @@ final class TestUtils {
static final String INVALID_URL = "htttttttps://localhost:8080";
static final String VALID_HTTPS_LOCALHOST = "https://localhost:8080";
static final String VALID_HTTP_LOCALHOST = "http://localhost:8080";
- static final String RECEIPT_LOCAL_URL = "src/test/resources/sample_files/Test/contoso-allinone.jpg";
- static final String RECEIPT_LOCAL_PNG_URL = "src/test/resources/sample_files/Test/contoso-receipt.png";
- static final String LAYOUT_LOCAL_URL = "src/test/resources/sample_files/Test/layout1.jpg";
- static final String FORM_LOCAL_URL = "src/test/resources/sample_files/Test/Invoice_6.pdf";
- static final String FORM_1_JPG_LOCAL_URL = "src/test/resources/sample_files/Test/Form_1.jpg";
- static final String BLANK_FORM_LOCAL_URL = "src/test/resources/sample_files/Test/blank.pdf";
- static final String MULTIPAGE_INVOICE_LOCAL_URL = "src/test/resources/sample_files/Test/multipage_invoice1.pdf";
- static final long RECEIPT_FILE_LENGTH = new File(RECEIPT_LOCAL_URL).length();
- static final long RECEIPT_PNG_FILE_LENGTH = new File(RECEIPT_LOCAL_PNG_URL).length();
- static final long LAYOUT_FILE_LENGTH = new File(LAYOUT_LOCAL_URL).length();
- static final long CUSTOM_FORM_FILE_LENGTH = new File(FORM_LOCAL_URL).length();
- static final long FORM_1_JPG_FILE_LENGTH = new File(FORM_1_JPG_LOCAL_URL).length();
- static final long BLANK_FORM_FILE_LENGTH = new File(BLANK_FORM_LOCAL_URL).length();
- static final long MULTIPAGE_INVOICE_FILE_LENGTH = new File(MULTIPAGE_INVOICE_LOCAL_URL).length();
- static final String VALID_URL = "https://resources/contoso-allinone.jpg";
- static final String DISPLAY_NAME_WITH_ARGUMENTS = "{displayName} with [{arguments}]";
- private static final String AZURE_FORM_RECOGNIZER_TEST_SERVICE_VERSIONS =
- "AZURE_FORM_RECOGNIZER_TEST_SERVICE_VERSIONS";
-
static final String BLANK_PDF = "blank.pdf";
static final String FORM_JPG = "Form_1.jpg";
- static final String INVOICE_1_PDF = "Invoice_1.pdf";
static final String TEST_DATA_PNG = "testData.png";
-
+ static final String LAYOUT_1_JPG = "layout1.jpg";
+ static final String INVOICE_6_PDF_LOCAL_URL = LOCAL_FILE_PATH + INVOICE_6_PDF;
+ static final String LAYOUT_LOCAL_URL = LOCAL_FILE_PATH + LAYOUT_1_JPG;
+ static final String RECEIPT_JPG_LOCAL_URL = LOCAL_FILE_PATH + RECEIPT_CONTOSO_JPG;
+ static final long RECEIPT_FILE_LENGTH = new File(RECEIPT_JPG_LOCAL_URL).length();
+ static final long LAYOUT_FILE_LENGTH = new File(LAYOUT_LOCAL_URL).length();
+ static final long CUSTOM_FORM_FILE_LENGTH = new File(INVOICE_6_PDF_LOCAL_URL).length();
+ static final String VALID_URL = "https://resources/contoso-allinone.jpg";
+ static final String DISPLAY_NAME_WITH_ARGUMENTS = "{displayName} with [{arguments}]";
static final Duration ONE_NANO_DURATION = Duration.ofNanos(1);
static final Duration DEFAULT_DURATION = Duration.ofSeconds(5);
private TestUtils() {
}
- static InputStream getFileData(String fileName) {
- final HttpClient httpClient = new NettyAsyncHttpClientBuilder().build();
- final HttpResponse httpResponse =
- httpClient.send(new HttpRequest(HttpMethod.GET, fileName)).block();
-
- if (httpResponse == null) {
- return new ByteArrayInputStream(new byte[]{});
- }
-
- final Mono bodyAsByteArrayMono = httpResponse.getBodyAsByteArray();
- if (bodyAsByteArrayMono == null) {
- return new ByteArrayInputStream(new byte[]{});
- }
-
- final byte[] bodyAsByteArray = bodyAsByteArrayMono.block();
- if (bodyAsByteArray == null) {
- return new ByteArrayInputStream(new byte[]{});
- }
- return new ByteArrayInputStream(bodyAsByteArray);
- }
-
static InputStream getContentDetectionFileData(String localFileUrl) {
try {
return new FileInputStream(localFileUrl);
@@ -175,7 +142,7 @@ static Stream getTestParameters() {
*/
private static boolean shouldServiceVersionBeTested(FormRecognizerServiceVersion serviceVersion) {
String serviceVersionFromEnv =
- Configuration.getGlobalConfiguration().get(AZURE_FORM_RECOGNIZER_TEST_SERVICE_VERSIONS);
+ Configuration.getGlobalConfiguration().get("AZURE_FORM_RECOGNIZER_TEST_SERVICE_VERSIONS");
if (CoreUtils.isNullOrEmpty(serviceVersionFromEnv)) {
return FormRecognizerServiceVersion.getLatest().equals(serviceVersion);
}