2525
2626import org .apache .cloudstack .framework .config .ConfigKey ;
2727import org .apache .cloudstack .framework .config .Configurable ;
28+ import org .apache .cloudstack .framework .config .ScopedConfigStorage ;
2829import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
2930import org .apache .cloudstack .framework .config .dao .ConfigurationSubGroupDao ;
3031import org .junit .Assert ;
3637import org .mockito .junit .MockitoJUnitRunner ;
3738import org .springframework .test .util .ReflectionTestUtils ;
3839
40+ import com .cloud .utils .Pair ;
41+
3942@ RunWith (MockitoJUnitRunner .class )
4043public class ConfigDepotImplTest {
4144
@@ -114,7 +117,7 @@ public void testGetConfigStringValueAfterExpiry() {
114117 }
115118
116119 @ Test
117- public void testPopulateConfiguration () {
120+ public void testPopulateConfigurationNewVO () {
118121 ConfigKey StorageDisableThreshold = new ConfigKey <>(ConfigKey .CATEGORY_ALERT , Double .class , "pool.storage.capacity.disablethreshold" , "0.85" ,
119122 "Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the pool for low storage available." ,
120123 true , List .of (ConfigKey .Scope .StoragePool , ConfigKey .Scope .Zone ));
@@ -138,4 +141,50 @@ public ConfigKey<?>[] getConfigKeys() {
138141 configDepotImpl ._scopeLevelConfigsMap .get (ConfigKey .Scope .StoragePool ).iterator ().next ().key ());
139142 Assert .assertEquals (0 , configDepotImpl ._scopeLevelConfigsMap .get (ConfigKey .Scope .Cluster ).size ());
140143 }
144+
145+ @ Test
146+ public void testPopulateConfiguration () {
147+ ConfigKey StorageDisableThreshold = new ConfigKey <>(ConfigKey .CATEGORY_ALERT , Double .class , "pool.storage.capacity.disablethreshold" , "0.85" ,
148+ "Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the pool for low storage available." ,
149+ true , List .of (ConfigKey .Scope .StoragePool , ConfigKey .Scope .Zone ));
150+ Configurable configurable = new Configurable () {
151+ @ Override
152+ public String getConfigComponentName () {
153+ return "test" ;
154+ }
155+
156+ @ Override
157+ public ConfigKey <?>[] getConfigKeys () {
158+ return new ConfigKey <?>[]{StorageDisableThreshold };
159+ }
160+ };
161+ configDepotImpl .setConfigurables (List .of (configurable ));
162+
163+ ConfigurationVO configurationVO = new ConfigurationVO (StorageDisableThreshold .category (), "DEFAULT" , "component" ,
164+ StorageDisableThreshold .key (), StorageDisableThreshold .defaultValue (), StorageDisableThreshold .description (),
165+ StorageDisableThreshold .displayText (), StorageDisableThreshold .parent (), 1L , 10L );
166+ Mockito .when (_configDao .findById ("pool.storage.capacity.disablethreshold" )).thenReturn (configurationVO );
167+ configDepotImpl .populateConfigurations ();
168+
169+ Mockito .verify (_configDao , Mockito .times (1 )).persist (configurationVO );
170+ }
171+
172+ @ Test
173+ public void getParentScopeWithValidScope () {
174+ ConfigKey .Scope scope = ConfigKey .Scope .Cluster ;
175+ ScopedConfigStorage scopedConfigStorage = Mockito .mock (ScopedConfigStorage .class );
176+ Long id = 1L ;
177+ ConfigKey .Scope parentScope = ConfigKey .Scope .Zone ;
178+ Long parentId = 2L ;
179+
180+ Mockito .when (scopedConfigStorage .getScope ()).thenReturn (scope );
181+ Mockito .when (scopedConfigStorage .getParentScope (id )).thenReturn (new Pair <>(parentScope , parentId ));
182+
183+ configDepotImpl .setScopedStorages (Collections .singletonList (scopedConfigStorage ));
184+ Pair <ConfigKey .Scope , Long > result = configDepotImpl .getParentScope (scope , id );
185+
186+ Assert .assertNotNull (result );
187+ Assert .assertEquals (parentScope , result .first ());
188+ Assert .assertEquals (parentId , result .second ());
189+ }
141190}
0 commit comments