2525import static com .microsoft .azure .spring .cloud .config .TestUtils .createItem ;
2626import static org .assertj .core .api .Assertions .assertThat ;
2727import static org .junit .Assert .assertEquals ;
28+ import static org .junit .Assert .assertNull ;
2829import static org .junit .Assert .fail ;
2930import static org .mockito .Mockito .when ;
3031
31- import com .azure .core .http .rest .PagedFlux ;
32- import com .azure .core .http .rest .PagedResponse ;
33- import com .azure .data .appconfiguration .ConfigurationAsyncClient ;
34- import com .azure .data .appconfiguration .models .ConfigurationSetting ;
35- import com .fasterxml .jackson .databind .ObjectMapper ;
36- import com .fasterxml .jackson .databind .PropertyNamingStrategy ;
37- import com .microsoft .azure .spring .cloud .config .feature .management .entity .Feature ;
38- import com .microsoft .azure .spring .cloud .config .feature .management .entity .FeatureFilterEvaluationContext ;
39- import com .microsoft .azure .spring .cloud .config .feature .management .entity .FeatureSet ;
40- import com .microsoft .azure .spring .cloud .config .properties .AppConfigurationProperties ;
41- import com .microsoft .azure .spring .cloud .config .properties .AppConfigurationProviderProperties ;
42- import com .microsoft .azure .spring .cloud .config .properties .ConfigStore ;
43- import com .microsoft .azure .spring .cloud .config .stores .ClientStore ;
4432import java .io .IOException ;
4533import java .util .ArrayList ;
4634import java .util .HashMap ;
4735import java .util .Iterator ;
4836import java .util .LinkedHashMap ;
4937import java .util .List ;
38+
5039import org .apache .commons .lang3 .ArrayUtils ;
5140import org .junit .Before ;
5241import org .junit .BeforeClass ;
5645import org .mockito .Mock ;
5746import org .mockito .Mockito ;
5847import org .mockito .MockitoAnnotations ;
48+
49+ import com .azure .core .http .rest .PagedFlux ;
50+ import com .azure .core .http .rest .PagedResponse ;
51+ import com .azure .data .appconfiguration .ConfigurationAsyncClient ;
52+ import com .azure .data .appconfiguration .models .ConfigurationSetting ;
53+ import com .fasterxml .jackson .databind .ObjectMapper ;
54+ import com .fasterxml .jackson .databind .PropertyNamingStrategy ;
55+ import com .microsoft .azure .spring .cloud .config .feature .management .entity .Feature ;
56+ import com .microsoft .azure .spring .cloud .config .feature .management .entity .FeatureFilterEvaluationContext ;
57+ import com .microsoft .azure .spring .cloud .config .feature .management .entity .FeatureSet ;
58+ import com .microsoft .azure .spring .cloud .config .properties .AppConfigurationProperties ;
59+ import com .microsoft .azure .spring .cloud .config .properties .AppConfigurationProviderProperties ;
60+ import com .microsoft .azure .spring .cloud .config .properties .ConfigStore ;
61+ import com .microsoft .azure .spring .cloud .config .stores .ClientStore ;
62+
5963import reactor .core .publisher .Flux ;
6064import reactor .core .publisher .Mono ;
6165
@@ -140,6 +144,9 @@ public class AppConfigurationPropertySourceTest {
140144
141145 @ Mock
142146 private PagedResponse <ConfigurationSetting > pagedResponseMock ;
147+
148+ @ Mock
149+ private ConfigStore configStoreMock ;
143150
144151 private AppConfigurationProviderProperties appProperties ;
145152
@@ -163,18 +170,17 @@ public void setup() {
163170 MockitoAnnotations .initMocks (this );
164171 appConfigurationProperties = new AppConfigurationProperties ();
165172 appProperties = new AppConfigurationProviderProperties ();
166- ConfigStore configStore = new ConfigStore ();
167- configStore .setEndpoint (TEST_STORE_NAME );
168173 ArrayList <String > contexts = new ArrayList <String >();
169174 contexts .add ("/application/*" );
170- propertySource = new AppConfigurationPropertySource (TEST_CONTEXT , configStore , "\0 " ,
175+ propertySource = new AppConfigurationPropertySource (TEST_CONTEXT , configStoreMock , "\0 " ,
171176 appConfigurationProperties , clientStoreMock , appProperties , tokenCredentialProvider , null );
172177
173178 testItems = new ArrayList <ConfigurationSetting >();
174179 testItems .add (item1 );
175180 testItems .add (item2 );
176181 testItems .add (item3 );
177182
183+ when (configStoreMock .getEndpoint ()).thenReturn (TEST_STORE_NAME );
178184 when (configClientMock .listConfigurationSettings (Mockito .any ())).thenReturn (settingsMock );
179185 when (settingsMock .byPage ()).thenReturn (pageMock );
180186 when (pageMock .collectList ()).thenReturn (collectionMock );
@@ -236,6 +242,7 @@ public void testPropertyNameSlashConvertedToDots() throws IOException {
236242 public void testFeatureFlagCanBeInitedAndQueried () throws IOException {
237243 when (clientStoreMock .listSettings (Mockito .any (), Mockito .anyString ()))
238244 .thenReturn (new ArrayList <ConfigurationSetting >()).thenReturn (FEATURE_ITEMS );
245+ when (configStoreMock .isUseFeatureManagement ()).thenReturn (true );
239246
240247 FeatureSet featureSet = new FeatureSet ();
241248 try {
@@ -271,6 +278,23 @@ public void testFeatureFlagCanBeInitedAndQueried() throws IOException {
271278
272279 assertEquals (convertedValue , propertySource .getProperty (FEATURE_MANAGEMENT_KEY ));
273280 }
281+
282+ @ Test
283+ public void testFeatureFlagDisabled () throws IOException {
284+ when (clientStoreMock .listSettings (Mockito .any (), Mockito .anyString ()))
285+ .thenReturn (new ArrayList <ConfigurationSetting >()).thenReturn (FEATURE_ITEMS );
286+ when (configStoreMock .isUseFeatureManagement ()).thenReturn (false );
287+
288+ FeatureSet featureSet = new FeatureSet ();
289+ try {
290+ propertySource .initProperties (featureSet );
291+ } catch (IOException e ) {
292+ fail ("Failed Reading in Feature Flags" );
293+ }
294+ propertySource .initFeatures (featureSet );
295+
296+ assertNull (propertySource .getProperty (FEATURE_MANAGEMENT_KEY ));
297+ }
274298
275299 @ Test
276300 public void testFeatureFlagThrowError () throws IOException {
@@ -285,6 +309,7 @@ public void testFeatureFlagThrowError() throws IOException {
285309 @ Test
286310 public void testFeatureFlagBuildError () throws IOException {
287311 when (clientStoreMock .listSettings (Mockito .any (), Mockito .anyString ())).thenReturn (FEATURE_ITEMS );
312+ when (configStoreMock .isUseFeatureManagement ()).thenReturn (true );
288313
289314 FeatureSet featureSet = new FeatureSet ();
290315 try {
@@ -375,7 +400,8 @@ public void initNullInvalidContentTypeFeatureFlagTest() throws IOException {
375400 public void testFeatureFlagTargeting () throws IOException {
376401 when (clientStoreMock .listSettings (Mockito .any (), Mockito .anyString ()))
377402 .thenReturn (new ArrayList <ConfigurationSetting >()).thenReturn (FEATURE_ITEMS_TARGETING );
378-
403+ when (configStoreMock .isUseFeatureManagement ()).thenReturn (true );
404+
379405 FeatureSet featureSet = new FeatureSet ();
380406 try {
381407 propertySource .initProperties (featureSet );
0 commit comments