X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Ftasks%2FRefreshConfigTaskTest.java;h=4823a44823fe4f157ac8d1715b0855061ec362c3;hb=144374e691c0f1bdcd90cf7c01de263c905d45b7;hp=e8f0ec942bd866c4245a83204ea8da67a047332b;hpb=b744f6266f838dbf60f37b1c8d5367632f1f0faa;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java index e8f0ec94..4823a448 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java @@ -40,6 +40,7 @@ import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -52,6 +53,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Properties; import java.util.Vector; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -77,12 +79,13 @@ import org.oransc.policyagent.repository.Ric; import org.oransc.policyagent.repository.Rics; import org.oransc.policyagent.repository.Services; import org.oransc.policyagent.utils.LoggingUtils; + import reactor.core.publisher.Flux; 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,7 +99,7 @@ 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(Arrays.asList("kista_1", "kista_2"))) // @@ -121,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(); @@ -139,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(); @@ -153,7 +156,7 @@ public class RefreshConfigTaskTest { } @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(); @@ -164,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 @@ -190,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(); @@ -210,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(); @@ -218,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 logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, WARN); Flux task = refreshTaskUnderTest.createRefreshTask(); @@ -226,7 +229,7 @@ public class RefreshConfigTaskTest { StepVerifier // .create(task) // .expectSubscription() // - .expectNoEvent(Duration.ofMillis(100)) // + .expectNoEvent(Duration.ofMillis(1000)) // .thenCancel() // .verify(); @@ -236,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); @@ -259,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 task = refreshTaskUnderTest.createRefreshTask(); @@ -307,6 +310,7 @@ public class RefreshConfigTaskTest { .ric(ric) // .json("{}") // .ownerServiceName("ownerServiceName") // + .isTransient(false) // .build(); return policy; }