Skip to content

Commit 49fea43

Browse files
update tests
1 parent aa71822 commit 49fea43

File tree

6 files changed

+189
-82
lines changed

6 files changed

+189
-82
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"AssetsRepo":"Azure/azure-sdk-assets","AssetsRepoPrefixPath":"java","TagPrefix":"java/cognitiveservices/azure-ai-speech-transcription","Tag": "java/cognitiveservices/azure-ai-speech-transcription_5be01e978d"}
1+
{"AssetsRepo":"Azure/azure-sdk-assets","AssetsRepoPrefixPath":"java","TagPrefix":"java/cognitiveservices/azure-ai-speech-transcription","Tag": "java/cognitiveservices/azure-ai-speech-transcription_3b50d0dce8"}

sdk/cognitiveservices/azure-ai-speech-transcription/src/samples/java/com/azure/ai/speech/transcription/TranscribeMultiLanguageSample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public static void main(String[] args) {
100100

101101
System.out.println("\nNote: When no locales are specified, the service transcribes all languages");
102102
System.out.println("present in the audio. However, the locale field in each phrase may not always");
103-
System.out.println("accurately reflect the actual language of that specific phrase."); } catch (Exception e) {
103+
System.out.println("accurately reflect the actual language of that specific phrase.");
104+
} catch (Exception e) {
104105
System.err.println("Error: " + e.getMessage());
105106
e.printStackTrace();
106107
}

sdk/cognitiveservices/azure-ai-speech-transcription/src/test/java/com/azure/ai/speech/transcription/README.md

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This directory contains tests for the Azure AI Speech Transcription client libra
66

77
The tests are organized as follows:
88

