From c85a8965e876fde2089582a6468eb02ce18bafd5 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Wed, 18 Mar 2020 09:38:27 +0100 Subject: Resolve all checkstyle warnings Issue-ID: AAF-1107 Signed-off-by: Bartosz Gardziejewski Change-Id: I28cfc2b82f1a4800a984e30f59ff36fe90bebb38 --- .../configuration/CmpServersConfigLoaderTest.java | 9 ++-- .../configuration/CmpServersConfigTest.java | 31 ++++++------ .../configuration/Cmpv2ServerProviderTest.java | 2 +- .../Cmpv2ServerConfigurationValidatorTest.java | 26 +++++----- .../constraints/Cmpv2URLValidatorTest.java | 55 --------------------- .../constraints/Cmpv2UrlValidatorTest.java | 57 ++++++++++++++++++++++ .../violations/PortNumberViolationTest.java | 36 +++++++------- .../violations/RequestTypeViolationTest.java | 18 ++++--- 8 files changed, 120 insertions(+), 114 deletions(-) delete mode 100644 certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2URLValidatorTest.java create mode 100644 certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2UrlValidatorTest.java (limited to 'certService/src/test/java/org/onap/aaf/certservice/certification/configuration') diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java index c78f6ceb..61970050 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import java.util.Map; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.aaf.certservice.CertServiceApplication; @@ -79,8 +80,8 @@ class CmpServersConfigLoaderTest { void shouldThrowExceptionWhenFileMissing() { // When Exception exception = assertThrows( - CmpServersConfigLoadingException.class, - () -> configLoader.load(NONEXISTENT_CONFIG_FILENAME)); + CmpServersConfigLoadingException.class, + () -> configLoader.load(NONEXISTENT_CONFIG_FILENAME)); // Then assertThat(exception.getMessage()).contains("Exception occurred during CMP Servers configuration loading"); @@ -93,8 +94,8 @@ class CmpServersConfigLoaderTest { // When Exception exception = assertThrows( - CmpServersConfigLoadingException.class, - () -> configLoader.load(path)); + CmpServersConfigLoadingException.class, + () -> configLoader.load(path)); // Then assertThat(exception.getMessage()).contains("Validation of CMPv2 servers configuration failed"); diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java index 043dbc03..511c3966 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java @@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.startsWith; import java.util.List; + import org.bouncycastle.asn1.x500.X500Name; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -95,12 +96,12 @@ class CmpServersConfigTest { void shouldRethrowExceptionWhenReloaded() throws CmpServersConfigLoadingException { // Given Mockito.when(cmpServersConfigLoader.load(any())).thenThrow(new CmpServersConfigLoadingException( - ERROR_MESSAGE)); + ERROR_MESSAGE)); // Then assertThrows( - CmpServersConfigLoadingException.class, - () -> cmpServersConfig.reloadConfiguration()); + CmpServersConfigLoadingException.class, + () -> cmpServersConfig.reloadConfiguration()); } @Test @@ -110,8 +111,8 @@ class CmpServersConfigTest { // When Exception exception = assertThrows( - CmpServersConfigLoadingException.class, - () -> cmpServersConfig.reloadConfiguration()); + CmpServersConfigLoadingException.class, + () -> cmpServersConfig.reloadConfiguration()); // Then assertThat(exception.getMessage()).isEqualTo(ERROR_MESSAGE); @@ -128,10 +129,10 @@ class CmpServersConfigTest { // Then receivedCmpServers.forEach((server) -> assertThat(server.toString()) - .doesNotContain( - server.getAuthentication().getIak(), - server.getAuthentication().getRv() - )); + .doesNotContain( + server.getAuthentication().getIak(), + server.getAuthentication().getRv() + )); } @Test @@ -141,8 +142,8 @@ class CmpServersConfigTest { // Then assertThrows( - CmpServersConfigLoadingException.class, - () -> cmpServersConfig.loadConfiguration()); + CmpServersConfigLoadingException.class, + () -> cmpServersConfig.loadConfiguration()); } @Test @@ -152,8 +153,8 @@ class CmpServersConfigTest { // When Exception exception = assertThrows( - CmpServersConfigLoadingException.class, - () -> cmpServersConfig.loadConfiguration()); + CmpServersConfigLoadingException.class, + () -> cmpServersConfig.loadConfiguration()); // Then assertThat(exception.getMessage()).isEqualTo(ERROR_MESSAGE); @@ -201,8 +202,8 @@ class CmpServersConfigTest { // When assertThrows( - CmpServersConfigLoadingException.class, - () -> cmpServersConfig.loadConfiguration()); + CmpServersConfigLoadingException.class, + () -> cmpServersConfig.loadConfiguration()); // Then assertThat(cmpServersConfig.isReady()).isFalse(); diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/Cmpv2ServerProviderTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/Cmpv2ServerProviderTest.java index 7e14e470..b83fb9aa 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/Cmpv2ServerProviderTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/Cmpv2ServerProviderTest.java @@ -51,7 +51,7 @@ class Cmpv2ServerProviderTest { @BeforeEach void setUp() { cmpv2ServerProvider = - new Cmpv2ServerProvider(cmpServersConfig); + new Cmpv2ServerProvider(cmpServersConfig); } @Test diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServerConfigurationValidatorTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServerConfigurationValidatorTest.java index 10a7ba46..1c021b43 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServerConfigurationValidatorTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServerConfigurationValidatorTest.java @@ -54,13 +54,13 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldNotThrowExceptionWhenServerConfigurationIsValid() { + void shouldNotThrowExceptionWhenServerConfigurationIsValid() { // Then assertDoesNotThrow(() -> validator.validate(server)); } @Test - public void shouldThrowExceptionWhenWrongProtocolInURL() { + void shouldThrowExceptionWhenWrongProtocolInUrl() { // Given server.setUrl("https://test.test.test:60000/"); @@ -69,7 +69,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenWrongPortInURL() { + void shouldThrowExceptionWhenWrongPortInUrl() { // Given server.setUrl("http://test.test.test:70000/"); @@ -78,7 +78,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenWrongCANameLength() { + void shouldThrowExceptionWhenWrongCaNameLength() { // Given server.setCaName(EMPTY_STRING); @@ -87,7 +87,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenWrongRVLength() { + void shouldThrowExceptionWhenWrongRvLength() { // Given authentication.setRv(EMPTY_STRING); @@ -97,7 +97,7 @@ class Cmpv2ServerConfigurationValidatorTest { @Test - public void shouldThrowExceptionWhenWrongIAKLength() { + void shouldThrowExceptionWhenWrongIakLength() { // Given authentication.setIak(EMPTY_STRING); @@ -106,7 +106,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenCaNameIsNull() { + void shouldThrowExceptionWhenCaNameIsNull() { // Given server.setCaName(null); @@ -115,7 +115,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenIssuerDnIsNull() { + void shouldThrowExceptionWhenIssuerDnIsNull() { // Given server.setIssuerDN(null); @@ -124,7 +124,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenCaModeIsNull() { + void shouldThrowExceptionWhenCaModeIsNull() { // Given server.setCaMode(null); @@ -133,7 +133,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenUrlIsNull() { + void shouldThrowExceptionWhenUrlIsNull() { // Given server.setUrl(null); @@ -142,7 +142,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenAuthenticationIsNull() { + void shouldThrowExceptionWhenAuthenticationIsNull() { // Given server.setAuthentication(null); @@ -151,7 +151,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenIakIsNull() { + void shouldThrowExceptionWhenIakIsNull() { // Given authentication.setIak(null); @@ -160,7 +160,7 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void shouldThrowExceptionWhenRvIsNull() { + void shouldThrowExceptionWhenRvIsNull() { // Given authentication.setRv(null); diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2URLValidatorTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2URLValidatorTest.java deleted file mode 100644 index 78368d8a..00000000 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2URLValidatorTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PROJECT - * ================================================================================ - * Copyright (C) 2020 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - - -package org.onap.aaf.certservice.certification.configuration.validation.constraints; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class Cmpv2URLValidatorTest { - - private final Cmpv2URLValidator validator = new Cmpv2URLValidator(); - - @Test - public void givenCorrectURLWhenValidatingShouldReturnTrue() { - //given - String URL = "http://127.0.0.1/ejbca/publicweb/cmp/cmp"; - - //when - boolean result = validator.isValid(URL, null); - - //then - assertTrue(result); - } - - @Test - public void givenIncorrectURLWhenValidatingShouldReturnFalse() { - //given - String URL = "httttp://127.0.0.1:80000/ejbca/publicweb/cmp/cmp"; - - //when - boolean result = validator.isValid(URL, null); - - //then - assertFalse(result); - } -} \ No newline at end of file diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2UrlValidatorTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2UrlValidatorTest.java new file mode 100644 index 00000000..7082626f --- /dev/null +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/Cmpv2UrlValidatorTest.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.onap.aaf.certservice.certification.configuration.validation.constraints; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +class Cmpv2UrlValidatorTest { + + private final Cmpv2UrlValidator validator = new Cmpv2UrlValidator(); + + @Test + void givenCorrectUrlWhenValidatingShouldReturnTrue() { + //given + String url = "http://127.0.0.1/ejbca/publicweb/cmp/cmp"; + + //when + boolean result = validator.isValid(url, null); + + //then + assertTrue(result); + } + + @Test + void givenIncorrectUrlWhenValidatingShouldReturnFalse() { + //given + String url = "httttp://127.0.0.1:80000/ejbca/publicweb/cmp/cmp"; + + //when + boolean result = validator.isValid(url, null); + + //then + assertFalse(result); + } +} diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/PortNumberViolationTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/PortNumberViolationTest.java index d1850473..e729c738 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/PortNumberViolationTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/PortNumberViolationTest.java @@ -18,28 +18,28 @@ * ============LICENSE_END========================================================= */ - package org.onap.aaf.certservice.certification.configuration.validation.constraints.violations; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class PortNumberViolationTest { private final PortNumberViolation violation = new PortNumberViolation(); @Test - public void givenValidPortShouldReturnTrue() { + void givenValidPortShouldReturnTrue() { //given - String validURL1 = "http://127.0.0.1:8080/ejbca/publicweb/cmp/cmp"; - String validURL2 = "http://127.0.0.1:1/ejbca/publicweb/cmp/cmp"; - String validURL3 = "http://127.0.0.1:65535/ejbca/publicweb/cmp/cmp"; + String validUrl1 = "http://127.0.0.1:8080/ejbca/publicweb/cmp/cmp"; + String validUrl2 = "http://127.0.0.1:1/ejbca/publicweb/cmp/cmp"; + String validUrl3 = "http://127.0.0.1:65535/ejbca/publicweb/cmp/cmp"; //when - boolean result1 = violation.validate(validURL1); - boolean result2 = violation.validate(validURL2); - boolean result3 = violation.validate(validURL3); + boolean result1 = violation.validate(validUrl1); + boolean result2 = violation.validate(validUrl2); + boolean result3 = violation.validate(validUrl3); //then assertTrue(result1); @@ -48,29 +48,29 @@ class PortNumberViolationTest { } @Test - public void givenEmptyPortShouldReturnTrue() { + void givenEmptyPortShouldReturnTrue() { //given - String validURL = "http://127.0.0.1/ejbca/publicweb/cmp/cmp"; + String validUrl = "http://127.0.0.1/ejbca/publicweb/cmp/cmp"; //when - boolean result = violation.validate(validURL); + boolean result = violation.validate(validUrl); //then assertTrue(result); } @Test - public void givenInvalidPortShouldReturnFalse() { + void givenInvalidPortShouldReturnFalse() { //given - String invalidURL1 = "http://127.0.0.1:0/ejbca/publicweb/cmp/cmp"; - String invalidURL2 = "http://127.0.0.1:65536/ejbca/publicweb/cmp/cmp"; + String invalidUrl1 = "http://127.0.0.1:0/ejbca/publicweb/cmp/cmp"; + String invalidUrl2 = "http://127.0.0.1:65536/ejbca/publicweb/cmp/cmp"; //when - boolean result1 = violation.validate(invalidURL1); - boolean result2 = violation.validate(invalidURL2); + boolean result1 = violation.validate(invalidUrl1); + boolean result2 = violation.validate(invalidUrl2); //then assertFalse(result1); assertFalse(result2); } -} \ No newline at end of file +} diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/RequestTypeViolationTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/RequestTypeViolationTest.java index cba2f340..dce66d52 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/RequestTypeViolationTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/constraints/violations/RequestTypeViolationTest.java @@ -22,33 +22,35 @@ package org.onap.aaf.certservice.certification.configuration.validation.constrai import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + class RequestTypeViolationTest { private final RequestTypeViolation violation = new RequestTypeViolation(); @Test - public void givenValidRequestTypeShouldReturnTrue() { + void givenValidRequestTypeShouldReturnTrue() { //given - String validURL = "http://127.0.0.1/ejbca/publicweb/cmp/cmp"; + String validUrl = "http://127.0.0.1/ejbca/publicweb/cmp/cmp"; //when - boolean result = violation.validate(validURL); + boolean result = violation.validate(validUrl); //then assertTrue(result); } @Test - public void givenInvalidRequestTypeShouldReturnFalse() { + void givenInvalidRequestTypeShouldReturnFalse() { //given - String invalidURL = "htestps://127.0.0.1/ejbca/publicweb/cmp/cmp"; + String invalidUrl = "htestps://127.0.0.1/ejbca/publicweb/cmp/cmp"; //when - boolean result = violation.validate(invalidURL); + boolean result = violation.validate(invalidUrl); //then assertFalse(result); } -} \ No newline at end of file +} -- cgit 1.2.3-korg