2 * ========================LICENSE_START=================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.configuration;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Vector;
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;
37 @ExtendWith(MockitoExtension.class)
38 class ApplicationConfigTest {
40 private static final ImmutableRicConfig RIC_CONFIG_1 = ImmutableRicConfig.builder() //
42 .baseUrl("ric1_url") //
43 .managedElementIds(new Vector<>()) //
44 .controllerName("") //
47 private static final ImmutableRicConfig RIC_CONFIG_2 = ImmutableRicConfig.builder() //
49 .baseUrl("ric1_url") //
50 .managedElementIds(new Vector<>()) //
51 .controllerName("") //
54 private static final ImmutableRicConfig RIC_CONFIG_3 = ImmutableRicConfig.builder() //
56 .baseUrl("ric1_url") //
57 .managedElementIds(new Vector<>()) //
58 .controllerName("") //
61 ConfigParserResult configParserResult(RicConfig... rics) {
62 return ImmutableConfigParserResult.builder() //
63 .ricConfigs(Arrays.asList(rics)) //
64 .dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") //
65 .dmaapProducerTopicUrl("dmaapProducerTopicUrl") //
66 .controllerConfigs(new HashMap<>()) //
71 void addRics() throws Exception {
72 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
74 List<RicConfigUpdate> update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)) //
75 .collectList().block();
76 assertEquals(1, update.size());
77 assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
78 assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
80 assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.ricId()),
81 "Not correct Ric retrieved from configurations.");
83 update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).collectList().block();
84 assertEquals(0, update.size());
86 update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2)).collectList()
88 assertEquals(1, update.size());
89 assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
94 void changedRic() throws Exception {
95 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
97 List<RicConfigUpdate> update = appConfigUnderTest
98 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
99 assertEquals(3, update.size());
101 ImmutableRicConfig changedRicConfig = ImmutableRicConfig.builder() //
102 .ricId(RIC_CONFIG_1.ricId()) //
103 .baseUrl("changed_ric1_url") //
104 .managedElementIds(new Vector<>()) //
105 .controllerName("") //
108 update = appConfigUnderTest.setConfiguration(configParserResult(changedRicConfig, RIC_CONFIG_2, RIC_CONFIG_3))
109 .collectList().block();
110 assertEquals(1, update.size());
112 assertEquals(RicConfigUpdate.Type.CHANGED, update.get(0).getType());
113 assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.ricId()),
114 "Changed Ric not retrieved from configurations.");
119 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
121 List<RicConfigUpdate> update = appConfigUnderTest
122 .setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
123 assertEquals(3, update.size());
125 update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_2, RIC_CONFIG_3)) //
128 assertEquals(1, update.size());
129 assertEquals(RicConfigUpdate.Type.REMOVED, update.get(0).getType());
130 assertEquals(RIC_CONFIG_1, update.get(0).getRicConfig());
131 assertEquals(2, appConfigUnderTest.getRicConfigs().size(), "Ric not deleted from configurations.");