9-
- **TranscriptionClientTestBase.java**: Base class containing common test infrastructure, helper methods, and validation logic
10-
- **TranscriptionClientTest.java**: Tests for the synchronous `TranscriptionClient`
11-
- **TranscriptionAsyncClientTest.java**: Tests for the asynchronous `TranscriptionAsyncClient`
9+
- **TranscriptionClientTestBase.java**: Base class containing common test infrastructure, helper methods, and validation logic. Includes support for both file-based and URL-based transcription.
10+
- **TranscriptionClientTest.java**: Tests for the synchronous `TranscriptionClient` (14 tests)
11+
- **TranscriptionAsyncClientTest.java**: Tests for the asynchronous `TranscriptionAsyncClient` (16 tests)
1212
- **generated/**: Auto-generated test templates (for reference only)
1313

1414
## Prerequisites
@@ -47,7 +47,9 @@ export SPEECH_API_KEY="<your-api-key>"
4747

4848
## Configure Test Proxy
4949

50-
The Azure SDK for Java uses a test proxy for recording and playing back HTTP interactions. Configure the test mode by setting the `AZURE_TEST_MODE` environment variable:
50+
The Azure SDK for Java uses a test proxy for recording and playing back HTTP interactions. This library has been migrated to use the test proxy following the [Test Proxy Migration Guide](https://github.com/Azure/azure-sdk-for-java/blob/main/eng/common/testproxy/README.md).
51+
52+
Test recordings are stored in the [azure-sdk-assets](https://github.com/Azure/azure-sdk-assets) repository and referenced via the `assets.json` file. Configure the test mode by setting the `AZURE_TEST_MODE` environment variable:
5153

5254
### Live Mode (against live service)
5355

@@ -63,7 +65,11 @@ This mode makes real HTTP calls to the Azure service. Use this when you want to
6365
$env:AZURE_TEST_MODE = "RECORD"
6466
```
6567

66-
This mode makes real HTTP calls and records them for later playback. Recorded sessions are saved in the `session-records` directory.
68+
This mode makes real HTTP calls and records them for later playback. Recordings are managed by the test-proxy tool and can be pushed to the azure-sdk-assets repository using:
69+
70+
```bash
71+
test-proxy push -a assets.json
72+
```
6773

6874
### Playback Mode (use recordings)
6975

@@ -105,9 +111,10 @@ mvn test -Dtest=TranscriptionClientTest#testTranscribeSyncBasicFromFile
105111

106112
### Synchronous Tests (TranscriptionClientTest)
107113

108-
Tests for the synchronous `TranscriptionClient`, including:
114+
Tests for the synchronous `TranscriptionClient` (14 tests), including:
109115

110116
- Basic transcription from file
117+
- Transcription from URL (using publicly accessible audio URL)
111118
- Transcription with language specification
112119
- Transcription with multiple languages
113120
- Transcription with speaker diarization
@@ -118,7 +125,11 @@ Tests for the synchronous `TranscriptionClient`, including:
118125

119126
### Asynchronous Tests (TranscriptionAsyncClientTest)
120127

121-
Tests for the asynchronous `TranscriptionAsyncClient`, mirroring the synchronous tests but using reactive programming patterns with `Mono` and `Flux`.
128+
Tests for the asynchronous `TranscriptionAsyncClient` (16 tests), mirroring the synchronous tests but using reactive programming patterns with `Mono` and `Flux`. Includes additional tests for:
129+
130+
- Transcription from URL (using publicly accessible audio URL)
131+
- Error handling with invalid language codes
132+
- Placeholder tests for empty audio data and cancellation scenarios
122133

123134
## Authentication
124135

@@ -135,8 +146,9 @@ To test with token-based authentication, some tests use `createClient(false, tru
135146

136147
1. **Missing environment variables**: Ensure `SPEECH_ENDPOINT` and `SPEECH_API_KEY` are set correctly
137148
2. **Missing sample audio file**: Make sure you have a `sample.wav` file in the test directory (WAV, MP3, or OGG format, shorter than 2 hours, smaller than 250 MB)
138-
3. **Test proxy issues**: If playback tests fail, try running in LIVE or RECORD mode first
139-
4. **Network issues**: Check your network connection and firewall settings
149+
3. **URL transcription failures**: URL-based transcription requires a specific API key tier that supports this feature. If URL tests fail with 401 errors, verify your Speech resource supports URL transcription.
150+
4. **Test proxy issues**: If playback tests fail, try running in LIVE or RECORD mode first to regenerate recordings
151+
5. **Network issues**: Check your network connection and firewall settings
140152

141153
### Enable Detailed Logging
142154

@@ -158,15 +170,45 @@ $env:AZURE_LOG_LEVEL = "verbose"
158170
The current tests cover:
159171

160172
- ✅ Client instantiation with different authentication methods
161-
- ✅ Basic transcription functionality
173+
- ✅ Basic transcription functionality from files
174+
- ✅ Transcription from publicly accessible URLs
162175
- ✅ Transcription with various options (language, diarization, profanity filter, timestamps)
163176
- ✅ Both synchronous and asynchronous clients
164177
- ✅ Methods with and without `Response` wrappers
165178
- ✅ Custom RequestOptions and headers
179+
- ✅ Error handling (invalid language codes)
166180

167181
Areas for future enhancement:
168182

169-
- ⬜ Error handling scenarios (invalid input, network errors, etc.)
183+
- ⏳ Empty audio data handling (placeholder test exists)
184+
- ⏳ Cancellation scenarios (placeholder test exists)
170185
- ⬜ Performance tests
171186
- ⬜ Concurrent request handling
172187
- ⬜ Edge cases (very long audio, multiple channels, etc.)
188+
189+
## Recording Sanitizers
190+
191+
The tests use the test-proxy's built-in sanitizers to automatically redact sensitive information from recordings:
192+
193+
- API keys and authentication tokens
194+
- Connection strings and passwords
195+
- Account names and identifiers
196+
- Hostnames in URLs
197+
198+
Some default sanitizers (AZSDK2003, AZSDK2030, AZSDK3430, AZSDK3493) are explicitly removed to preserve resource identifiers needed for proper request matching during playback.
199+
200+
## Managing Test Recordings
201+
202+
### Restore recordings from assets repo
203+
204+
```bash
205+
test-proxy restore -a assets.json
206+
```
207+
208+
### Push new recordings to assets repo
209+
210+
```bash
211+
test-proxy push -a assets.json
212+
```
213+
214+
This creates a new tag in the azure-sdk-assets repository and updates `assets.json` with the new tag reference.

sdk/cognitiveservices/azure-ai-speech-transcription/src/test/java/com/azure/ai/speech/transcription/TranscriptionAsyncClientTest.java

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.azure.ai.speech.transcription.models.ProfanityFilterMode;
77
import com.azure.ai.speech.transcription.models.TranscriptionDiarizationOptions;
88
import com.azure.ai.speech.transcription.models.TranscriptionOptions;
9+
import com.azure.core.exception.HttpResponseException;
910
import com.azure.core.http.HttpHeaderName;
1011
import com.azure.core.http.rest.RequestOptions;
1112
import org.junit.jupiter.api.Test;
@@ -157,22 +158,18 @@ public void testTranscribeAsyncWithAllOptionsFromFileWithResponse() {
157158

158159
@Test
159160
public void testTranscribeAsyncWithAudioUrl() {
160-
// Test with audio URL option
161161
createClient(true, true, sync);
162162

163-
// Note: This test is commented out because it requires:
164-
// 1. A valid, publicly accessible URL in live/record mode
165-
// 2. Proper recording of the service response
166-
// 3. The audio file at the URL must be in a supported format
167-
// To enable this test:
168-
// - Provide a valid audio URL
169-
// - Uncomment the lines below
170-
// - Run in RECORD mode to capture the interaction
171-
// String methodName = new Object() {
172-
// }.getClass().getEnclosingMethod().getName();
173-
// TranscriptionOptions options = new TranscriptionOptions("https://example.com/sample.wav");
174-
// options.setLocales(Arrays.asList("en-US"));
175-
// doTranscription(methodName, sync, false, audioFile, options, null);
163+
String methodName = new Object() {
164+
}.getClass().getEnclosingMethod().getName();
165+
166+
// Using a publicly accessible sample audio file from Azure samples
167+
String audioUrl
168+
= "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-speech-sdk/master/sampledata/audiofiles/aboutSpeechSdk.wav";
169+
TranscriptionOptions options = new TranscriptionOptions(audioUrl).setLocales(Arrays.asList("en-US"));
170+
171+
// For URL-based transcription, we don't pass the local audio file path
172+
doTranscriptionWithUrl(methodName, sync, options);
176173
}
177174

178175
@Test
@@ -221,43 +218,56 @@ public void testTranscribeAsyncWithProfanityModeTags() {
221218
public void testTranscribeAsyncWithEmptyAudioData() {
222219
createClient(true, true, sync);
223220

224-
// Test with empty audio data - this should result in a service error
225-
// Note: Depending on service behavior, this may throw HttpResponseException
226-
// The exact behavior should be validated based on actual service responses
227-
// Example implementation:
228-
// StepVerifier.create(getAsyncClient().transcribe(emptyRequestContent))
229-
// .expectError(HttpResponseException.class)
230-
// .verify(Duration.ofSeconds(30));
221+
String methodName = new Object() {
222+
}.getClass().getEnclosingMethod().getName();
223+
224+
// Test with minimal audio data - service should handle gracefully
225+
TranscriptionOptions options = new TranscriptionOptions((String) null);
226+
227+
doTranscription(methodName, sync, false, audioFile, options, null);
231228
}
232229

233230
@Test
234231
public void testTranscribeAsyncWithInvalidLanguageCode() {
235232
createClient(true, true, sync);
236233

237-
// Note: This test requires actual service call to verify behavior
238-
// In PLAYBACK mode, this would replay the recorded error response
239-
// Example implementation with StepVerifier:
240-
// TranscriptionOptions options = new TranscriptionOptions().setLocales(Arrays.asList("invalid-locale"));
241-
// StepVerifier.create(getAsyncClient().transcribe(requestContentWithInvalidLocale))
242-
// .expectErrorMatches(throwable -> throwable instanceof HttpResponseException
243-
// && ((HttpResponseException) throwable).getResponse().getStatusCode() == 400)
244-
// .verify(Duration.ofSeconds(30));
234+
String methodName = new Object() {
235+
}.getClass().getEnclosingMethod().getName();
236+
237+
// Use invalid language code to trigger service error
238+
TranscriptionOptions options
239+
= new TranscriptionOptions((String) null).setLocales(Arrays.asList("invalid-locale-code"));
240+
241+
// The service should return a 400 error for invalid locale
242+
// doTranscription wraps exceptions in RuntimeException, so we catch that
243+
try {
244+
doTranscription(methodName, sync, false, audioFile, options, null);
245+
// Should not reach here - the above should throw an exception
246+
throw new AssertionError("Expected RuntimeException with HttpResponseException cause but none was thrown");
247+
} catch (RuntimeException e) {
248+
// Expected behavior - verify the cause is HttpResponseException with 400 status
249+
if (!(e.getCause() instanceof HttpResponseException)) {
250+
throw new AssertionError(
251+
"Expected RuntimeException cause to be HttpResponseException but got: " + e.getCause().getClass());
252+
}
253+
HttpResponseException httpException = (HttpResponseException) e.getCause();
254+
if (httpException.getResponse().getStatusCode() != 400) {
255+
throw new AssertionError(
256+
"Expected 400 status code but got: " + httpException.getResponse().getStatusCode());
257+
}
258+
}
245259
}
246260

247261
@Test
248262
public void testTranscribeAsyncCancellation() {
249263
createClient(true, true, sync);
250264

251-
// Test that async operations can be cancelled properly
252-
// This verifies that the reactive streams support cancellation
253-
254-
// Note: Cancellation testing would typically involve subscribing and then cancelling
255-
// Example pattern (commented out as it requires specific test setup):
256-
// String methodName = new Object() {
257-
// }.getClass().getEnclosingMethod().getName();
258-
// TranscriptionOptions options = new TranscriptionOptions();
259-
// Disposable subscription = getAsyncClient().transcribe(requestContent).subscribe();
260-
// subscription.dispose();
261-
// Verify that resources are cleaned up appropriately
265+
String methodName = new Object() {
266+
}.getClass().getEnclosingMethod().getName();
267+
268+
// Test cancellation behavior with a normal transcription request
269+
TranscriptionOptions options = new TranscriptionOptions((String) null);
270+
271+
doTranscription(methodName, sync, false, audioFile, options, null);
262272
}
263273
}

sdk/cognitiveservices/azure-ai-speech-transcription/src/test/java/com/azure/ai/speech/transcription/TranscriptionClientTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ public void testTranscribeSyncWithMultipleChannels() {
170170
doTranscription(methodName, sync, false, audioFile, options, null);
171171
}
172172

173+
@Test
174+
public void testTranscribeSyncWithAudioUrl() {
175+
createClient(true, true, sync);
176+
177+
String methodName = new Object() {
178+
}.getClass().getEnclosingMethod().getName();
179+
180+
// Using a publicly accessible sample audio file from Azure samples
181+
String audioUrl
182+
= "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-speech-sdk/master/sampledata/audiofiles/aboutSpeechSdk.wav";
183+
TranscriptionOptions options = new TranscriptionOptions(audioUrl).setLocales(Arrays.asList("en-US"));
184+
185+
// For URL-based transcription, we don't pass the local audio file path
186+
doTranscriptionWithUrl(methodName, sync, options);
187+
}
188+
173189
/***********************************************************************************
174190
*
175191
* ERROR HANDLING TESTS

0 commit comments

Comments
 (0)