private void createKeystore(List<String> data, PrivateKey privateKey)
throws PemConversionException, CertFileWriterException {
Password password = passwordGenerator.generate(PASSWORD_LENGTH);
- String keystoreArtifactName = String.format("%s.%s", KEYSTORE, fileExtension);
- String keystorePass = String.format("%s.%s", KEYSTORE, PASS_EXT);
+ String keystoreArtifactName = getFilenameWithExtension(KEYSTORE, fileExtension);
+ String keystorePass = getFilenameWithExtension(KEYSTORE, PASS_EXT);
LOGGER.debug("Attempt to create keystore files and saving data. File names: {}, {}", keystoreArtifactName, keystorePass);
private void createTruststore(List<String> data)
throws PemConversionException, CertFileWriterException {
Password password = passwordGenerator.generate(PASSWORD_LENGTH);
- String truststoreArtifactName = String.format("%s.%s", TRUSTSTORE, fileExtension);
- String truststorePass = String.format("%s.%s", TRUSTSTORE, PASS_EXT);
+ String truststoreArtifactName = getFilenameWithExtension(TRUSTSTORE, fileExtension);
+ String truststorePass = getFilenameWithExtension(TRUSTSTORE, PASS_EXT);
LOGGER.debug("Attempt to create truststore files and saving data. File names: {}, {}", truststoreArtifactName, truststorePass);
private byte[] getPasswordAsBytes(Password password) {
return password.getCurrentPassword().getBytes();
}
+
+ private String getFilenameWithExtension(String filename, String extension) {
+ return String.format("%s.%s", filename, extension);
+ }
}
AppExitHandler appExitHandler = new AppExitHandler();
@Test
- public void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() {
+ void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() {
// given
doNothing().when(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION);
doNothing().when(appExitHandler).exit(SUCCESS);
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
-public class CsrFactoryTest {
+class CsrFactoryTest {
CsrConfiguration config = mock(CsrConfiguration.class);
private static final String PRIVATE_KEY_PEM_PATH = RESOURCES_DIR + "rsaPrivateKeyPem";
@Test
- public void shouldReturnProperlyEncodedPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException, PkEncodingException, IOException {
+ void shouldReturnProperlyEncodedPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException, PkEncodingException, IOException {
//given
String expectedPem = Files.readString(Paths.get(PRIVATE_KEY_PEM_PATH));
PrivateKeyToPemEncoder testedPkEncoder = new PrivateKeyToPemEncoder();
KeyFactory kf = KeyFactory.getInstance(ENCRYPTION_ALGORITHM);
return kf.generatePrivate(spec);
}
-}
\ No newline at end of file
+}
private EnvProvider envProvider;
@BeforeEach
- public void setUp() {
+ void setUp() {
envProvider = Mockito.spy(EnvProvider.class);
}
@Test
- public void shouldReturnSystemEnvVariableWhenItWasDefined() {
+ void shouldReturnSystemEnvVariableWhenItWasDefined() {
// given
when(envProvider.getSystemEnv(TEST_ENV)).thenReturn(TEST_ENV_VALUE);
final Optional<String> testEnv = envProvider.readEnvVariable(TEST_ENV);
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV_VALUE);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV_VALUE);
}
@Test
- public void shouldReportThatSystemEnvVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envProvider.readEnvVariable(TEST_ENV);
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
}
final Optional<String> testEnv = envsForCsr.getCommonName();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvCommonNameVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForCsr.getCommonName();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForCsr.getOrganization();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvOrganizationVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForCsr.getOrganization();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
final Optional<String> testEnv = envsForCsr.getOrganizationUnit();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForCsr.getLocation();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvLocationVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForCsr.getLocation();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForCsr.getState();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvStateVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForCsr.getState();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForCsr.getCountry();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvCountryVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForCsr.getCountry();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
final Optional<String> testEnv = envsForCsr.getSubjectAlternativesName();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
}
final Optional<String> testEnv = envsForTls.getKeystorePath();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvKeyStorePathVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvKeyStorePathVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForTls.getKeystorePath();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForTls.getKeystorePassword();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvKeyStorePasswordVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvKeyStorePasswordVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForTls.getKeystorePassword();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForTls.getTruststorePath();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvTrustStorePathVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvTrustStorePathVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForTls.getTruststorePath();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
@Test
final Optional<String> testEnv = envsForTls.getTruststorePassword();
// then
- assertThat(testEnv.isPresent()).isTrue();
- assertThat(testEnv.get()).isEqualTo(TEST_ENV);
+ assertThat(testEnv)
+ .isPresent()
+ .contains(TEST_ENV);
}
@Test
- public void shouldReportThatSystemEnvTrustStorePasswordVariableIsNotPresentWhenItWasNotDefined() {
+ void shouldReportThatSystemEnvTrustStorePasswordVariableIsNotPresentWhenItWasNotDefined() {
// when
final Optional<String> testEnv = envsForTls.getTruststorePassword();
// then
- assertThat(testEnv.isPresent()).isFalse();
+ assertThat(testEnv).isNotPresent();
}
}
import static org.assertj.core.api.Assertions.assertThat;
-public class TlsConfigurationExceptionTest {
+class TlsConfigurationExceptionTest {
@Test
- public void containsProperExitStatus() {
+ void containsProperExitStatus() {
// Given
ExitStatus exitStatus = null;
}
// Then
- assertThat(exitStatus).isNotNull();
- assertThat(exitStatus).isEqualTo(ExitStatus.TLS_CONFIGURATION_EXCEPTION);
+ assertThat(exitStatus)
+ .isNotNull()
+ .isEqualTo(ExitStatus.TLS_CONFIGURATION_EXCEPTION);
}
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-public class AbstractConfigurationFactoryTest {
+class AbstractConfigurationFactoryTest {
private final AbstractConfigurationFactory cut = mock(AbstractConfigurationFactory.class, Mockito.CALLS_REAL_METHODS);
@ParameterizedTest
@ValueSource(strings = {"/var/log", "/", "/var/log/", "/second_var", "/second-var"})
- public void shouldAcceptValidPath(String path) {
+ void shouldAcceptValidPath(String path) {
assertThat(cut.isPathValid(path)).isTrue();
}
@ParameterizedTest
@ValueSource(strings = {"/var/log?", "", "var_", "var", "//", "/var//log"})
- public void shouldRejectInvalidPath(String path) {
+ void shouldRejectInvalidPath(String path) {
assertThat(cut.isPathValid(path)).isFalse();
}
@ParameterizedTest
@ValueSource(strings = {"PL", "DE", "PN", "US", "IO", "CA", "KH", "CO", "DK", "EC", "CZ", "CN", "BR", "BD", "BE"})
- public void shouldAcceptValidCountryCode(String countryCode) {
+ void shouldAcceptValidCountryCode(String countryCode) {
assertThat(cut.isCountryValid(countryCode)).isTrue();
}
@ParameterizedTest
@ValueSource(strings = {"", "QQ", "AFG", "D", "&*", "!", "ONAP", "p", "pl", "us", "afg"})
- public void shouldRejectInvalidCountryCode(String countryCode) {
+ void shouldRejectInvalidCountryCode(String countryCode) {
assertThat(cut.isCountryValid(countryCode)).isFalse();
}
@ParameterizedTest
@ValueSource(strings = {"caname", "caname1", "123caName", "ca1name"})
- public void shouldAcceptValidAlphanumeric(String caName) {
+ void shouldAcceptValidAlphanumeric(String caName) {
assertThat(cut.isAlphaNumeric(caName)).isTrue();
}
@ParameterizedTest
@ValueSource(strings = {"44caname$", "#caname1", "1c_aname", "ca1-name"})
- public void shouldRejectInvalidAlphanumeric(String caName) {
+ void shouldRejectInvalidAlphanumeric(String caName) {
assertThat(cut.isAlphaNumeric(caName)).isFalse();
}
@ParameterizedTest
@ValueSource(strings = {"example.com", "www.example.com"})
- public void shouldAcceptValidCommonName(String commonName) {
+ void shouldAcceptValidCommonName(String commonName) {
assertThat(cut.isCommonNameValid(commonName)).isTrue();
}
@ParameterizedTest
@ValueSource(strings = {"https://example.com", "http://example.com", "example.com:8080", "0.0.0.0", "@#$%.com"})
- public void shouldRejectInvalidCommonName(String commonName) {
+ void shouldRejectInvalidCommonName(String commonName) {
assertThat(cut.isCommonNameValid(commonName)).isFalse();
}
@ParameterizedTest
@ValueSource(strings = {"JKS", "P12", "PEM"})
- public void shouldAcceptValidOutputType(String outputType) {
+ void shouldAcceptValidOutputType(String outputType) {
assertThat(cut.isOutputTypeValid(outputType)).isTrue();
}
@ParameterizedTest
@ValueSource(strings = {"jks", "p12", "pem", "", "pass", "!@$#pp"})
- public void shouldRejectInvalidOutputType(String outputType) {
+ void shouldRejectInvalidOutputType(String outputType) {
assertThat(cut.isOutputTypeValid(outputType)).isFalse();
}
}