Fix checkstyle warnings
[oom/platform/cert-service.git] / certServiceClient / src / test / java / org / onap / aaf / certservice / client / configuration / EnvsForCsrTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * aaf-certservice-client
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.client.configuration;
22
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.mockito.Mockito;
26
27 import java.util.Optional;
28
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.mockito.Mockito.when;
31
32 class EnvsForCsrTest {
33     private static final String TEST_ENV = "testEnv";
34     private EnvsForCsr envsForCsr;
35
36     @BeforeEach
37     public void setUp() {
38         envsForCsr = Mockito.spy(EnvsForCsr.class);
39     }
40
41     @Test
42     void shouldReturnSystemEnvCommonNameVariableWhenItWasDefined() {
43         // given
44         when(envsForCsr.readEnv(CsrConfigurationEnvs.COMMON_NAME)).thenReturn(Optional.of(TEST_ENV));
45
46         // when
47         final Optional<String> testEnv = envsForCsr.getCommonName();
48
49         // then
50         assertThat(testEnv.isPresent()).isTrue();
51         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
52     }
53
54     @Test
55     public void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() {
56         // when
57         final Optional<String> testEnv = envsForCsr.getCommonName();
58
59         // then
60         assertThat(testEnv.isPresent()).isFalse();
61     }
62
63     @Test
64     void shouldReturnSystemEnvOrganizationVariableWhenItWasDefined() {
65         // given
66         when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION)).thenReturn(Optional.of(TEST_ENV));
67
68         // when
69         final Optional<String> testEnv = envsForCsr.getOrganization();
70
71         // then
72         assertThat(testEnv.isPresent()).isTrue();
73         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
74     }
75
76     @Test
77     public void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() {
78         // when
79         final Optional<String> testEnv = envsForCsr.getOrganization();
80
81         // then
82         assertThat(testEnv.isPresent()).isFalse();
83     }
84
85     @Test
86     void shouldReturnSystemEnvOuVariableWhenItWasDefined() {
87         // given
88         when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION_UNIT)).thenReturn(Optional.of(TEST_ENV));
89
90         // when
91         final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
92
93         // then
94         assertThat(testEnv.isPresent()).isTrue();
95         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
96     }
97
98     @Test
99     public void shouldReportThatSystemEnvOuVariableIsNotPresentWhenItWasNotDefined() {
100         // when
101         final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
102
103         // then
104         assertThat(testEnv.isPresent()).isFalse();
105     }
106
107     @Test
108     void shouldReturnSystemEnvLocationVariableWhenItWasDefined() {
109         // given
110         when(envsForCsr.readEnv(CsrConfigurationEnvs.LOCATION)).thenReturn(Optional.of(TEST_ENV));
111
112         // when
113         final Optional<String> testEnv = envsForCsr.getLocation();
114
115         // then
116         assertThat(testEnv.isPresent()).isTrue();
117         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
118     }
119
120     @Test
121     public void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() {
122         // when
123         final Optional<String> testEnv = envsForCsr.getLocation();
124
125         // then
126         assertThat(testEnv.isPresent()).isFalse();
127     }
128
129     @Test
130     void shouldReturnSystemEnvStateVariableWhenItWasDefined() {
131         // given
132         when(envsForCsr.readEnv(CsrConfigurationEnvs.STATE)).thenReturn(Optional.of(TEST_ENV));
133
134         // when
135         final Optional<String> testEnv = envsForCsr.getState();
136
137         // then
138         assertThat(testEnv.isPresent()).isTrue();
139         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
140     }
141
142     @Test
143     public void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() {
144         // when
145         final Optional<String> testEnv = envsForCsr.getState();
146
147         // then
148         assertThat(testEnv.isPresent()).isFalse();
149     }
150
151     @Test
152     void shouldReturnSystemEnvCountryVariableWhenItWasDefined() {
153         // given
154         when(envsForCsr.readEnv(CsrConfigurationEnvs.COUNTRY)).thenReturn(Optional.of(TEST_ENV));
155
156         // when
157         final Optional<String> testEnv = envsForCsr.getCountry();
158
159         // then
160         assertThat(testEnv.isPresent()).isTrue();
161         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
162     }
163
164     @Test
165     public void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() {
166         // when
167         final Optional<String> testEnv = envsForCsr.getCountry();
168
169         // then
170         assertThat(testEnv.isPresent()).isFalse();
171     }
172
173     @Test
174     void shouldReturnSystemEnvSansVariableWhenItWasDefined() {
175         // given
176         when(envsForCsr.readEnv(CsrConfigurationEnvs.SANS)).thenReturn(Optional.of(TEST_ENV));
177
178         // when
179         final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
180
181         // then
182         assertThat(testEnv.isPresent()).isTrue();
183         assertThat(testEnv.get()).isEqualTo(TEST_ENV);
184     }
185
186     @Test
187     public void shouldReportThatSystemEnvSansVariableIsNotPresentWhenItWasNotDefined() {
188         // when
189         final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
190
191         // then
192         assertThat(testEnv.isPresent()).isFalse();
193     }
194 }