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
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.aaf.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();
50 assertThat(testEnv.isPresent()).isTrue();
51 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
55 public void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() {
57 final Optional<String> testEnv = envsForCsr.getCommonName();
60 assertThat(testEnv.isPresent()).isFalse();
64 void shouldReturnSystemEnvOrganizationVariableWhenItWasDefined() {
66 when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION)).thenReturn(Optional.of(TEST_ENV));
69 final Optional<String> testEnv = envsForCsr.getOrganization();
72 assertThat(testEnv.isPresent()).isTrue();
73 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
77 public void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() {
79 final Optional<String> testEnv = envsForCsr.getOrganization();
82 assertThat(testEnv.isPresent()).isFalse();
86 void shouldReturnSystemEnvOuVariableWhenItWasDefined() {
88 when(envsForCsr.readEnv(CsrConfigurationEnvs.ORGANIZATION_UNIT)).thenReturn(Optional.of(TEST_ENV));
91 final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
94 assertThat(testEnv.isPresent()).isTrue();
95 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
99 public void shouldReportThatSystemEnvOuVariableIsNotPresentWhenItWasNotDefined() {
101 final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
104 assertThat(testEnv.isPresent()).isFalse();
108 void shouldReturnSystemEnvLocationVariableWhenItWasDefined() {
110 when(envsForCsr.readEnv(CsrConfigurationEnvs.LOCATION)).thenReturn(Optional.of(TEST_ENV));
113 final Optional<String> testEnv = envsForCsr.getLocation();
116 assertThat(testEnv.isPresent()).isTrue();
117 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
121 public void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() {
123 final Optional<String> testEnv = envsForCsr.getLocation();
126 assertThat(testEnv.isPresent()).isFalse();
130 void shouldReturnSystemEnvStateVariableWhenItWasDefined() {
132 when(envsForCsr.readEnv(CsrConfigurationEnvs.STATE)).thenReturn(Optional.of(TEST_ENV));
135 final Optional<String> testEnv = envsForCsr.getState();
138 assertThat(testEnv.isPresent()).isTrue();
139 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
143 public void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() {
145 final Optional<String> testEnv = envsForCsr.getState();
148 assertThat(testEnv.isPresent()).isFalse();
152 void shouldReturnSystemEnvCountryVariableWhenItWasDefined() {
154 when(envsForCsr.readEnv(CsrConfigurationEnvs.COUNTRY)).thenReturn(Optional.of(TEST_ENV));
157 final Optional<String> testEnv = envsForCsr.getCountry();
160 assertThat(testEnv.isPresent()).isTrue();
161 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
165 public void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() {
167 final Optional<String> testEnv = envsForCsr.getCountry();
170 assertThat(testEnv.isPresent()).isFalse();
174 void shouldReturnSystemEnvSansVariableWhenItWasDefined() {
176 when(envsForCsr.readEnv(CsrConfigurationEnvs.SANS)).thenReturn(Optional.of(TEST_ENV));
179 final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
182 assertThat(testEnv.isPresent()).isTrue();
183 assertThat(testEnv.get()).isEqualTo(TEST_ENV);
187 public void shouldReportThatSystemEnvSansVariableIsNotPresentWhenItWasNotDefined() {
189 final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
192 assertThat(testEnv.isPresent()).isFalse();