Automation adds INFO.yaml
[oom/platform/cert-service.git] / certService / src / test / java / org / onap / aaf / certservice / api / ReloadConfigControllerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * PROJECT
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aaf.certservice.api;
22
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;
26
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.aaf.certservice.certification.configuration.CmpServersConfig;
34 import org.onap.aaf.certservice.certification.configuration.CmpServersConfigLoadingException;
35 import org.springframework.http.HttpStatus;
36 import org.springframework.http.ResponseEntity;
37
38 @ExtendWith(MockitoExtension.class)
39 public class ReloadConfigControllerTest {
40
41     private static final String ERROR_MESSAGE = "Exception occurred during CMP Servers configuration loading";
42
43     private ReloadConfigController reloadConfigController;
44
45     @Mock
46     public CmpServersConfig cmpServersConfig;
47
48     @BeforeEach
49     void setUp() {
50         this.reloadConfigController = new ReloadConfigController(cmpServersConfig);
51     }
52
53     @Test
54     void shouldReturnStatusOkWhenSuccessfullyReloaded() throws CmpServersConfigLoadingException {
55         // When
56         ResponseEntity<String> response = reloadConfigController.reloadConfiguration();
57
58         // Then
59         assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
60     }
61
62     @Test
63     void shouldRethrowSameErrorWhenFailedToReload() throws CmpServersConfigLoadingException {
64         // Given
65         doThrow(new CmpServersConfigLoadingException(ERROR_MESSAGE)).when(cmpServersConfig).reloadConfiguration();
66
67         // When
68         Exception exception = assertThrows(
69                 CmpServersConfigLoadingException.class,
70                 () -> reloadConfigController.reloadConfiguration());
71
72         // Then
73         Assertions.assertThat(exception.getMessage()).isEqualTo(ERROR_MESSAGE);
74     }
75
76
77 }