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;
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"))) //
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();
}
@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();
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();
}
@Test
- public void whenTheConfigurationFits_thenConfiguredRicsArePutInRepository() throws Exception {
+ void whenTheConfigurationFits_thenConfiguredRicsArePutInRepository() throws Exception {
refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_EXISTS);
refreshTaskUnderTest.systemEnvironment = new Properties();
// When
}
@Test
- public void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() throws Exception {
+ void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() throws Exception {
refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_EXISTS);
refreshTaskUnderTest.systemEnvironment = new Properties();
}
@Test
- public void whenPeriodicConfigRefreshNoConsul_thenErrorIsLogged() {
+ void whenPeriodicConfigRefreshNoConsul_thenErrorIsLogged() {
refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST);
refreshTaskUnderTest.systemEnvironment = new Properties();
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();
StepVerifier //
.create(task) //
.expectSubscription() //
- .expectNoEvent(Duration.ofMillis(100)) //
+ .expectNoEvent(Duration.ofMillis(1000)) //
.thenCancel() //
.verify();
}
@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);
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();
.ric(ric) //
.json("{}") //
.ownerServiceName("ownerServiceName") //
+ .isTransient(false) //
.build();
return policy;
}