fd77eb8f38a38b62e8e9cec82921080b0d6ca603
[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 import java.util.Vector;
30
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 ImmutableRicConfig RIC_CONFIG_1 = ImmutableRicConfig.builder() //
41             .ricId("ric1") //
42             .baseUrl("ric1_url") //
43             .managedElementIds(new Vector<>()) //
44             .controllerName("") //
45             .customAdapterClass("") //
46             .build();
47
48     private static final ImmutableRicConfig RIC_CONFIG_2 = ImmutableRicConfig.builder() //
49             .ricId("ric2") //
50             .baseUrl("ric1_url") //
51             .managedElementIds(new Vector<>()) //
52             .controllerName("") //
53             .customAdapterClass("") //
54             .build();
55
56     private static final ImmutableRicConfig RIC_CONFIG_3 = ImmutableRicConfig.builder() //
57             .ricId("ric3") //
58             .baseUrl("ric1_url") //
59             .managedElementIds(new Vector<>()) //
60             .controllerName("") //
61             .customAdapterClass("") //
62             .build();
63
64     ConfigParserResult configParserResult(RicConfig... rics) {
65         return ImmutableConfigParserResult.builder() //
66                 .ricConfigs(Arrays.asList(rics)) //
67                 .dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") //
68                 .dmaapProducerTopicUrl("dmaapProducerTopicUrl") //
69                 .controllerConfigs(new HashMap<>()) //
70                 .build();
71     }
72
73     @Test
74     void addRics() throws Exception {
75         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
76
77         List<RicConfigUpdate> update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)) //
78                 .collectList().block();
79         assertEquals(1, update.size());
80         assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
81         assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
82
83         assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.ricId()),
84                 "Not correct Ric retrieved from configurations.");
85
86         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).collectList().block();
87         assertEquals(0, update.size());
88
89         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2)).collectList()
90                 .block();
91         assertEquals(1, update.size());
92         assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
93
94     }
95
96     @Test
97     void changedRic() throws Exception {
98         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
99
100         List<RicConfigUpdate> update = appConfigUnderTest
101                 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
102         assertEquals(3, update.size());
103
104         ImmutableRicConfig changedRicConfig = ImmutableRicConfig.builder() //
105                 .ricId(RIC_CONFIG_1.ricId()) //
106                 .baseUrl("changed_ric1_url") //
107                 .managedElementIds(new Vector<>()) //
108                 .controllerName("") //
109                 .customAdapterClass("") //
110                 .build();
111
112         update = appConfigUnderTest.setConfiguration(configParserResult(changedRicConfig, RIC_CONFIG_2, RIC_CONFIG_3))
113                 .collectList().block();
114         assertEquals(1, update.size());
115
116         assertEquals(RicConfigUpdate.Type.CHANGED, update.get(0).getType());
117         assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.ricId()),
118                 "Changed Ric not retrieved from configurations.");
119     }
120
121     @Test
122     void removedRic() {
123         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
124
125         List<RicConfigUpdate> update = appConfigUnderTest
126                 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
127         assertEquals(3, update.size());
128
129         update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_2, RIC_CONFIG_3)) //
130                 .collectList() //
131                 .block();
132         assertEquals(1, update.size());
133         assertEquals(RicConfigUpdate.Type.REMOVED, update.get(0).getType());
134         assertEquals(RIC_CONFIG_1, update.get(0).getRicConfig());
135         assertEquals(2, appConfigUnderTest.getRicConfigs().size(), "Ric not deleted from configurations.");
136     }
137
138 }