abf91f20d7a61d3618790bab509fb309196c6422
[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.Test;
31 import org.junit.jupiter.api.extension.ExtendWith;
32 import org.mockito.junit.jupiter.MockitoExtension;
33 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate;
34 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser.ConfigParserResult;
35
36 @ExtendWith(MockitoExtension.class)
37 class ApplicationConfigTest {
38
39     private static final RicConfig RIC_CONFIG_1 = RicConfig.builder() //
40             .ricId("ric1") //
41             .baseUrl("ric1_url") //
42             .build();
43
44     private static final RicConfig RIC_CONFIG_2 = RicConfig.builder() //
45             .ricId("ric2") //
46             .baseUrl("ric1_url") //
47             .build();
48
49     private static final RicConfig RIC_CONFIG_3 = RicConfig.builder() //
50             .ricId("ric3") //
51             .baseUrl("ric1_url") //
52             .build();
53
54     ConfigParserResult configParserResult(RicConfig... rics) {
55         return ConfigParserResult.builder() //
56                 .ricConfigs(Arrays.asList(rics)) //
57                 .dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") //
58                 .dmaapProducerTopicUrl("dmaapProducerTopicUrl") //
59                 .controllerConfigs(new HashMap<>()) //
60                 .build();
61     }
62
63     @Test
64     void addRics() throws Exception {
65         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
66
67         List<RicConfigUpdate> update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)) //
68                 .collectList().block();
69         assertEquals(1, update.size());
70         assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
71         assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
72
73         assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.getRicId()),
74                 "Not correct Ric retrieved from configurations.");
75
76         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).collectList().block();
77         assertEquals(0, update.size());
78
79         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2)).collectList()
80                 .block();
81         assertEquals(1, update.size());
82         assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
83
84     }
85
86     @Test
87     void changedRic() throws Exception {
88         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
89
90         List<RicConfigUpdate> update = appConfigUnderTest
91                 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
92         assertEquals(3, update.size());
93
94         RicConfig changedRicConfig = RicConfig.builder() //
95                 .ricId(RIC_CONFIG_1.getRicId()) //
96                 .baseUrl("changed_ric1_url") //
97                 .build();
98
99         update = appConfigUnderTest.setConfiguration(configParserResult(changedRicConfig, RIC_CONFIG_2, RIC_CONFIG_3))
100                 .collectList().block();
101         assertEquals(1, update.size());
102
103         assertEquals(RicConfigUpdate.Type.CHANGED, update.get(0).getType());
104         assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.getRicId()),
105                 "Changed Ric not retrieved from configurations.");
106     }
107
108     @Test
109     void removedRic() {
110         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
111
112         List<RicConfigUpdate> update = appConfigUnderTest
113                 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
114         assertEquals(3, update.size());
115
116         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_2, RIC_CONFIG_3)) //
117                 .collectList() //
118                 .block();
119         assertEquals(1, update.size());
120         assertEquals(RicConfigUpdate.Type.REMOVED, update.get(0).getType());
121         assertEquals(RIC_CONFIG_1, update.get(0).getRicConfig());
122         assertEquals(2, appConfigUnderTest.getRicConfigs().size(), "Ric not deleted from configurations.");
123     }
124
125 }