Automation adds INFO.yaml
[oom/platform/cert-service.git] / certServiceClient / src / test / java / org / onap / oom / certservice / client / configuration / EnvsForCsrTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * oom-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.oom.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)
51                 .isPresent()
52                 .contains(TEST_ENV);
53     }
54
55     @Test
56     void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() {
57         // when
58         final Optional<String> testEnv = envsForCsr.getCommonName();
59
60         // then
61         assertThat(testEnv).isNotPresent();
62     }
63
64     @Test
65     void shouldReturnSystemEnvOrganizationVariableWhenItWasDefined() {
66         // given
67         when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION)).thenReturn(Optional.of(TEST_ENV));
68
69         // when
70         final Optional<String> testEnv = envsForCsr.getOrganization();
71
72         // then
73         assertThat(testEnv)
74                 .isPresent()
75                 .contains(TEST_ENV);
76     }
77
78     @Test
79     void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() {
80         // when
81         final Optional<String> testEnv = envsForCsr.getOrganization();
82
83         // then
84         assertThat(testEnv).isNotPresent();
85     }
86
87     @Test
88     void shouldReturnSystemEnvOuVariableWhenItWasDefined() {
89         // given
90         when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION_UNIT)).thenReturn(Optional.of(TEST_ENV));
91
92         // when
93         final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
94
95         // then
96         assertThat(testEnv)
97                 .isPresent()
98                 .contains(TEST_ENV);
99     }
100
101     @Test
102     public void shouldReportThatSystemEnvOuVariableIsNotPresentWhenItWasNotDefined() {
103         // when
104         final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
105
106         // then
107         assertThat(testEnv).isNotPresent();
108     }
109
110     @Test
111     void shouldReturnSystemEnvLocationVariableWhenItWasDefined() {
112         // given
113         when(envsForCsr.readEnv(CsrConfigurationEnvs.LOCATION)).thenReturn(Optional.of(TEST_ENV));
114
115         // when
116         final Optional<String> testEnv = envsForCsr.getLocation();
117
118         // then
119         assertThat(testEnv)
120                 .isPresent()
121                 .contains(TEST_ENV);
122     }
123
124     @Test
125     void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() {
126         // when
127         final Optional<String> testEnv = envsForCsr.getLocation();
128
129         // then
130         assertThat(testEnv).isNotPresent();
131     }
132
133     @Test
134     void shouldReturnSystemEnvStateVariableWhenItWasDefined() {
135         // given
136         when(envsForCsr.readEnv(CsrConfigurationEnvs.STATE)).thenReturn(Optional.of(TEST_ENV));
137
138         // when
139         final Optional<String> testEnv = envsForCsr.getState();
140
141         // then
142         assertThat(testEnv)
143                 .isPresent()
144                 .contains(TEST_ENV);
145     }
146
147     @Test
148     void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() {
149         // when
150         final Optional<String> testEnv = envsForCsr.getState();
151
152         // then
153         assertThat(testEnv).isNotPresent();
154     }
155
156     @Test
157     void shouldReturnSystemEnvCountryVariableWhenItWasDefined() {
158         // given
159         when(envsForCsr.readEnv(CsrConfigurationEnvs.COUNTRY)).thenReturn(Optional.of(TEST_ENV));
160
161         // when
162         final Optional<String> testEnv = envsForCsr.getCountry();
163
164         // then
165         assertThat(testEnv)
166                 .isPresent()
167                 .contains(TEST_ENV);
168     }
169
170     @Test
171     void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() {
172         // when
173         final Optional<String> testEnv = envsForCsr.getCountry();
174
175         // then
176         assertThat(testEnv).isNotPresent();
177     }
178
179     @Test
180     void shouldReturnSystemEnvSansVariableWhenItWasDefined() {
181         // given
182         when(envsForCsr.readEnv(CsrConfigurationEnvs.SANS)).thenReturn(Optional.of(TEST_ENV));
183
184         // when
185         final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
186
187         // then
188         assertThat(testEnv)
189                 .isPresent()
190                 .contains(TEST_ENV);
191     }
192
193     @Test
194     public void shouldReportThatSystemEnvSansVariableIsNotPresentWhenItWasNotDefined() {
195         // when
196         final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
197
198         // then
199         assertThat(testEnv).isNotPresent();
200     }
201 }