Skip to content

Commit a968bc6

Browse files
authored
Fix Form Recognizer tests (Azure#27984)
1 parent 2044f46 commit a968bc6

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/administration/DocumentModelAdministrationAsyncClientTest.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
4343
import static org.junit.jupiter.api.Assertions.assertEquals;
4444
import static org.junit.jupiter.api.Assertions.assertNotNull;
45-
import static org.junit.jupiter.api.Assertions.assertThrows;
4645
import static org.junit.jupiter.api.Assertions.assertTrue;
4746
import static org.junit.jupiter.api.Assertions.fail;
4847

@@ -140,11 +139,12 @@ public void deleteModelValidModelIdWithResponse(HttpClient httpClient,
140139
@MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters")
141140
public void copyAuthorization(HttpClient httpClient, DocumentAnalysisServiceVersion serviceVersion) {
142141
client = getDocumentModelAdminAsyncClient(httpClient, serviceVersion);
143-
StepVerifier.create(client.getCopyAuthorization())
144-
.assertNext(DocumentModelAdministrationClientTestBase::validateCopyAuthorizationResult)
142+
String modelId = "java_copy_model_test";
143+
StepVerifier.create(client.getCopyAuthorizationWithResponse(new CopyAuthorizationOptions().setModelId(modelId)))
144+
.assertNext(response -> validateCopyAuthorizationResult(response.getValue()))
145145
.verifyComplete();
146146

147-
StepVerifier.create(client.deleteModel("java_copy_model_test")).verifyComplete();
147+
StepVerifier.create(client.deleteModel(modelId)).verifyComplete();
148148
}
149149

150150
/**
@@ -157,15 +157,15 @@ public void beginCreateComposedModel(HttpClient httpClient, DocumentAnalysisServ
157157
client = getDocumentModelAdminAsyncClient(httpClient, serviceVersion);
158158
buildModelRunner((trainingFilesUrl) -> {
159159
SyncPoller<DocumentOperationResult, DocumentModel> syncPoller1 =
160-
client.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE
161-
)
160+
client.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE,
161+
new BuildModelOptions().setModelId("async_component_model_1"))
162162
.setPollInterval(durationTestMode).getSyncPoller();
163163
syncPoller1.waitForCompletion();
164164
DocumentModel createdModel1 = syncPoller1.getFinalResult();
165165

166166
SyncPoller<DocumentOperationResult, DocumentModel> syncPoller2 =
167-
client.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE
168-
)
167+
client.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE,
168+
new BuildModelOptions().setModelId("async_component_model_2"))
169169
.setPollInterval(durationTestMode).getSyncPoller();
170170
syncPoller2.waitForCompletion();
171171
DocumentModel createdModel2 = syncPoller2.getFinalResult();
@@ -335,15 +335,14 @@ public void beginBuildModelFailsWithInvalidPrefix(HttpClient httpClient, Documen
335335
client = getDocumentModelAdminAsyncClient(httpClient, serviceVersion);
336336

337337
buildModelRunner((trainingFilesUrl) -> {
338-
HttpResponseException httpResponseException = assertThrows(HttpResponseException.class,
339-
() -> client.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE,
340-
new BuildModelOptions().setPrefix("subfolder"))
341-
.setPollInterval(durationTestMode)
342-
.getSyncPoller()
343-
.getFinalResult());
344-
345-
ResponseError responseError = (ResponseError) httpResponseException.getValue();
346-
Assertions.assertEquals("InvalidRequest", responseError.getCode());
338+
StepVerifier.create(client.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE,
339+
new BuildModelOptions().setPrefix("invalidPrefix"))
340+
.setPollInterval(durationTestMode))
341+
.verifyErrorSatisfies(throwable -> {
342+
assertEquals(HttpResponseException.class, throwable.getClass());
343+
final ResponseError responseError = (ResponseError) ((HttpResponseException) throwable).getValue();
344+
assertEquals("InvalidRequest", responseError.getCode());
345+
});
347346
});
348347
}
349348

@@ -430,14 +429,14 @@ public void beginCopyWithOptions(HttpClient httpClient, DocumentAnalysisServiceV
430429
public void listModels(HttpClient httpClient, DocumentAnalysisServiceVersion serviceVersion) {
431430
client = getDocumentModelAdminAsyncClient(httpClient, serviceVersion);
432431
StepVerifier.create(client.listModels().byPage().take(4))
433-
.thenConsumeWhile(documentModelInfoPagedResponse -> {
434-
documentModelInfoPagedResponse.getValue()
435-
.forEach(documentModelInfo -> {
436-
assertNotNull(documentModelInfo.getModelId());
437-
assertNotNull(documentModelInfo.getCreatedOn());
438-
});
439-
return true;
440-
}).verifyComplete();
432+
.thenConsumeWhile(documentModelInfoPagedResponse -> {
433+
documentModelInfoPagedResponse.getValue()
434+
.forEach(documentModelInfo -> {
435+
assertNotNull(documentModelInfo.getModelId());
436+
assertNotNull(documentModelInfo.getCreatedOn());
437+
});
438+
return true;
439+
}).verifyComplete();
441440
}
442441

443442
/**

sdk/formrecognizer/azure-ai-formrecognizer/src/test/resources/session-records/DocumentModelAdministrationAsyncClientTest.beginBuildModelFailsWithInvalidPrefix[1].json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
"Method" : "POST",
44
"Uri" : "https://REDACTED.cognitiveservices.azure.com/formrecognizer/documentModels:build?api-version=2022-01-30-preview",
55
"Headers" : {
6-
"User-Agent" : "azsdk-java-azure-ai-formrecognizer/4.0.0-beta.4 (11.0.9; Windows 10; 10.0)",
7-
"x-ms-client-request-id" : "2aa63960-25f3-4ce6-aeba-4dac7f83b338",
6+
"User-Agent" : "azsdk-java-azure-ai-formrecognizer/4.0.0-beta.5 (11.0.9; Windows 10; 10.0)",
7+
"x-ms-client-request-id" : "7bf5cb23-eaea-445f-909b-f502834b7eb6",
88
"Content-Type" : "application/json"
99
},
1010
"Response" : {
1111
"Transfer-Encoding" : "chunked",
12-
"x-envoy-upstream-service-time" : "873",
12+
"x-envoy-upstream-service-time" : "779",
1313
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
1414
"x-content-type-options" : "nosniff",
15-
"apim-request-id" : "9f188eb7-9b0d-421b-95b0-4471ffd5a548",
15+
"apim-request-id" : "d65fe876-84a0-4929-8748-12aab60974df",
1616
"retry-after" : "0",
1717
"StatusCode" : "400",
1818
"Body" : "{\n \"error\": {\n \"code\": \"InvalidRequest\",\n \"message\": \"Invalid request.\",\n \"innererror\": {\n \"code\": \"TrainingContentMissing\",\n \"message\": \"Training data is missing: Could not find any training data at the given path.\"\n }\n }\n}",
19-
"Date" : "Thu, 27 Jan 2022 23:47:09 GMT",
19+
"Date" : "Tue, 05 Apr 2022 18:44:17 GMT",
2020
"Content-Type" : "application/json"
2121
},
2222
"Exception" : null

0 commit comments

Comments
 (0)