diff options
author | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2020-02-27 16:15:29 +0100 |
---|---|---|
committer | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2020-02-28 09:45:00 +0100 |
commit | cbe239fb79ee16e1aabfd0d2be286b41fa8941eb (patch) | |
tree | 16997bb13410724d97d69ddc7fb57dd633d242a3 /certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java | |
parent | 7dc94694ec75ce738ecb2e98508c57eadc1d81fa (diff) |
Refactor access to env variables in certservice-client
Issue-ID: AAF-996
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: Ib11998a72e3addefd16587cda5e10fb787e99a62
Diffstat (limited to 'certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java')
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java index f355de1a..2c875c24 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java @@ -26,6 +26,8 @@ import org.onap.aaf.certservice.client.configuration.EnvsForClient; import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException; import org.onap.aaf.certservice.client.configuration.factory.ClientConfigurationFactory; +import java.util.Optional; + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.mock; @@ -33,22 +35,22 @@ import static org.mockito.Mockito.when; public class ClientConfigurationFactoryTest { - final String CA_NAME_VALID = "caaaftest2"; - final String TIME_OUT_VALID = "30000"; - final String OUTPUT_PATH_VALID = "/opt/app/osaaf"; - final String URL_TO_CERT_SERVICE_VALID = "http://cert-service:8080/v1/certificate/"; - final String CA_NAME_INVALID = "caaaftest2#$"; - final String OUTPUT_PATH_INVALID = "/opt//app/osaaf"; + private final String CA_NAME_VALID = "caaaftest2"; + private final String TIME_OUT_VALID = "30000"; + private final String OUTPUT_PATH_VALID = "/opt/app/osaaf"; + private final String URL_TO_CERT_SERVICE_VALID = "http://cert-service:8080/v1/certificate/"; + private final String CA_NAME_INVALID = "caaaftest2#$"; + private final String OUTPUT_PATH_INVALID = "/opt//app/osaaf"; private EnvsForClient envsForClient = mock(EnvsForClient.class); @Test void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() throws ClientConfigurationException { // given - when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID); - when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID); - when(envsForClient.getRequestTimeOut()).thenReturn(TIME_OUT_VALID); - when(envsForClient.getUrlToCertService()).thenReturn(URL_TO_CERT_SERVICE_VALID); + when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_VALID)); + when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID)); + when(envsForClient.getRequestTimeOut()).thenReturn(Optional.of(TIME_OUT_VALID)); + when(envsForClient.getUrlToCertService()).thenReturn(Optional.of(URL_TO_CERT_SERVICE_VALID)); // when ClientConfiguration configuration = new ClientConfigurationFactory(envsForClient).create(); @@ -63,8 +65,8 @@ public class ClientConfigurationFactoryTest { @Test void create_shouldReturnSuccessWhenDefaultVariablesAreNotSet() throws ClientConfigurationException { // given - when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID); - when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID); + when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_VALID)); + when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID)); // when ClientConfiguration configuration = new ClientConfigurationFactory(envsForClient).create(); @@ -79,7 +81,7 @@ public class ClientConfigurationFactoryTest { @Test void create_shouldReturnClientExceptionWhenRequiredVariableIsNotSet() { // given - when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID); + when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID)); // when ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory(envsForClient); @@ -93,10 +95,10 @@ public class ClientConfigurationFactoryTest { @Test void create_shouldReturnClientExceptionWhenCANameContainsSpecialCharacters() { // given - when(envsForClient.getCaName()).thenReturn(CA_NAME_INVALID); - when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID); - when(envsForClient.getRequestTimeOut()).thenReturn(TIME_OUT_VALID); - when(envsForClient.getUrlToCertService()).thenReturn(URL_TO_CERT_SERVICE_VALID); + when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_INVALID)); + when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID)); + when(envsForClient.getRequestTimeOut()).thenReturn(Optional.of(TIME_OUT_VALID)); + when(envsForClient.getUrlToCertService()).thenReturn(Optional.of(URL_TO_CERT_SERVICE_VALID)); // when ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory(envsForClient); @@ -110,10 +112,10 @@ public class ClientConfigurationFactoryTest { @Test void create_shouldReturnClientExceptionWhenOutputPathContainsSpecialCharacters() { // given - when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID); - when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_INVALID); - when(envsForClient.getRequestTimeOut()).thenReturn(TIME_OUT_VALID); - when(envsForClient.getUrlToCertService()).thenReturn(URL_TO_CERT_SERVICE_VALID); + when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_VALID)); + when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_INVALID)); + when(envsForClient.getRequestTimeOut()).thenReturn(Optional.of(TIME_OUT_VALID)); + when(envsForClient.getUrlToCertService()).thenReturn(Optional.of(URL_TO_CERT_SERVICE_VALID)); // when ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory(envsForClient); |