-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed setting
asyncHttpClientBuilder
in AwsClientCustomizer
for a…
…sync clients (#875)
- Loading branch information
1 parent
4566bff
commit 3c793be
Showing
2 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
113 changes: 113 additions & 0 deletions
113
...onfigure/src/test/java/io/awspring/cloud/autoconfigure/core/AwsClientCustomizerTests.java
This file contains 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,113 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.core; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.withSettings; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.awscore.client.builder.AwsAsyncClientBuilder; | ||
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder; | ||
import software.amazon.awssdk.awscore.client.builder.AwsSyncClientBuilder; | ||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
|
||
class AwsClientCustomizerTests { | ||
AwsClientBuilder<?, ?> syncClientBuilder = mock(AwsClientBuilder.class, | ||
withSettings().extraInterfaces(AwsSyncClientBuilder.class)); | ||
AwsClientBuilder<?, ?> asyncClientBuilder = mock(AwsClientBuilder.class, | ||
withSettings().extraInterfaces(AwsAsyncClientBuilder.class)); | ||
|
||
@Test | ||
void applyOverrideConfigurationCustomizer() { | ||
var customizer = new AwsClientCustomizer<AwsClientBuilder<?, ?>>() { | ||
@Override | ||
public ClientOverrideConfiguration overrideConfiguration() { | ||
return ClientOverrideConfiguration.builder().build(); | ||
} | ||
}; | ||
|
||
AwsClientCustomizer.apply(customizer, syncClientBuilder); | ||
assertAll(() -> verify(syncClientBuilder).overrideConfiguration(any(ClientOverrideConfiguration.class)), | ||
() -> verify((AwsSyncClientBuilder<?, ?>) syncClientBuilder, never()) | ||
.httpClient(any(SdkHttpClient.class)), | ||
() -> verify((AwsSyncClientBuilder<?, ?>) syncClientBuilder, never()) | ||
.httpClientBuilder(any(SdkHttpClient.Builder.class))); | ||
} | ||
|
||
@Test | ||
void applySyncClientCustomizer() { | ||
var customizer = new AwsClientCustomizer<AwsClientBuilder<?, ?>>() { | ||
@Override | ||
public SdkHttpClient httpClient() { | ||
return mock(SdkHttpClient.class); | ||
} | ||
|
||
@Override | ||
public SdkHttpClient.Builder<?> httpClientBuilder() { | ||
return mock(SdkHttpClient.Builder.class); | ||
} | ||
}; | ||
|
||
AwsClientCustomizer.apply(customizer, syncClientBuilder); | ||
assertAll( | ||
() -> verify(syncClientBuilder, never()).overrideConfiguration(any(ClientOverrideConfiguration.class)), | ||
() -> verify((AwsSyncClientBuilder<?, ?>) syncClientBuilder).httpClient(any(SdkHttpClient.class)), | ||
() -> verify((AwsSyncClientBuilder<?, ?>) syncClientBuilder) | ||
.httpClientBuilder(any(SdkHttpClient.Builder.class))); | ||
} | ||
|
||
@Test | ||
void applyAsyncClientBuilderCustomizer() { | ||
var customizer = new AwsClientCustomizer<AwsClientBuilder<?, ?>>() { | ||
@Override | ||
public SdkAsyncHttpClient asyncHttpClient() { | ||
return mock(SdkAsyncHttpClient.class); | ||
} | ||
|
||
@Override | ||
public SdkAsyncHttpClient.Builder<?> asyncHttpClientBuilder() { | ||
return mock(SdkAsyncHttpClient.Builder.class); | ||
} | ||
}; | ||
|
||
AwsClientCustomizer.apply(customizer, asyncClientBuilder); | ||
assertAll( | ||
() -> verify(asyncClientBuilder, never()).overrideConfiguration(any(ClientOverrideConfiguration.class)), | ||
() -> verify((AwsAsyncClientBuilder<?, ?>) asyncClientBuilder) | ||
.httpClient(any(SdkAsyncHttpClient.class)), | ||
() -> verify((AwsAsyncClientBuilder<?, ?>) asyncClientBuilder) | ||
.httpClientBuilder(any(SdkAsyncHttpClient.Builder.class))); | ||
} | ||
|
||
@Test | ||
void applyEmptyCustomizer() { | ||
var customizer = new AwsClientCustomizer<AwsClientBuilder<?, ?>>() { | ||
}; | ||
AwsClientCustomizer.apply(customizer, asyncClientBuilder); | ||
assertAll( | ||
() -> verify(asyncClientBuilder, never()).overrideConfiguration(any(ClientOverrideConfiguration.class)), | ||
() -> verify((AwsAsyncClientBuilder<?, ?>) asyncClientBuilder, never()) | ||
.httpClient(any(SdkAsyncHttpClient.class)), | ||
() -> verify((AwsAsyncClientBuilder<?, ?>) asyncClientBuilder, never()) | ||
.httpClientBuilder(any(SdkAsyncHttpClient.Builder.class))); | ||
} | ||
} |