2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 Nordix Foundation
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.oransc.policyagent.configuration;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
27 import java.util.Arrays;
28 import java.util.Vector;
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.oransc.policyagent.configuration.ApplicationConfig.RicConfigUpdate;
34 import org.oransc.policyagent.exceptions.ServiceException;
36 @ExtendWith(MockitoExtension.class)
37 public class ApplicationConfigTest {
39 private static final ImmutableRicConfig RIC_CONFIG_1 = ImmutableRicConfig.builder() //
41 .baseUrl("ric1_url") //
42 .managedElementIds(new Vector<>()) //
46 public void gettingNotAddedRicShouldThrowException() {
47 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
49 appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1), null, null);
51 Exception exception = assertThrows(ServiceException.class, () -> {
52 appConfigUnderTest.getRic("name");
55 assertEquals("Could not find ric: name", exception.getMessage());
59 public void addRicShouldNotifyAllObserversOfRicAdded() throws Exception {
60 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
62 RicConfigUpdate update =
63 appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1), null, null).blockFirst();
64 assertEquals(RicConfigUpdate.Type.ADDED, update.getType());
65 assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
67 assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.name()),
68 "Not correct Ric retrieved from configurations.");
72 public void changedRicShouldNotifyAllObserversOfRicChanged() throws Exception {
73 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
75 appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1), null, null);
77 ImmutableRicConfig changedRicConfig = ImmutableRicConfig.builder() //
79 .baseUrl("changed_ric1_url") //
80 .managedElementIds(new Vector<>()) //
83 RicConfigUpdate update =
84 appConfigUnderTest.setConfiguration(Arrays.asList(changedRicConfig), null, null).blockFirst();
86 assertEquals(RicConfigUpdate.Type.CHANGED, update.getType());
87 assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.name()),
88 "Changed Ric not retrieved from configurations.");
92 public void removedRicShouldNotifyAllObserversOfRicRemoved() {
93 ApplicationConfig appConfigUnderTest = new ApplicationConfig();
95 ImmutableRicConfig ricConfig2 = ImmutableRicConfig.builder() //
97 .baseUrl("ric2_url") //
98 .managedElementIds(new Vector<>()) //
101 appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1, ricConfig2), null, null);
103 RicConfigUpdate update =
104 appConfigUnderTest.setConfiguration(Arrays.asList(ricConfig2), null, null).blockFirst();
106 assertEquals(RicConfigUpdate.Type.REMOVED, update.getType());
107 assertEquals(1, appConfigUnderTest.getRicConfigs().size(), "Ric not deleted from configurations.");