Merge "Version Up & Removed unncessary properties"
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / tasks / RefreshConfigTaskTest.java
index f81962d..4823a44 100644 (file)
@@ -50,6 +50,7 @@ import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Properties;
 import java.util.Vector;
 
@@ -65,6 +66,8 @@ import org.oransc.policyagent.clients.A1ClientFactory;
 import org.oransc.policyagent.configuration.ApplicationConfig;
 import org.oransc.policyagent.configuration.ApplicationConfig.RicConfigUpdate.Type;
 import org.oransc.policyagent.configuration.ApplicationConfigParser;
+import org.oransc.policyagent.configuration.ApplicationConfigParser.ConfigParserResult;
+import org.oransc.policyagent.configuration.ImmutableConfigParserResult;
 import org.oransc.policyagent.configuration.ImmutableRicConfig;
 import org.oransc.policyagent.configuration.RicConfig;
 import org.oransc.policyagent.repository.ImmutablePolicy;
@@ -82,7 +85,7 @@ import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
 
 @ExtendWith(MockitoExtension.class)
-public class RefreshConfigTaskTest {
+class RefreshConfigTaskTest {
 
     private static final boolean CONFIG_FILE_EXISTS = true;
     private static final boolean CONFIG_FILE_DOES_NOT_EXIST = false;
@@ -96,10 +99,11 @@ public class RefreshConfigTaskTest {
     CbsClient cbsClient;
 
     private static final String RIC_1_NAME = "ric1";
-    public static final ImmutableRicConfig CORRECT_RIC_CONIFG = ImmutableRicConfig.builder() //
+    private static final ImmutableRicConfig CORRECT_RIC_CONIFG = ImmutableRicConfig.builder() //
         .name(RIC_1_NAME) //
         .baseUrl("http://localhost:8080/") //
         .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
+        .controllerName("") //
         .build();
 
     private static EnvProperties properties() {
@@ -120,13 +124,13 @@ public class RefreshConfigTaskTest {
         RefreshConfigTask obj = spy(new RefreshConfigTask(appConfig, rics, policies, new Services(), new PolicyTypes(),
             new A1ClientFactory(appConfig)));
         if (stubConfigFileExists) {
-            doReturn(configFileExists).when(obj).configFileExists();
+            doReturn(configFileExists).when(obj).fileExists(any());
         }
         return obj;
     }
 
     @Test
-    public void startWithStubbedRefresh_thenTerminationLogged() {
+    void startWithStubbedRefresh_thenTerminationLogged() {
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false);
         doReturn(Flux.empty()).when(refreshTaskUnderTest).createRefreshTask();
 
@@ -138,7 +142,7 @@ public class RefreshConfigTaskTest {
     }
 
     @Test
-    public void startWithStubbedRefreshReturnError_thenErrorAndTerminationLogged() {
+    void startWithStubbedRefreshReturnError_thenErrorAndTerminationLogged() {
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false);
         doReturn(Flux.error(new Exception("Error"))).when(refreshTaskUnderTest).createRefreshTask();
 
@@ -147,12 +151,12 @@ public class RefreshConfigTaskTest {
         refreshTaskUnderTest.start();
 
         ILoggingEvent event = logAppender.list.get(0);
-        assertThat(event.getThrowableProxy().getMessage()).isEqualTo("Error");
+        assertThat(event.getLevel()).isEqualTo(ERROR);
         assertThat(event.toString().contains("Configuration refresh terminated due to exception")).isTrue();
     }
 
     @Test
-    public void stop_thenTaskIsDisposed() throws Exception {
+    void stop_thenTaskIsDisposed() throws Exception {
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false);
         refreshTaskUnderTest.systemEnvironment = new Properties();
 
@@ -163,7 +167,7 @@ public class RefreshConfigTaskTest {
     }
 
     @Test
-    public void whenTheConfigurationFits_thenConfiguredRicsArePutInRepository() throws Exception {
+    void whenTheConfigurationFits_thenConfiguredRicsArePutInRepository() throws Exception {
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_EXISTS);
         refreshTaskUnderTest.systemEnvironment = new Properties();
         // When
@@ -189,7 +193,7 @@ public class RefreshConfigTaskTest {
     }
 
     @Test
-    public void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() throws Exception {
+    void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() throws Exception {
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_EXISTS);
         refreshTaskUnderTest.systemEnvironment = new Properties();
 
@@ -209,7 +213,7 @@ public class RefreshConfigTaskTest {
     }
 
     @Test
-    public void whenPeriodicConfigRefreshNoConsul_thenErrorIsLogged() {
+    void whenPeriodicConfigRefreshNoConsul_thenErrorIsLogged() {
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST);
         refreshTaskUnderTest.systemEnvironment = new Properties();
 
@@ -217,7 +221,7 @@ public class RefreshConfigTaskTest {
         doReturn(Mono.just(props)).when(refreshTaskUnderTest).getEnvironment(any());
 
         doReturn(Mono.just(cbsClient)).when(refreshTaskUnderTest).createCbsClient(props);
-        when(cbsClient.updates(any(), any(), any())).thenReturn(Flux.error(new IOException()));
+        when(cbsClient.get(any())).thenReturn(Mono.error(new IOException()));
 
         final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, WARN);
         Flux<Type> task = refreshTaskUnderTest.createRefreshTask();
@@ -225,7 +229,7 @@ public class RefreshConfigTaskTest {
         StepVerifier //
             .create(task) //
             .expectSubscription() //
-            .expectNoEvent(Duration.ofMillis(100)) //
+            .expectNoEvent(Duration.ofMillis(1000)) //
             .thenCancel() //
             .verify();
 
@@ -235,7 +239,7 @@ public class RefreshConfigTaskTest {
     }
 
     @Test
-    public void whenPeriodicConfigRefreshSuccess_thenNewConfigIsCreatedAndRepositoryUpdated() throws Exception {
+    void whenPeriodicConfigRefreshSuccess_thenNewConfigIsCreatedAndRepositoryUpdated() throws Exception {
         Rics rics = new Rics();
         Policies policies = new Policies();
         refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, rics, policies, false);
@@ -246,7 +250,7 @@ public class RefreshConfigTaskTest {
         RicConfig removedRicConfig = getRicConfig("removed");
         Ric removedRic = new Ric(removedRicConfig);
         rics.put(removedRic);
-        appConfig.setConfiguration(Arrays.asList(changedRicConfig, removedRicConfig), null, null);
+        appConfig.setConfiguration(configParserResult(changedRicConfig, removedRicConfig));
 
         Policy policy = getPolicy(removedRic);
         policies.put(policy);
@@ -258,7 +262,7 @@ public class RefreshConfigTaskTest {
         JsonObject configAsJson = getJsonRootObject();
         String newBaseUrl = "newBaseUrl";
         modifyTheRicConfiguration(configAsJson, newBaseUrl);
-        when(cbsClient.updates(any(), any(), any())).thenReturn(Flux.just(configAsJson));
+        when(cbsClient.get(any())).thenReturn(Mono.just(configAsJson));
         doNothing().when(refreshTaskUnderTest).runRicSynchronization(any(Ric.class));
 
         Flux<Type> task = refreshTaskUnderTest.createRefreshTask();
@@ -289,6 +293,7 @@ public class RefreshConfigTaskTest {
             .name(name) //
             .baseUrl("url") //
             .managedElementIds(Collections.emptyList()) //
+            .controllerName("controllerName") //
             .build();
         return ricConfig;
     }
@@ -305,13 +310,24 @@ public class RefreshConfigTaskTest {
             .ric(ric) //
             .json("{}") //
             .ownerServiceName("ownerServiceName") //
+            .isTransient(false) //
             .build();
         return policy;
     }
 
+    ConfigParserResult configParserResult(RicConfig... rics) {
+        return ImmutableConfigParserResult.builder() //
+            .ricConfigs(Arrays.asList(rics)) //
+            .dmaapConsumerConfig(new Properties()) //
+            .dmaapPublisherConfig(new Properties()) //
+            .controllerConfigs(new HashMap<>()) //
+            .build();
+    }
+
     private void modifyTheRicConfiguration(JsonObject configAsJson, String newBaseUrl) {
-        ((JsonObject) configAsJson.getAsJsonObject("config").getAsJsonArray("ric").get(0)).addProperty("baseUrl",
-            newBaseUrl);
+        ((JsonObject) configAsJson.getAsJsonObject("config") //
+            .getAsJsonArray("ric").get(0)) //
+                .addProperty("baseUrl", newBaseUrl);
     }
 
     private JsonObject getJsonRootObject() throws JsonIOException, JsonSyntaxException, IOException {