-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Unit test for CallClientBuilder and other small fixes #21964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zihzhan-msft
merged 1 commit into
feature/communication-ServerCalling
from
arifsaikat/public-preview-unit-tests
May 31, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...ingserver/src/test/java/com/azure/communication/callingserver/CallClientBuilderTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.azure.communication.callingserver; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import java.net.MalformedURLException; | ||
| import java.security.InvalidKeyException; | ||
| import java.security.NoSuchAlgorithmException; | ||
|
|
||
| import com.azure.core.credential.AzureKeyCredential; | ||
| import com.azure.core.http.HttpClient; | ||
| import com.azure.core.http.HttpPipelineBuilder; | ||
| import com.azure.core.http.HttpRequest; | ||
| import com.azure.core.http.HttpResponse; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import reactor.core.publisher.Mono; | ||
|
|
||
| public class CallClientBuilderTests { | ||
| static final String MOCK_URL = "https://REDACTED.communication.azure.com"; | ||
| static final String MOCK_ACCESS_KEY = "eyKfcHciOiJIUzI1NiIsInR5cCI6IkqXVCJ9eyJzdWIiOiIxMjM0NTY5ODkwIiwibmFtZSI7IkpvaGfQSflKxwRJSMeKKF2QT4fwpMeJf36POk6yJVadUs4s5d"; | ||
| static final String MOCK_CONNECTION_STRING = "endpoint=https://REDACTED.communication.azure.com/;accesskey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaGfQSflKxwRJSMeKKF2QT4fwpMeJf36POk6yJVadQssw5c"; | ||
|
|
||
| static class NoOpHttpClient implements HttpClient { | ||
| @Override | ||
| public Mono<HttpResponse> send(HttpRequest request) { | ||
| return Mono.empty(); // NOP | ||
| } | ||
| } | ||
|
|
||
| private final CallClientBuilder builder = new CallClientBuilder(); | ||
|
|
||
| @Test | ||
| public void missingTokenCredentialTest() | ||
| throws NullPointerException, MalformedURLException, InvalidKeyException, NoSuchAlgorithmException { | ||
| builder | ||
| .endpoint(MOCK_URL) | ||
| .httpClient(new NoOpHttpClient()); | ||
| assertThrows(Exception.class, () -> { | ||
| builder.buildAsyncClient(); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void missingUrlTest() | ||
| throws NullPointerException, MalformedURLException { | ||
| builder | ||
| .credential(new AzureKeyCredential(MOCK_ACCESS_KEY)) | ||
| .httpClient(new NoOpHttpClient()); | ||
| assertThrows(Exception.class, () -> { | ||
| builder.buildAsyncClient(); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullPipelineTest() { | ||
| assertThrows(NullPointerException.class, () -> { | ||
| builder | ||
| .connectionString(MOCK_CONNECTION_STRING) | ||
| .httpClient(new NoOpHttpClient()) | ||
| .pipeline(null); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullCustomPolicyTest() { | ||
| assertThrows(NullPointerException.class, () -> { | ||
| builder | ||
| .connectionString(MOCK_CONNECTION_STRING) | ||
| .httpClient(new NoOpHttpClient()) | ||
| .addPolicy(null); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullConfigurationTest() { | ||
| assertThrows(NullPointerException.class, () -> { | ||
| builder | ||
| .connectionString(MOCK_CONNECTION_STRING) | ||
| .httpClient(new NoOpHttpClient()) | ||
| .configuration(null); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullHttpLogOptionsTest() { | ||
| assertThrows(NullPointerException.class, () -> { | ||
| builder | ||
| .connectionString(MOCK_CONNECTION_STRING) | ||
| .httpClient(new NoOpHttpClient()) | ||
| .httpLogOptions(null); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullRetryPolicyTest() { | ||
| assertThrows(NullPointerException.class, () -> { | ||
| builder | ||
| .connectionString(MOCK_CONNECTION_STRING) | ||
| .httpClient(new NoOpHttpClient()) | ||
| .retryPolicy(null); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void buildPiplineForClient() { | ||
| CallAsyncClient callAsyncClient = builder | ||
| .connectionString(MOCK_CONNECTION_STRING) | ||
| .httpClient(new NoOpHttpClient()) | ||
| .pipeline(new HttpPipelineBuilder().build()) | ||
| .buildAsyncClient(); | ||
| assertNotNull(callAsyncClient); | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.