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
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.client.configuration;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.mockito.Mockito;
27 import java.util.Optional;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.mockito.Mockito.when;
32 class EnvsForCsrTest {
33 private static final String TEST_ENV = "testEnv";
34 private EnvsForCsr envsForCsr;
38 envsForCsr = Mockito.spy(EnvsForCsr.class);
42 void shouldReturnSystemEnvCommonNameVariableWhenItWasDefined() {
44 when(envsForCsr.readEnv(CsrConfigurationEnvs.COMMON_NAME)).thenReturn(Optional.of(TEST_ENV));
47 final Optional<String> testEnv = envsForCsr.getCommonName();
56 void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() {
58 final Optional<String> testEnv = envsForCsr.getCommonName();
61 assertThat(testEnv).isNotPresent();
65 void shouldReturnSystemEnvOrganizationVariableWhenItWasDefined() {
67 when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION)).thenReturn(Optional.of(TEST_ENV));
70 final Optional<String> testEnv = envsForCsr.getOrganization();
79 void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() {
81 final Optional<String> testEnv = envsForCsr.getOrganization();
84 assertThat(testEnv).isNotPresent();
88 void shouldReturnSystemEnvOuVariableWhenItWasDefined() {
90 when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION_UNIT)).thenReturn(Optional.of(TEST_ENV));
93 final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
102 void shouldReportThatSystemEnvOuVariableIsNotPresentWhenItWasNotDefined() {
104 final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
107 assertThat(testEnv).isNotPresent();
111 void shouldReturnSystemEnvLocationVariableWhenItWasDefined() {
113 when(envsForCsr.readEnv(CsrConfigurationEnvs.LOCATION)).thenReturn(Optional.of(TEST_ENV));
116 final Optional<String> testEnv = envsForCsr.getLocation();
125 void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() {
127 final Optional<String> testEnv = envsForCsr.getLocation();
130 assertThat(testEnv).isNotPresent();
134 void shouldReturnSystemEnvStateVariableWhenItWasDefined() {
136 when(envsForCsr.readEnv(CsrConfigurationEnvs.STATE)).thenReturn(Optional.of(TEST_ENV));
139 final Optional<String> testEnv = envsForCsr.getState();
148 void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() {
150 final Optional<String> testEnv = envsForCsr.getState();
153 assertThat(testEnv).isNotPresent();
157 void shouldReturnSystemEnvCountryVariableWhenItWasDefined() {
159 when(envsForCsr.readEnv(CsrConfigurationEnvs.COUNTRY)).thenReturn(Optional.of(TEST_ENV));
162 final Optional<String> testEnv = envsForCsr.getCountry();
171 void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() {
173 final Optional<String> testEnv = envsForCsr.getCountry();
176 assertThat(testEnv).isNotPresent();
180 void shouldReturnSystemEnvSansVariableWhenItWasDefined() {
182 when(envsForCsr.readEnv(CsrConfigurationEnvs.SANS)).thenReturn(Optional.of(TEST_ENV));
185 final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
194 void shouldReportThatSystemEnvSansVariableIsNotPresentWhenItWasNotDefined() {
196 final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
199 assertThat(testEnv).isNotPresent();