Skip to content

Commit 439bd3a

Browse files
authored
[Form Recognizer] Enable AAD authentication for tests (Azure#24696)
1 parent b8af903 commit 439bd3a

File tree

169 files changed

+5207
-3297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+5207
-3297
lines changed

eng/versioning/version_client.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ com.azure.resourcemanager:azure-resourcemanager-storagepool;1.0.0-beta.1;1.0.0-b
328328
# note: The unreleased dependencies will not be manipulated with the automatic PR creation code.
329329
# In the pom, the version update tag after the version should name the unreleased package and the dependency version:
330330
# <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
331+
unreleased_com.azure:azure-core;1.22.0-beta.1
331332

332333
# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
333334
# version and set the version to the released beta. Released beta dependencies are only valid

sdk/formrecognizer/azure-ai-formrecognizer/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>com.azure</groupId>
4747
<artifactId>azure-core</artifactId>
48-
<version>1.21.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
48+
<version>1.22.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
4949
</dependency>
5050
<dependency>
5151
<groupId>com.azure</groupId>

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/DocumentAnalysisAsyncClient.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public final class DocumentAnalysisAsyncClient {
8181
* or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
8282
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation} returns
8383
* with an {@link OperationStatus#FAILED}..
84-
* @throws NullPointerException If {@code documentUrl} or {@code modelId} is null.
84+
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
8585
*/
8686
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
8787
public PollerFlux<DocumentOperationResult, AnalyzeResult>
@@ -107,7 +107,7 @@ public final class DocumentAnalysisAsyncClient {
107107
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
108108
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation} returns
109109
* with an {@link OperationStatus#FAILED}.
110-
* @throws NullPointerException If {@code documentUrl} or {@code modelId} is null.
110+
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
111111
*/
112112
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
113113
public PollerFlux<DocumentOperationResult, AnalyzeResult>
@@ -121,9 +121,13 @@ public final class DocumentAnalysisAsyncClient {
121121
AnalyzeDocumentOptions analyzeDocumentOptions,
122122
Context context) {
123123
try {
124-
Objects.requireNonNull(documentUrl, "'documentUrl' is required and cannot be null.");
125-
Objects.requireNonNull(modelId, "'modelId' is required and cannot be null.");
126-
124+
if (CoreUtils.isNullOrEmpty(documentUrl)) {
125+
throw logger.logExceptionAsError(new IllegalArgumentException("'documentUrl' is required and cannot"
126+
+ " be null or empty"));
127+
} if (CoreUtils.isNullOrEmpty(modelId)) {
128+
throw logger.logExceptionAsError(new IllegalArgumentException("'modelId' is required and cannot"
129+
+ " be null or empty"));
130+
}
127131
final AnalyzeDocumentOptions finalAnalyzeDocumentOptions
128132
= getAnalyzeDocumentOptions(analyzeDocumentOptions);
129133
return new PollerFlux<>(
@@ -180,7 +184,7 @@ public final class DocumentAnalysisAsyncClient {
180184
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
181185
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation} returns
182186
* with an {@link OperationStatus#FAILED}.
183-
* @throws NullPointerException If {@code document} or {@code modelId} is null.
187+
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
184188
*/
185189
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
186190
public PollerFlux<DocumentOperationResult, AnalyzeResult>
@@ -211,7 +215,7 @@ public final class DocumentAnalysisAsyncClient {
211215
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
212216
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation} returns
213217
* with an {@link OperationStatus#FAILED}..
214-
* @throws NullPointerException If {@code document} or {@code modelId} is null.
218+
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
215219
*/
216220
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
217221
public PollerFlux<DocumentOperationResult, AnalyzeResult>
@@ -225,7 +229,10 @@ public final class DocumentAnalysisAsyncClient {
225229
AnalyzeDocumentOptions analyzeDocumentOptions, Context context) {
226230
try {
227231
Objects.requireNonNull(document, "'document' is required and cannot be null.");
228-
Objects.requireNonNull(modelId, "'modelId' is required and cannot be null.");
232+
if (CoreUtils.isNullOrEmpty(modelId)) {
233+
throw logger.logExceptionAsError(new IllegalArgumentException("'modelId' is required and cannot"
234+
+ " be null or empty"));
235+
}
229236

230237
final AnalyzeDocumentOptions finalAnalyzeDocumentOptions
231238
= getAnalyzeDocumentOptions(analyzeDocumentOptions);

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/DocumentAnalysisClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public final class DocumentAnalysisClient {
6262
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
6363
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation} returns
6464
* with an {@link OperationStatus#FAILED}..
65-
* @throws NullPointerException If {@code documentUrl} or {@code modelId} is null.
65+
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
6666
*/
6767
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
6868
public SyncPoller<DocumentOperationResult, AnalyzeResult>
@@ -90,7 +90,7 @@ public final class DocumentAnalysisClient {
9090
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
9191
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation}returns
9292
* with an {@link OperationStatus#FAILED}.
93-
* @throws NullPointerException If {@code documentUrl} or {@code modelId} is null.
93+
* @throws IllegalArgumentException If {@code documentUrl} or {@code modelId} is null.
9494
*/
9595
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
9696
public SyncPoller<DocumentOperationResult, AnalyzeResult>
@@ -118,7 +118,7 @@ public final class DocumentAnalysisClient {
118118
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
119119
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation}returns
120120
* with an {@link OperationStatus#FAILED}.
121-
* @throws NullPointerException If {@code document} or {@code modelId} is null.
121+
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
122122
*/
123123
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
124124
public SyncPoller<DocumentOperationResult, AnalyzeResult>
@@ -147,7 +147,7 @@ public final class DocumentAnalysisClient {
147147
* has failed, or has been cancelled. The completed operation returns an {@link AnalyzeResult}.
148148
* @throws DocumentAnalysisException If analyze operation fails and the {@link AnalyzeResultOperation} returns
149149
* with an {@link OperationStatus#FAILED}.
150-
* @throws NullPointerException If {@code document} or {@code modelId} is null.
150+
* @throws IllegalArgumentException If {@code document} or {@code modelId} is null.
151151
*/
152152
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
153153
public SyncPoller<DocumentOperationResult, AnalyzeResult>

sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/DocumentAnalysisAsyncClientTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
package com.azure.ai.formrecognizer;
55

6+
import com.azure.ai.formrecognizer.administration.models.FormRecognizerError;
67
import com.azure.ai.formrecognizer.implementation.util.Utility;
78
import com.azure.ai.formrecognizer.models.AnalyzeDocumentOptions;
8-
import com.azure.ai.formrecognizer.models.DocumentOperationResult;
99
import com.azure.ai.formrecognizer.models.AnalyzeResult;
10-
import com.azure.ai.formrecognizer.administration.models.FormRecognizerError;
10+
import com.azure.ai.formrecognizer.models.DocumentOperationResult;
1111
import com.azure.core.exception.HttpResponseException;
1212
import com.azure.core.http.HttpClient;
1313
import com.azure.core.util.polling.SyncPoller;
@@ -63,7 +63,7 @@ static void afterAll() {
6363

6464
private DocumentAnalysisAsyncClient getDocumentAnalysisAsyncClient(HttpClient httpClient,
6565
DocumentAnalysisServiceVersion serviceVersion) {
66-
return getDocumentAnalysisBuilder(httpClient, serviceVersion).buildAsyncClient();
66+
return getDocumentAnalysisBuilder(httpClient, serviceVersion, false).buildAsyncClient();
6767
}
6868

6969
// Receipt recognition

sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/DocumentAnalysisClientTest.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.junit.jupiter.api.AfterAll;
1919
import org.junit.jupiter.api.Assertions;
2020
import org.junit.jupiter.api.BeforeAll;
21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.params.ParameterizedTest;
2322
import org.junit.jupiter.params.provider.MethodSource;
2423
import reactor.test.StepVerifier;
@@ -72,12 +71,12 @@ static void afterAll() {
7271

7372
private DocumentAnalysisClient getDocumentAnalysisClient(HttpClient httpClient,
7473
DocumentAnalysisServiceVersion serviceVersion) {
75-
return getDocumentAnalysisBuilder(httpClient, serviceVersion).buildClient();
74+
return getDocumentAnalysisBuilder(httpClient, serviceVersion, false).buildClient();
7675
}
7776

7877
private DocumentModelAdministrationClient getDocumentModelAdminClient(HttpClient httpClient,
7978
DocumentAnalysisServiceVersion serviceVersion) {
80-
return getDocumentModelAdminClientBuilder(httpClient, serviceVersion).buildClient();
79+
return getDocumentModelAdminClientBuilder(httpClient, serviceVersion, false).buildClient();
8180
}
8281

8382
// Receipt recognition
@@ -543,9 +542,7 @@ public void analyzeGermanContentFromUrl(HttpClient httpClient,
543542
*/
544543
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
545544
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
546-
@Disabled
547545
public void analyzeCustomDocument(HttpClient httpClient, DocumentAnalysisServiceVersion serviceVersion) {
548-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
549546
client = getDocumentAnalysisClient(httpClient, serviceVersion);
550547
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
551548
dataRunner((data, dataLength) ->
@@ -576,10 +573,8 @@ public void analyzeCustomDocument(HttpClient httpClient, DocumentAnalysisService
576573
*/
577574
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
578575
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
579-
@Disabled
580576
public void analyzeCustomDocumentBlankPdf(HttpClient httpClient,
581577
DocumentAnalysisServiceVersion serviceVersion) {
582-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
583578
client = getDocumentAnalysisClient(httpClient, serviceVersion);
584579
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
585580
dataRunner((data, dataLength) ->
@@ -610,10 +605,9 @@ public void analyzeCustomDocumentBlankPdf(HttpClient httpClient,
610605
*/
611606
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
612607
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
613-
@Disabled
614608
public void analyzeCustomDocumentWithNullData(HttpClient httpClient,
615609
DocumentAnalysisServiceVersion serviceVersion) {
616-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
610+
617611
client = getDocumentAnalysisClient(httpClient, serviceVersion);
618612
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
619613
dataRunner((data, dataLength) ->
@@ -659,22 +653,16 @@ public void analyzeCustomDocumentWithNullModelId(HttpClient httpClient,
659653
*/
660654
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
661655
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
662-
@Disabled
663656
public void analyzeCustomDocumentWithEmptyModelId(HttpClient httpClient,
664657
DocumentAnalysisServiceVersion serviceVersion) {
665-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
666658
client = getDocumentAnalysisClient(httpClient, serviceVersion);
667659

668660
dataRunner((data, dataLength) -> {
669-
HttpResponseException errorResponseException = Assertions.assertThrows(HttpResponseException.class,
661+
Assertions.assertThrows(IllegalArgumentException.class,
670662
() -> client.beginAnalyzeDocument("",
671663
data,
672664
dataLength)
673665
.setPollInterval(durationTestMode));
674-
FormRecognizerError errorInformation
675-
= (FormRecognizerError) errorResponseException.getValue();
676-
Assertions.assertEquals(404, errorResponseException.getResponse().getStatusCode());
677-
Assertions.assertEquals("ModelNotFound", errorInformation.getInnerError().getCode());
678666
}, INVOICE_6_PDF);
679667
}
680668

@@ -683,10 +671,9 @@ public void analyzeCustomDocumentWithEmptyModelId(HttpClient httpClient,
683671
*/
684672
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
685673
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
686-
@Disabled
687674
public void analyzeCustomDocumentWithContentTypeAutoDetection(HttpClient httpClient,
688675
DocumentAnalysisServiceVersion serviceVersion) {
689-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
676+
690677
client = getDocumentAnalysisClient(httpClient, serviceVersion);
691678
client = getDocumentAnalysisClient(httpClient, serviceVersion);
692679
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
@@ -715,10 +702,9 @@ public void analyzeCustomDocumentWithContentTypeAutoDetection(HttpClient httpCli
715702

716703
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
717704
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
718-
@Disabled
719705
public void analyzeCustomDocumentMultiPage(HttpClient httpClient,
720706
DocumentAnalysisServiceVersion serviceVersion) {
721-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
707+
722708
client = getDocumentAnalysisClient(httpClient, serviceVersion);
723709
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
724710
dataRunner((data, dataLength) -> multipageTrainingRunner((trainingFilesUrl) -> {
@@ -744,10 +730,8 @@ public void analyzeCustomDocumentMultiPage(HttpClient httpClient,
744730

745731
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
746732
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
747-
@Disabled
748733
public void analyzeCustomDocumentWithSelectionMark(HttpClient httpClient,
749734
DocumentAnalysisServiceVersion serviceVersion) {
750-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
751735
client = getDocumentAnalysisClient(httpClient, serviceVersion);
752736
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
753737
dataRunner((data, dataLength) ->
@@ -779,14 +763,11 @@ public void analyzeCustomDocumentWithSelectionMark(HttpClient httpClient,
779763
*/
780764
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
781765
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
782-
@Disabled
783766
public void analyzeCustomDocumentUrl(HttpClient httpClient,
784767
DocumentAnalysisServiceVersion serviceVersion) {
785-
// null values reported
786-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
787768
client = getDocumentAnalysisClient(httpClient, serviceVersion);
788769
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
789-
urlRunner((fileUrl) -> multipageTrainingRunner((trainingFilesUrl) -> {
770+
urlRunner((fileUrl) -> buildModelRunner((trainingFilesUrl) -> {
790771
SyncPoller<DocumentOperationResult, DocumentModel> buildModelPoller
791772
= adminClient
792773
.beginBuildModel(trainingFilesUrl, null)
@@ -904,10 +885,8 @@ public void analyzeCustomDocumentUrlNonExistModelId(HttpClient httpClient,
904885
*/
905886
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
906887
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
907-
@Disabled
908888
public void analyzeCustomDocumentDamagedPdf(HttpClient httpClient,
909889
DocumentAnalysisServiceVersion serviceVersion) {
910-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
911890
client = getDocumentAnalysisClient(httpClient, serviceVersion);
912891
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
913892
damagedPdfDataRunner((data, dataLength) ->
@@ -929,16 +908,14 @@ public void analyzeCustomDocumentDamagedPdf(HttpClient httpClient,
929908

930909
FormRecognizerError errorInformation
931910
= (FormRecognizerError) httpResponseException.getValue();
932-
Assertions.assertEquals("Invalid input file.", errorInformation.getMessage());
911+
Assertions.assertEquals("InvalidContent", errorInformation.getInnerError().getCode());
933912
})));
934913
}
935914

936915
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
937916
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
938-
@Disabled
939917
public void analyzeCustomDocumentUrlWithSelectionMark(HttpClient httpClient,
940918
DocumentAnalysisServiceVersion serviceVersion) {
941-
// TODO: (https://github.com/Azure/azure-sdk-for-java-pr/issues/1353)
942919
DocumentModelAdministrationClient adminClient = getDocumentModelAdminClient(httpClient, serviceVersion);
943920
urlRunner(fileUrl -> selectionMarkTrainingRunner((trainingFilesUrl) -> {
944921
client = getDocumentAnalysisClient(httpClient, serviceVersion);
@@ -1278,7 +1255,6 @@ public void analyzeInvoiceSourceUrl(HttpClient httpClient, DocumentAnalysisServi
12781255
*/
12791256
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
12801257
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
1281-
@Disabled("https://github.com/Azure/azure-sdk-for-java/issues/21687")
12821258
public void analyzeInvoiceFromUrlWithEncodedBlankSpaceSourceUrl(HttpClient httpClient,
12831259
DocumentAnalysisServiceVersion serviceVersion) {
12841260
client = getDocumentAnalysisClient(httpClient, serviceVersion);

0 commit comments

Comments
 (0)