-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Startup Bug Fixes #48278
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
Merged
Startup Bug Fixes #48278
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
107 changes: 107 additions & 0 deletions
107
...zure/spring/cloud/appconfiguration/config/AppConfigurationWatchAutoConfigurationTest.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,107 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.azure.spring.cloud.appconfiguration.config; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.bootstrap.BootstrapContext; | ||
|
|
||
| import com.azure.spring.cloud.appconfiguration.config.implementation.AppConfigurationReplicaClientFactory; | ||
| import com.azure.spring.cloud.appconfiguration.config.implementation.autofailover.ReplicaLookUp; | ||
| import com.azure.spring.cloud.appconfiguration.config.implementation.properties.AppConfigurationProperties; | ||
| import com.azure.spring.cloud.appconfiguration.config.implementation.properties.ConfigStore; | ||
|
|
||
| public class AppConfigurationWatchAutoConfigurationTest { | ||
|
|
||
| private AppConfigurationWatchAutoConfiguration autoConfiguration; | ||
| private AppConfigurationProperties properties; | ||
| private BootstrapContext bootstrapContext; | ||
| private AppConfigurationReplicaClientFactory clientFactory; | ||
| private ReplicaLookUp replicaLookUp; | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| autoConfiguration = new AppConfigurationWatchAutoConfiguration(); | ||
| properties = new AppConfigurationProperties(); | ||
| properties.setRefreshInterval(Duration.ofSeconds(30)); | ||
|
|
||
| ConfigStore store = new ConfigStore(); | ||
| store.setEndpoint("https://test.azconfig.io"); | ||
| List<ConfigStore> stores = new ArrayList<>(); | ||
| stores.add(store); | ||
| properties.setStores(stores); | ||
|
|
||
| bootstrapContext = mock(BootstrapContext.class); | ||
| clientFactory = mock(AppConfigurationReplicaClientFactory.class); | ||
| replicaLookUp = mock(ReplicaLookUp.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void appConfigurationRefreshBeanIsCreatedWhenDependenciesExist() { | ||
| // Arrange | ||
| when(bootstrapContext.getOrElse(AppConfigurationReplicaClientFactory.class, null)) | ||
| .thenReturn(clientFactory); | ||
| when(bootstrapContext.getOrElse(ReplicaLookUp.class, null)) | ||
| .thenReturn(replicaLookUp); | ||
|
|
||
| // Act | ||
| AppConfigurationRefresh result = autoConfiguration.appConfigurationRefresh(properties, bootstrapContext); | ||
|
|
||
| // Assert | ||
| assertNotNull(result, "AppConfigurationRefresh bean should be created when dependencies exist"); | ||
| } | ||
|
|
||
| @Test | ||
| public void appConfigurationRefreshBeanIsNotCreatedWhenClientFactoryIsMissing() { | ||
| // Arrange | ||
| when(bootstrapContext.getOrElse(AppConfigurationReplicaClientFactory.class, null)) | ||
| .thenReturn(null); | ||
| when(bootstrapContext.getOrElse(ReplicaLookUp.class, null)) | ||
| .thenReturn(replicaLookUp); | ||
|
|
||
| // Act | ||
| AppConfigurationRefresh result = autoConfiguration.appConfigurationRefresh(properties, bootstrapContext); | ||
|
|
||
| // Assert | ||
| assertNull(result, "AppConfigurationRefresh bean should not be created when clientFactory is missing"); | ||
| } | ||
|
|
||
| @Test | ||
| public void appConfigurationRefreshBeanIsNotCreatedWhenReplicaLookUpIsMissing() { | ||
| // Arrange | ||
| when(bootstrapContext.getOrElse(AppConfigurationReplicaClientFactory.class, null)) | ||
| .thenReturn(clientFactory); | ||
| when(bootstrapContext.getOrElse(ReplicaLookUp.class, null)) | ||
| .thenReturn(null); | ||
|
|
||
| // Act | ||
| AppConfigurationRefresh result = autoConfiguration.appConfigurationRefresh(properties, bootstrapContext); | ||
|
|
||
| // Assert | ||
| assertNull(result, "AppConfigurationRefresh bean should not be created when replicaLookUp is missing"); | ||
| } | ||
|
|
||
| @Test | ||
| public void appConfigurationRefreshBeanIsNotCreatedWhenBothDependenciesAreMissing() { | ||
| // Arrange | ||
| when(bootstrapContext.getOrElse(AppConfigurationReplicaClientFactory.class, null)) | ||
| .thenReturn(null); | ||
| when(bootstrapContext.getOrElse(ReplicaLookUp.class, null)) | ||
| .thenReturn(null); | ||
|
|
||
| // Act | ||
| AppConfigurationRefresh result = autoConfiguration.appConfigurationRefresh(properties, bootstrapContext); | ||
|
|
||
| // Assert | ||
| assertNull(result, "AppConfigurationRefresh bean should not be created when both dependencies are missing"); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.