|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package com.cloud.upgrade; |
| 18 | + |
| 19 | +import static org.mockito.Mockito.when; |
| 20 | + |
| 21 | +import java.util.Collections; |
| 22 | + |
| 23 | +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
| 24 | +import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDao; |
| 25 | +import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao; |
| 26 | +import org.apache.cloudstack.framework.config.impl.ConfigurationSubGroupVO; |
| 27 | +import org.apache.cloudstack.framework.config.impl.ConfigurationVO; |
| 28 | +import org.apache.logging.log4j.Logger; |
| 29 | +import org.junit.Assert; |
| 30 | +import org.junit.Test; |
| 31 | +import org.junit.runner.RunWith; |
| 32 | +import org.mockito.InjectMocks; |
| 33 | +import org.mockito.Mock; |
| 34 | +import org.mockito.Mockito; |
| 35 | +import org.mockito.junit.MockitoJUnitRunner; |
| 36 | + |
| 37 | +@RunWith(MockitoJUnitRunner.class) |
| 38 | +public class ConfigurationGroupsAggregatorTest { |
| 39 | + @InjectMocks |
| 40 | + private ConfigurationGroupsAggregator configurationGroupsAggregator = new ConfigurationGroupsAggregator(); |
| 41 | + |
| 42 | + @Mock |
| 43 | + private ConfigurationDao configDao; |
| 44 | + |
| 45 | + @Mock |
| 46 | + private ConfigurationGroupDao configGroupDao; |
| 47 | + |
| 48 | + @Mock |
| 49 | + private ConfigurationSubGroupDao configSubGroupDao; |
| 50 | + |
| 51 | + @Mock |
| 52 | + private Logger logger; |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testUpdateConfigurationGroups() { |
| 56 | + ConfigurationVO config = new ConfigurationVO("Advanced", "DEFAULT", "management-server", |
| 57 | + "test.config.name", null, "description"); |
| 58 | + config.setGroupId(1L); |
| 59 | + config.setSubGroupId(1L); |
| 60 | + |
| 61 | + when(configDao.searchPartialConfigurations()).thenReturn(Collections.singletonList(config)); |
| 62 | + |
| 63 | + ConfigurationSubGroupVO configSubGroup = Mockito.mock(ConfigurationSubGroupVO.class); |
| 64 | + when(configSubGroupDao.findByName("name")).thenReturn(configSubGroup); |
| 65 | + Mockito.when(configSubGroup.getId()).thenReturn(10L); |
| 66 | + Mockito.when(configSubGroup.getGroupId()).thenReturn(5L); |
| 67 | + |
| 68 | + configurationGroupsAggregator.updateConfigurationGroups(); |
| 69 | + |
| 70 | + Assert.assertEquals(Long.valueOf(5), config.getGroupId()); |
| 71 | + Assert.assertEquals(Long.valueOf(10), config.getSubGroupId()); |
| 72 | + Mockito.verify(configDao, Mockito.times(1)).persist(config); |
| 73 | + Mockito.verify(logger, Mockito.times(1)).debug("Updating configuration groups"); |
| 74 | + Mockito.verify(logger, Mockito.times(1)).debug("Successfully updated configuration groups."); |
| 75 | + } |
| 76 | +} |
0 commit comments