aboutsummaryrefslogtreecommitdiffstats
path: root/certServiceClient/src/test
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2020-02-28 09:49:08 +0000
committerGerrit Code Review <gerrit@onap.org>2020-02-28 09:49:08 +0000
commit8bff1cbaeec0ff9aaf82b3873464b04b324f933c (patch)
tree1f4c9f859103097c10adc5cb113932ff6f77934a /certServiceClient/src/test
parent7bf4e60bca87ae68d37a7632fa5c51e16608574e (diff)
parentcbe239fb79ee16e1aabfd0d2be286b41fa8941eb (diff)
Merge "Refactor access to env variables in certservice-client"
Diffstat (limited to 'certServiceClient/src/test')
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java44
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java54
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 695a9e4b..707094c0 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);