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 | |
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')
2 files changed, 51 insertions, 47 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); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java index d6bf431b..32298e9d 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java @@ -26,6 +26,8 @@ import org.onap.aaf.certservice.client.configuration.EnvsForCsr; import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException; import org.onap.aaf.certservice.client.configuration.factory.CsrConfigurationFactory; +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,14 +35,14 @@ import static org.mockito.Mockito.when; public class CsrConfigurationFactoryTest { - final String COMMON_NAME_VALID = "onap.org"; - final String SANS_VALID = "test-name"; - final String COUNTRY_VALID = "US"; - final String LOCATION_VALID = "San-Francisco"; - final String ORGANIZATION_VALID = "Linux-Foundation"; - final String ORGANIZATION_UNIT_VALID = "ONAP"; - final String STATE_VALID = "California"; - final String COMMON_NAME_INVALID = "onap.org*&"; + private final String COMMON_NAME_VALID = "onap.org"; + private final String SANS_VALID = "test-name"; + private final String COUNTRY_VALID = "US"; + private final String LOCATION_VALID = "San-Francisco"; + private final String ORGANIZATION_VALID = "Linux-Foundation"; + private final String ORGANIZATION_UNIT_VALID = "ONAP"; + private final String STATE_VALID = "California"; + private final String COMMON_NAME_INVALID = "onap.org*&"; private EnvsForCsr envsForCsr = mock(EnvsForCsr.class); @@ -48,13 +50,13 @@ public class CsrConfigurationFactoryTest { @Test void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() throws CsrConfigurationException { // given - when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_VALID); - when(envsForCsr.getSubjectAlternativesName()).thenReturn(SANS_VALID); - when(envsForCsr.getCountry()).thenReturn(COUNTRY_VALID); - when(envsForCsr.getLocation()).thenReturn(LOCATION_VALID); - when(envsForCsr.getOrganization()).thenReturn(ORGANIZATION_VALID); - when(envsForCsr.getOrganizationUnit()).thenReturn(ORGANIZATION_UNIT_VALID); - when(envsForCsr.getState()).thenReturn(STATE_VALID); + when(envsForCsr.getCommonName()).thenReturn(Optional.of(COMMON_NAME_VALID)); + when(envsForCsr.getSubjectAlternativesName()).thenReturn(Optional.of(SANS_VALID)); + when(envsForCsr.getCountry()).thenReturn(Optional.of(COUNTRY_VALID)); + when(envsForCsr.getLocation()).thenReturn(Optional.of(LOCATION_VALID)); + when(envsForCsr.getOrganization()).thenReturn(Optional.of(ORGANIZATION_VALID)); + when(envsForCsr.getOrganizationUnit()).thenReturn(Optional.of(ORGANIZATION_UNIT_VALID)); + when(envsForCsr.getState()).thenReturn(Optional.of(STATE_VALID)); // when CsrConfiguration configuration = new CsrConfigurationFactory(envsForCsr).create(); @@ -72,10 +74,10 @@ public class CsrConfigurationFactoryTest { @Test void create_shouldReturnSuccessWhenNotRequiredVariablesAreNotSet() throws CsrConfigurationException { // given - when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_VALID); - when(envsForCsr.getState()).thenReturn(STATE_VALID); - when(envsForCsr.getCountry()).thenReturn(COUNTRY_VALID); - when(envsForCsr.getOrganization()).thenReturn(ORGANIZATION_VALID); + when(envsForCsr.getCommonName()).thenReturn(Optional.of(COMMON_NAME_VALID)); + when(envsForCsr.getState()).thenReturn(Optional.of(STATE_VALID)); + when(envsForCsr.getCountry()).thenReturn(Optional.of(COUNTRY_VALID)); + when(envsForCsr.getOrganization()).thenReturn(Optional.of(ORGANIZATION_VALID)); // when CsrConfiguration configuration = new CsrConfigurationFactory(envsForCsr).create(); @@ -91,13 +93,13 @@ public class CsrConfigurationFactoryTest { @Test void create_shouldReturnCsrConfigurationExceptionWhenCommonNameContainsSpecialCharacters() { // given - when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_INVALID); - when(envsForCsr.getSubjectAlternativesName()).thenReturn(SANS_VALID); - when(envsForCsr.getCountry()).thenReturn(COUNTRY_VALID); - when(envsForCsr.getLocation()).thenReturn(LOCATION_VALID); - when(envsForCsr.getOrganization()).thenReturn(ORGANIZATION_VALID); - when(envsForCsr.getOrganizationUnit()).thenReturn(ORGANIZATION_UNIT_VALID); - when(envsForCsr.getState()).thenReturn(SANS_VALID); + when(envsForCsr.getCommonName()).thenReturn(Optional.of(COMMON_NAME_INVALID)); + when(envsForCsr.getSubjectAlternativesName()).thenReturn(Optional.of(SANS_VALID)); + when(envsForCsr.getCountry()).thenReturn(Optional.of(COUNTRY_VALID)); + when(envsForCsr.getLocation()).thenReturn(Optional.of(LOCATION_VALID)); + when(envsForCsr.getOrganization()).thenReturn(Optional.of(ORGANIZATION_VALID)); + when(envsForCsr.getOrganizationUnit()).thenReturn(Optional.of(ORGANIZATION_UNIT_VALID)); + when(envsForCsr.getState()).thenReturn(Optional.of(SANS_VALID)); // when CsrConfigurationFactory configurationFactory = new CsrConfigurationFactory(envsForCsr); |