Merge "Added STD sim 2.0.0 tests"
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / configuration / ApplicationConfigTest.java
index 17f0997..5667fd2 100644 (file)
 package org.oransc.policyagent.configuration;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Vector;
 
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.oransc.policyagent.configuration.ApplicationConfig.RicConfigUpdate;
+import org.oransc.policyagent.configuration.ApplicationConfigParser.ConfigParserResult;
 import org.oransc.policyagent.exceptions.ServiceException;
 
 @ExtendWith(MockitoExtension.class)
-public class ApplicationConfigTest {
+class ApplicationConfigTest {
 
     private static final ImmutableRicConfig RIC_CONFIG_1 = ImmutableRicConfig.builder() //
         .name("ric1") //
         .baseUrl("ric1_url") //
         .managedElementIds(new Vector<>()) //
+        .controllerName("") //
         .build();
 
+    ConfigParserResult configParserResult(RicConfig... rics) {
+        return ImmutableConfigParserResult.builder() //
+            .ricConfigs(Arrays.asList(rics)) //
+            .dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") //
+            .dmaapProducerTopicUrl("dmaapProducerTopicUrl") //
+            .controllerConfigs(new HashMap<>()) //
+            .build();
+    }
+
     @Test
-    public void gettingNotAddedRicShouldThrowException() {
+    void gettingNotAddedRicShouldThrowException() {
         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
 
-        appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1), null, null);
+        appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1));
 
         Exception exception = assertThrows(ServiceException.class, () -> {
             appConfigUnderTest.getRic("name");
         });
 
-        assertEquals("Could not find ric: name", exception.getMessage());
+        assertEquals("Could not find ric configuration: name", exception.getMessage());
     }
 
     @Test
-    public void addRicShouldNotifyAllObserversOfRicAdded() throws Exception {
+    void addRicShouldNotifyAllObserversOfRicAdded() throws Exception {
         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
 
-        RicConfigUpdate update =
-            appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1), null, null).blockFirst();
+        RicConfigUpdate update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).blockFirst();
         assertEquals(RicConfigUpdate.Type.ADDED, update.getType());
-        assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configuraions.");
+        assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
 
         assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.name()),
             "Not correct Ric retrieved from configurations.");
+
+        update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).blockFirst();
+        assertNull(update, "Nothing should be updated");
+        assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric should remain.");
+
     }
 
     @Test
-    public void changedRicShouldNotifyAllObserversOfRicChanged() throws Exception {
+    void changedRicShouldNotifyAllObserversOfRicChanged() throws Exception {
         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
 
-        appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1), null, null);
+        appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1));
 
         ImmutableRicConfig changedRicConfig = ImmutableRicConfig.builder() //
             .name("ric1") //
             .baseUrl("changed_ric1_url") //
             .managedElementIds(new Vector<>()) //
+            .controllerName("") //
             .build();
 
-        RicConfigUpdate update =
-            appConfigUnderTest.setConfiguration(Arrays.asList(changedRicConfig), null, null).blockFirst();
+        RicConfigUpdate update = appConfigUnderTest.setConfiguration(configParserResult(changedRicConfig)).blockFirst();
 
         assertEquals(RicConfigUpdate.Type.CHANGED, update.getType());
         assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.name()),
@@ -89,19 +106,19 @@ public class ApplicationConfigTest {
     }
 
     @Test
-    public void removedRicShouldNotifyAllObserversOfRicRemoved() {
+    void removedRicShouldNotifyAllObserversOfRicRemoved() {
         ApplicationConfig appConfigUnderTest = new ApplicationConfig();
 
         ImmutableRicConfig ricConfig2 = ImmutableRicConfig.builder() //
             .name("ric2") //
             .baseUrl("ric2_url") //
             .managedElementIds(new Vector<>()) //
+            .controllerName("") //
             .build();
 
-        appConfigUnderTest.setConfiguration(Arrays.asList(RIC_CONFIG_1, ricConfig2), null, null);
+        appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1, ricConfig2));
 
-        RicConfigUpdate update =
-            appConfigUnderTest.setConfiguration(Arrays.asList(ricConfig2), null, null).blockFirst();
+        RicConfigUpdate update = appConfigUnderTest.setConfiguration(configParserResult(ricConfig2)).blockFirst();
 
         assertEquals(RicConfigUpdate.Type.REMOVED, update.getType());
         assertEquals(1, appConfigUnderTest.getRicConfigs().size(), "Ric not deleted from configurations.");