aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Baniewski <pawel.baniewski@nokia.com>2021-06-18 10:23:12 +0000
committerGerrit Code Review <gerrit@onap.org>2021-06-18 10:23:12 +0000
commit1003acd962438f82633c8a8a50f03499a8ca61a7 (patch)
tree8c678560609684024e7e4cc135d1b2bb19e5341c
parent649be36042dd5d58022c28e628399e350dc43282 (diff)
parente3283b7f953eca13ae68933b6d7b8cceb237acc4 (diff)
Merge "Fix sonar issues"
-rw-r--r--certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java4
-rw-r--r--certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java8
-rw-r--r--certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelper.java1
-rw-r--r--certService/src/test/java/org/onap/oom/certservice/api/ReloadConfigControllerTest.java4
-rw-r--r--certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java17
-rw-r--r--certService/src/test/java/org/onap/oom/certservice/certification/configuration/CmpServersConfigLoaderTest.java9
-rw-r--r--certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java2
-rw-r--r--certService/src/test/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelperTest.java2
-rw-r--r--certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/PemTruststore.java11
-rw-r--r--certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/Truststore.java4
-rw-r--r--certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/common/PasswordReaderTest.java5
-rw-r--r--certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/configuration/path/DelimitedPathsSplitterTest.java21
-rw-r--r--certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/copier/KeystoreCopierTest.java24
-rw-r--r--certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/merger/model/TruststoreTest.java16
14 files changed, 59 insertions, 69 deletions
diff --git a/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java b/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java
index d3a83ed1..fd35ec8e 100644
--- a/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java
+++ b/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,7 +86,7 @@ public class CertificationController {
@Parameter(description = "Private key in form of PEM object encoded in Base64 (with header and footer).")
@RequestHeader("PK") String encodedPrivateKey
) throws DecryptionException, CmpClientException {
- caName = caName.replaceAll("[\n|\r|\t]", "_");
+ caName = caName.replaceAll("[\n\r\t]", "_");
LOGGER.info("Received certificate signing request for CA named: {}", caName);
CertificationModel certificationModel = certificationModelFactory
.createCertificationModel(encodedCsr, encodedPrivateKey, caName);
diff --git a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java
index a673869d..38e7e3f8 100644
--- a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java
+++ b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java
@@ -180,13 +180,15 @@ public class CmpClientImpl implements CmpClient {
}
private void logServerResponse(CertResponse certResponse) {
- LOG.info("Response status code: {}", certResponse.getStatus().getStatus().toString());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Response status code: {}", certResponse.getStatus().getStatus());
+ }
if (certResponse.getStatus().getStatusString() != null) {
String serverMessage = certResponse.getStatus().getStatusString().getStringAt(0).getString();
LOG.warn("Response status text: {}", serverMessage);
}
- if (certResponse.getStatus().getFailInfo() != null) {
- LOG.warn("Response fail info: {}", certResponse.getStatus().getFailInfo().toString());
+ if (LOG.isWarnEnabled() && certResponse.getStatus().getFailInfo() != null) {
+ LOG.warn("Response fail info: {}", certResponse.getStatus().getFailInfo());
}
}
diff --git a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelper.java b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelper.java
index 1e64a2e0..0255b82e 100644
--- a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelper.java
+++ b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelper.java
@@ -25,7 +25,6 @@ import static org.onap.oom.certservice.cmpv2client.impl.CmpUtil.generateProtecte
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
-import java.security.Key;
import java.security.KeyPair;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
diff --git a/certService/src/test/java/org/onap/oom/certservice/api/ReloadConfigControllerTest.java b/certService/src/test/java/org/onap/oom/certservice/api/ReloadConfigControllerTest.java
index 8b367e1a..4247809c 100644
--- a/certService/src/test/java/org/onap/oom/certservice/api/ReloadConfigControllerTest.java
+++ b/certService/src/test/java/org/onap/oom/certservice/api/ReloadConfigControllerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ExtendWith(MockitoExtension.class)
-public class ReloadConfigControllerTest {
+class ReloadConfigControllerTest {
private static final String ERROR_MESSAGE = "Exception occurred during CMP Servers configuration loading";
diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java b/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java
index 8d28148b..705ae004 100644
--- a/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java
+++ b/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.oom.certservice.certification.CertificationData.CA_CERT;
@@ -111,8 +110,8 @@ class CertificationModelFactoryTest {
String expectedMessage = "Incorrect CSR, decryption failed";
when(
csrModelFactory.createCsrModel(
- eq(new CsrModelFactory.StringBase64(ENCODED_WRONG_CSR)),
- eq(new CsrModelFactory.StringBase64(ENCODED_WRONG_PK))
+ new CsrModelFactory.StringBase64(ENCODED_WRONG_CSR),
+ new CsrModelFactory.StringBase64(ENCODED_WRONG_PK)
)
).thenThrow(
new CsrDecryptionException(expectedMessage)
@@ -158,7 +157,7 @@ class CertificationModelFactoryTest {
CsrModel csrModel = mockCsrFactoryModelCreation();
Cmpv2Server testServer = mockCmpv2ProviderServerSelection();
when(
- certificationProvider.signCsr(eq(csrModel), eq(testServer))
+ certificationProvider.signCsr(csrModel, testServer)
).thenThrow(
new CmpClientException(expectedMessage)
);
@@ -178,14 +177,14 @@ class CertificationModelFactoryTest {
throws CmpClientException, Cmpv2ClientAdapterException {
CertificationModel expectedCertificationModel = getCertificationModel();
when(
- certificationProvider.signCsr(eq(csrModel), eq(testServer))
+ certificationProvider.signCsr(csrModel, testServer)
).thenReturn(expectedCertificationModel);
}
private Cmpv2Server mockCmpv2ProviderServerSelection() {
Cmpv2Server testServer = getCmpv2Server();
when(
- cmpv2ServerProvider.getCmpv2Server(eq(TEST_CA))
+ cmpv2ServerProvider.getCmpv2Server(TEST_CA)
).thenReturn(testServer);
return testServer;
}
@@ -195,8 +194,8 @@ class CertificationModelFactoryTest {
CsrModel csrModel = getCsrModel();
when(
csrModelFactory.createCsrModel(
- eq(new CsrModelFactory.StringBase64(ENCODED_CSR)),
- eq(new CsrModelFactory.StringBase64(ENCODED_PK))
+ new CsrModelFactory.StringBase64(ENCODED_CSR),
+ new CsrModelFactory.StringBase64(ENCODED_PK)
)
).thenReturn(csrModel);
return csrModel;
diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/configuration/CmpServersConfigLoaderTest.java b/certService/src/test/java/org/onap/oom/certservice/certification/configuration/CmpServersConfigLoaderTest.java
index b755b977..98932d0c 100644
--- a/certService/src/test/java/org/onap/oom/certservice/certification/configuration/CmpServersConfigLoaderTest.java
+++ b/certService/src/test/java/org/onap/oom/certservice/certification/configuration/CmpServersConfigLoaderTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,8 +70,9 @@ class CmpServersConfigLoaderTest {
List<Cmpv2Server> cmpServers = configLoader.load(path);
// Then
- assertThat(cmpServers).isNotNull();
- assertThat(cmpServers).hasSize(2);
+ assertThat(cmpServers)
+ .isNotNull()
+ .hasSize(2);
verifyThatCmpServerEquals(cmpServers.get(0), EXPECTED_FIRST_CMP_SERVER);
verifyThatCmpServerEquals(cmpServers.get(1), EXPECTED_SECOND_CMP_SERVER);
}
@@ -109,7 +110,7 @@ class CmpServersConfigLoaderTest {
private void verifyThatCmpServerEquals(Cmpv2Server cmpv2Server, Map<String, String> expected) {
assertThat(cmpv2Server.getCaName()).isEqualTo(expected.get("CA_NAME"));
assertThat(cmpv2Server.getUrl()).isEqualTo(expected.get("URL"));
- assertThat(cmpv2Server.getIssuerDN().toString()).isEqualTo(expected.get("ISSUER_DN"));
+ assertThat(cmpv2Server.getIssuerDN()).hasToString(expected.get("ISSUER_DN"));
assertThat(cmpv2Server.getCaMode().name()).isEqualTo(expected.get("CA_MODE"));
assertThat(cmpv2Server.getAuthentication().getIak()).isEqualTo(expected.get("IAK"));
assertThat(cmpv2Server.getAuthentication().getRv()).isEqualTo(expected.get("RV"));
diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java
index df9699ae..6a5a37f6 100644
--- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java
+++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java
@@ -41,9 +41,7 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Collections;
import java.util.Date;
-import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelperTest.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelperTest.java
index 0aae26a4..0d614cdc 100644
--- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelperTest.java
+++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelperTest.java
@@ -33,7 +33,7 @@ import org.bouncycastle.asn1.x509.KeyUsage;
import org.junit.jupiter.api.Test;
import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException;
-public class CmpMessageHelperTest {
+class CmpMessageHelperTest {
private final KeyUsage expectedKeyUsage = new KeyUsage(
KeyUsage.digitalSignature | KeyUsage.keyEncipherment | KeyUsage.nonRepudiation);
diff --git a/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/PemTruststore.java b/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/PemTruststore.java
index d7f4bfd2..642721cc 100644
--- a/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/PemTruststore.java
+++ b/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/PemTruststore.java
@@ -1,7 +1,7 @@
/*============LICENSE_START=======================================================
* oom-truststore-merger
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,10 +37,10 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator;
import org.bouncycastle.util.io.pem.PemObjectGenerator;
import org.bouncycastle.util.io.pem.PemWriter;
+import org.onap.oom.certservice.postprocessor.common.FileTools;
import org.onap.oom.certservice.postprocessor.merger.exception.MissingTruststoreException;
import org.onap.oom.certservice.postprocessor.merger.exception.TruststoreDataOperationException;
import org.onap.oom.certservice.postprocessor.merger.exception.WriteTruststoreFileException;
-import org.onap.oom.certservice.postprocessor.common.FileTools;
import org.onap.oom.certservice.postprocessor.merger.model.certificate.CertificateWithAlias;
import org.onap.oom.certservice.postprocessor.merger.model.certificate.CertificateWithAliasFactory;
import org.slf4j.Logger;
@@ -110,8 +110,8 @@ public class PemTruststore extends Truststore {
private List<Certificate> extractCertificatesFromFile() throws TruststoreDataOperationException {
try (FileInputStream inputStream = new FileInputStream(storeFile)) {
Security.addProvider(new BouncyCastleProvider());
- CertificateFactory factory = CertificateFactory.getInstance(X_509_CERTIFICATE, BOUNCY_CASTLE_PROVIDER);
- return new ArrayList<>(factory.generateCertificates(inputStream));
+ CertificateFactory certFactory = CertificateFactory.getInstance(X_509_CERTIFICATE, BOUNCY_CASTLE_PROVIDER);
+ return new ArrayList<>(certFactory.generateCertificates(inputStream));
} catch (Exception e) {
LOGGER.error("Cannot read certificates from file: {}", storeFile.getPath());
throw new TruststoreDataOperationException(e);
@@ -145,8 +145,7 @@ public class PemTruststore extends Truststore {
}
private void appendToFile(String certificatesAsString) throws WriteTruststoreFileException {
- try {
- FileOutputStream fileOutputStream = new FileOutputStream(storeFile, APPEND_TO_FILE);
+ try (FileOutputStream fileOutputStream = new FileOutputStream(storeFile, APPEND_TO_FILE)) {
fileOutputStream.write(certificatesAsString.getBytes());
} catch (Exception e) {
LOGGER.error("Cannot write certificates to file");
diff --git a/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/Truststore.java b/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/Truststore.java
index 058613a9..307fc9e6 100644
--- a/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/Truststore.java
+++ b/certServicePostProcessor/src/main/java/org/onap/oom/certservice/postprocessor/merger/model/Truststore.java
@@ -1,7 +1,7 @@
/*============LICENSE_START=======================================================
* oom-truststore-merger
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ public abstract class Truststore {
private final FileTools fileTools;
- public Truststore(File storeFile, FileTools fileTools) {
+ protected Truststore(File storeFile, FileTools fileTools) {
this.storeFile = storeFile;
this.fileTools = fileTools;
}
diff --git a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/common/PasswordReaderTest.java b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/common/PasswordReaderTest.java
index 697eaa83..1e229821 100644
--- a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/common/PasswordReaderTest.java
+++ b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/common/PasswordReaderTest.java
@@ -1,7 +1,7 @@
/*============LICENSE_START=======================================================
* oom-truststore-merger
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,8 @@ class PasswordReaderTest {
@Test
void shouldThrowExceptionForNonExistingFile() {
+ final File file = new File("src/test/resources/non-esisting-file.pass");
assertThatExceptionOfType(PasswordReaderException.class)
- .isThrownBy(() -> PasswordReader.readPassword(new File("src/test/resources/non-esisting-file.pass")));
+ .isThrownBy(() -> PasswordReader.readPassword(file));
}
}
diff --git a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/configuration/path/DelimitedPathsSplitterTest.java b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/configuration/path/DelimitedPathsSplitterTest.java
index be1bc394..c546604c 100644
--- a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/configuration/path/DelimitedPathsSplitterTest.java
+++ b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/configuration/path/DelimitedPathsSplitterTest.java
@@ -1,7 +1,7 @@
/*============LICENSE_START=======================================================
* oom-truststore-merger
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.oom.certservice.postprocessor.configuration.exception.CertificatesPathsValidationException;
+import org.onap.oom.certservice.postprocessor.configuration.model.EnvVariable;
@ExtendWith(MockitoExtension.class)
class DelimitedPathsSplitterTest {
@@ -58,16 +59,13 @@ class DelimitedPathsSplitterTest {
@Test
void shouldThrowExceptionWhenTruststoresPathsEnvIsEmpty() {
// when, then
- assertThatExceptionOfType(CertificatesPathsValidationException.class)
- .isThrownBy(() -> delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PATHS, Optional.of("")));
+ assertCorrectExceptionIsThrownFor(TRUSTSTORES_PATHS, "");
}
@Test
void shouldThrowExceptionWhenOneOfTruststoresPathsInvalid() {
// when, then
- assertThatExceptionOfType(CertificatesPathsValidationException.class)
- .isThrownBy(() -> delimitedPathsSplitter
- .getValidatedPaths(TRUSTSTORES_PATHS, Optional.of(INVALID_TRUSTSTORES)));
+ assertCorrectExceptionIsThrownFor(TRUSTSTORES_PATHS, INVALID_TRUSTSTORES);
}
@Test
@@ -92,16 +90,19 @@ class DelimitedPathsSplitterTest {
@Test
void shouldThrowExceptionWhenTruststoresPasswordsPathEnvIsEmpty() {
// when, then
- assertThatExceptionOfType(CertificatesPathsValidationException.class)
- .isThrownBy(
- () -> delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS, Optional.of("")));
+ assertCorrectExceptionIsThrownFor(TRUSTSTORES_PASSWORDS_PATHS, "");
}
@Test
void shouldThrowExceptionWhenOneOfTruststorePasswordPathsInvalid() {
// when, then
+ assertCorrectExceptionIsThrownFor(TRUSTSTORES_PASSWORDS_PATHS, INVALID_TRUSTSTORES_PASSWORDS);
+ }
+
+ private void assertCorrectExceptionIsThrownFor(EnvVariable envVariable, String envValue) {
+ final Optional<String> envValueOptional = Optional.of(envValue);
assertThatExceptionOfType(CertificatesPathsValidationException.class)
.isThrownBy(() -> delimitedPathsSplitter
- .getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS, Optional.of(INVALID_TRUSTSTORES_PASSWORDS)));
+ .getValidatedPaths(envVariable, envValueOptional));
}
}
diff --git a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/copier/KeystoreCopierTest.java b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/copier/KeystoreCopierTest.java
index 99193a8d..c4a34c50 100644
--- a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/copier/KeystoreCopierTest.java
+++ b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/copier/KeystoreCopierTest.java
@@ -1,7 +1,7 @@
/*============LICENSE_START=======================================================
* oom-truststore-merger
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import org.onap.oom.certservice.postprocessor.copier.exception.KeystoreNotExistE
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-public class KeystoreCopierTest {
+class KeystoreCopierTest {
private static final String SOURCE_CONTENT = "source content";
private static final String DESTINATION_CONTENT = "destination content";
@@ -50,7 +50,7 @@ public class KeystoreCopierTest {
copier.copyKeystores(configuration);
- assertThat(dir.listFiles()).isEmpty();
+ assertThat(dir).isEmptyDirectory();
}
@@ -64,7 +64,7 @@ public class KeystoreCopierTest {
copier.copyKeystores(configuration);
assertThat(readFile(destination)).isEqualTo(readFile(source));
- assertThat(backup.exists()).isTrue();
+ assertThat(backup).exists();
assertThat(readFile(backup)).isEqualTo(DESTINATION_CONTENT);
}
@@ -77,9 +77,9 @@ public class KeystoreCopierTest {
copier.copyKeystores(configuration);
- assertThat(destination.exists()).isTrue();
+ assertThat(destination).exists();
assertThat(readFile(destination)).isEqualTo(readFile(source));
- assertThat(backup.exists()).isFalse();
+ assertThat(backup).doesNotExist();
}
@Test
@@ -93,9 +93,9 @@ public class KeystoreCopierTest {
copier.copyKeystores(configuration)
);
- assertThat(source.exists()).isFalse();
- assertThat(destination.exists()).isFalse();
- assertThat(backup.exists()).isFalse();
+ assertThat(source).doesNotExist();
+ assertThat(destination).doesNotExist();
+ assertThat(backup).doesNotExist();
}
@Test
@@ -110,9 +110,9 @@ public class KeystoreCopierTest {
copier.copyKeystores(configuration)
);
- assertThat(source.exists()).isTrue();
- assertThat(destination.exists()).isFalse();
- assertThat(backup.exists()).isFalse();
+ assertThat(source).exists();
+ assertThat(destination).doesNotExist();
+ assertThat(backup).doesNotExist();
}
private AppConfiguration createConfiguration(File source, File destination) {
diff --git a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/merger/model/TruststoreTest.java b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/merger/model/TruststoreTest.java
index 8ef148a8..6150310d 100644
--- a/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/merger/model/TruststoreTest.java
+++ b/certServicePostProcessor/src/test/java/org/onap/oom/certservice/postprocessor/merger/model/TruststoreTest.java
@@ -1,7 +1,7 @@
/*============LICENSE_START=======================================================
* oom-truststore-merger
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import org.onap.oom.certservice.postprocessor.api.CertificateConstants;
import org.onap.oom.certservice.postprocessor.api.ExitableException;
import org.onap.oom.certservice.postprocessor.merger.exception.CreateBackupException;
import org.onap.oom.certservice.postprocessor.merger.exception.KeystoreInstanceException;
@@ -69,8 +68,8 @@ class TruststoreTest {
//then
File backupFile = new File(PEM_BACKUP_FILE_PATH);
- assertThat(backupFile.getName().endsWith(BACKUP_EXTENSION)).isTrue();
- assertThat(backupFile.isFile()).isTrue();
+ assertThat(backupFile.getName()).endsWith(BACKUP_EXTENSION);
+ assertThat(backupFile).isFile();
}
@ParameterizedTest
@@ -194,13 +193,4 @@ class TruststoreTest {
TestCertificateProvider.removeTemporaryFiles();
}
- private static Stream<Arguments> truststoreProvider()
- throws LoadTruststoreException, KeystoreInstanceException, PasswordReaderException {
- return Stream.of(
- Arguments.of(TestCertificateProvider.getSampleJksTruststoreFile()),
- Arguments.of(TestCertificateProvider.getSampleP12Truststore()),
- Arguments.of(TestCertificateProvider.getSamplePemTruststoreFile())
- );
- }
-
}