39a8aa89853a0a6a23e47b67fd40aed14ae658a2
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2020 Nordix Foundation. All rights reserved.
6  * ======================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.configuration;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29
30 import org.junit.jupiter.api.DisplayName;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.mockito.junit.jupiter.MockitoExtension;
34 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate;
35 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser.ConfigParserResult;
36
37 @ExtendWith(MockitoExtension.class)
38 class ApplicationConfigTest {
39
40     private static final RicConfig RIC_CONFIG_1 = RicConfig.builder() //
41             .ricId("ric1") //
42             .baseUrl("ric1_url") //
43             .build();
44
45     private static final RicConfig RIC_CONFIG_2 = RicConfig.builder() //
46             .ricId("ric2") //
47             .baseUrl("ric1_url") //
48             .build();
49
50     private static final RicConfig RIC_CONFIG_3 = RicConfig.builder() //
51             .ricId("ric3") //
52             .baseUrl("ric1_url") //
53             .build();
54
55     ConfigParserResult configParserResult(RicConfig... rics) {
56         return ConfigParserResult.builder() //
57                 .ricConfigs(Arrays.asList(rics)) //
58                 .dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") //
59                 .dmaapProducerTopicUrl("dmaapProducerTopicUrl") //
60                 .controllerConfigs(new HashMap<>()) //
61                 .build();
62     }
63
64     @Test
65     @DisplayName("test add Rics")
66     void addRics() throws Exception {
67         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
68
69         List<RicConfigUpdate> update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)) //
70                 .collectList().block();
71         assertEquals(1, update.size());
72         assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
73         assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
74
75         assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.getRicId()),
76                 "Not correct Ric retrieved from configurations.");
77
78         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).collectList().block();
79         assertEquals(0, update.size());
80
81         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2)).collectList()
82                 .block();
83         assertEquals(1, update.size());
84         assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
85
86     }
87
88     @Test
89     @DisplayName("test changed Ric")
90     void changedRic() throws Exception {
91         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
92
93         List<RicConfigUpdate> update = appConfigUnderTest
94                 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
95         assertEquals(3, update.size());
96
97         RicConfig changedRicConfig = RicConfig.builder() //
98                 .ricId(RIC_CONFIG_1.getRicId()) //
99                 .baseUrl("changed_ric1_url") //
100                 .build();
101
102         update = appConfigUnderTest.setConfiguration(configParserResult(changedRicConfig, RIC_CONFIG_2, RIC_CONFIG_3))
103                 .collectList().block();
104         assertEquals(1, update.size());
105
106         assertEquals(RicConfigUpdate.Type.CHANGED, update.get(0).getType());
107         assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.getRicId()),
108                 "Changed Ric not retrieved from configurations.");
109     }
110
111     @Test
112     @DisplayName("test removed Ric")
113     void removedRic() {
114         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
115
116         List<RicConfigUpdate> update = appConfigUnderTest
117                 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
118         assertEquals(3, update.size());
119
120         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_2, RIC_CONFIG_3)) //
121                 .collectList() //
122                 .block();
123         assertEquals(1, update.size());
124         assertEquals(RicConfigUpdate.Type.REMOVED, update.get(0).getType());
125         assertEquals(RIC_CONFIG_1, update.get(0).getRicConfig());
126         assertEquals(2, appConfigUnderTest.getRicConfigs().size(), "Ric not deleted from configurations.");
127     }
128
129 }