Catalog alignment
[sdc.git] / common-app-api / src / test / java / org / openecomp / sdc / be / config / ConfigurationManagerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP SDC
4  * ================================================================================
5  * Copyright (C) 2019 Samsung. All rights reserved.
6  * Modifications Copyright (C) 2019 Nokia.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.openecomp.sdc.be.config;
25
26 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
27 import static org.hamcrest.MatcherAssert.assertThat;
28 import static org.junit.Assert.assertEquals;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mockito;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.openecomp.sdc.common.api.ConfigurationListener;
36 import org.openecomp.sdc.common.api.ConfigurationSource;
37 import org.openecomp.sdc.common.config.EcompErrorConfiguration;
38 import org.openecomp.sdc.common.impl.ExternalConfiguration;
39 import org.openecomp.sdc.common.impl.FSConfigurationSource;
40
41 @RunWith(MockitoJUnitRunner.class)
42 public class ConfigurationManagerTest {
43
44     private ConfigurationManager configurationManager;
45
46     @Before
47     public void setUp() {
48         String appConfigDir = "src/test/resources/config/common";
49         ConfigurationSource configurationSource =
50                 new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
51         configurationManager = new ConfigurationManager(configurationSource);
52     }
53
54     @Test
55     public void validateBean() {
56         assertThat(ConfigurationManager.class,
57                 hasValidGettersAndSettersExcluding(
58                         "distributionEngineConfiguration",
59                         "ecompErrorConfiguration",
60                         "errorConfiguration",
61                         "neo4jErrorsConfiguration"
62                 ));
63     }
64     private class TestErrorConfiguration extends ErrorConfiguration{}
65     @Test
66     public void testGetSetErrorConfiguration() {
67         configurationManager.setErrorConfiguration(new TestErrorConfiguration());
68         assertEquals(
69                 configurationManager.getErrorConfiguration().getClass(),
70                 TestErrorConfiguration.class);
71     }
72     private class TestEcompErrorConfiguration extends EcompErrorConfiguration{}
73     @Test
74     public void testGetSetEcompErrorConfiguration() {
75         configurationManager.setEcompErrorConfiguration(new TestEcompErrorConfiguration());
76         assertEquals(
77                 configurationManager.getEcompErrorConfiguration().getClass(),
78                 TestEcompErrorConfiguration.class);
79     }
80     @Test
81     public void testGetDistributionEngineConfiguration() {
82         assertEquals(configurationManager.getDistributionEngineConfiguration(),
83                 ConfigurationManager.getConfigurationManager().configurations
84                         .get(DistributionEngineConfiguration.class.getSimpleName()));
85     }
86     private class TestConfiguration extends Configuration{}
87     @Test
88     public void testGetConfigurationAndWatch() {
89         ConfigurationListener testListener = Mockito.mock(ConfigurationListener.class);
90         configurationManager.setConfiguration(new TestConfiguration());
91         assertEquals(
92                 configurationManager.getConfigurationAndWatch(testListener).getClass(),
93                 TestConfiguration.class
94                 );
95     }
96
97 }