2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. All rights reserved.
6 * ================================================================================
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.onap.oom.certservice.api;
23 import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25 import static org.mockito.Mockito.doThrow;
27 import org.assertj.core.api.Assertions;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.jupiter.MockitoExtension;
33 import org.onap.oom.certservice.certification.configuration.CmpServersConfig;
34 import org.onap.oom.certservice.certification.configuration.CmpServersConfigLoadingException;
35 import org.springframework.http.HttpStatus;
36 import org.springframework.http.ResponseEntity;
38 @ExtendWith(MockitoExtension.class)
39 public class ReloadConfigControllerTest {
41 private static final String ERROR_MESSAGE = "Exception occurred during CMP Servers configuration loading";
43 private ReloadConfigController reloadConfigController;
46 public CmpServersConfig cmpServersConfig;
50 this.reloadConfigController = new ReloadConfigController(cmpServersConfig);
54 void shouldReturnStatusOkWhenSuccessfullyReloaded() throws CmpServersConfigLoadingException {
56 ResponseEntity<String> response = reloadConfigController.reloadConfiguration();
59 assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
63 void shouldRethrowSameErrorWhenFailedToReload() throws CmpServersConfigLoadingException {
65 doThrow(new CmpServersConfigLoadingException(ERROR_MESSAGE)).when(cmpServersConfig).reloadConfiguration();
68 Exception exception = assertThrows(
69 CmpServersConfigLoadingException.class,
70 () -> reloadConfigController.reloadConfiguration());
73 Assertions.assertThat(exception.getMessage()).isEqualTo(ERROR_MESSAGE);