From e3283b7f953eca13ae68933b6d7b8cceb237acc4 Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Wed, 9 Jun 2021 12:12:30 +0200 Subject: Fix sonar issues Issue-ID: OOM-2764 Signed-off-by: Remigiusz Janeczek Change-Id: Iab71cbcac1982207e6f29b4b046280ad27143e03 --- .../oom/certservice/api/ReloadConfigControllerTest.java | 4 ++-- .../certification/CertificationModelFactoryTest.java | 17 ++++++++--------- .../configuration/CmpServersConfigLoaderTest.java | 9 +++++---- .../oom/certservice/cmpv2client/Cmpv2ClientTest.java | 2 -- .../cmpv2client/impl/CmpMessageHelperTest.java | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) (limited to 'certService/src/test') 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 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 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); -- cgit 1.2.3-korg