From 09128196b16368651e8fa2a20140216e086700f2 Mon Sep 17 00:00:00 2001 From: awudzins Date: Tue, 3 Mar 2020 14:51:21 +0100 Subject: Fix reload endpoint to return status Signed-off-by: Adam Wudzinski Issue-ID: AAF-997 wChange-Id: I4563428ef407b4dc8c84c3efc8ec213145806b32 Change-Id: Iee33a26feb5cc1acd39d91ee9f34a49183040e06 --- .../Cmpv2ServerConfigurationValidatorTest.java | 124 ++++++++++++++++----- 1 file changed, 97 insertions(+), 27 deletions(-) (limited to 'certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServerConfigurationValidatorTest.java') 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 18097608..10a7ba46 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 @@ -20,6 +20,9 @@ package org.onap.aaf.certservice.certification.configuration.validation; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.bouncycastle.asn1.x500.X500Name; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,13 +35,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; - @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = CertServiceApplication.class) class Cmpv2ServerConfigurationValidatorTest { + private static final String EMPTY_STRING = ""; + @Autowired private Cmpv2ServerConfigurationValidator validator; @@ -52,53 +54,121 @@ class Cmpv2ServerConfigurationValidatorTest { } @Test - public void givenValidServerDetailsWhenValidatingShouldNotThrowAnyException() { - //then + public void shouldNotThrowExceptionWhenServerConfigurationIsValid() { + // Then assertDoesNotThrow(() -> validator.validate(server)); } @Test - public void givenWrongProtocolInURLServerDetailsWhenValidatingShouldThrowException() { - //given + public void shouldThrowExceptionWhenWrongProtocolInURL() { + // Given server.setUrl("https://test.test.test:60000/"); - //then - assertThrows(IllegalArgumentException.class, () -> {validator.validate(server);}); + // Then + assertExceptionIsThrown(); } @Test - public void givenWrongPortInURLServerDetailsWhenValidatingShouldThrowException() { - //given + public void shouldThrowExceptionWhenWrongPortInURL() { + // Given server.setUrl("http://test.test.test:70000/"); - //then - assertThrows(IllegalArgumentException.class, () -> validator.validate(server)); + // Then + assertExceptionIsThrown(); } @Test - public void givenWrongCANameLengthInURLServerDetailsWhenValidatingShouldThrowException() { - //given - server.setCaName(""); + public void shouldThrowExceptionWhenWrongCANameLength() { + // Given + server.setCaName(EMPTY_STRING); - //then - assertThrows(IllegalArgumentException.class, () -> validator.validate(server)); + // Then + assertExceptionIsThrown(); } @Test - public void givenWrongRVLengthInURLServerDetailsWhenValidatingShouldThrowException() { - //given - authentication.setRv(""); + public void shouldThrowExceptionWhenWrongRVLength() { + // Given + authentication.setRv(EMPTY_STRING); - //then - assertThrows(IllegalArgumentException.class, () -> validator.validate(server)); + // Then + assertExceptionIsThrown(); } + @Test - public void givenWrongIAKLengthInURLServerDetailsWhenValidatingShouldThrowException() { - //given - authentication.setIak(""); + public void shouldThrowExceptionWhenWrongIAKLength() { + // Given + authentication.setIak(EMPTY_STRING); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenCaNameIsNull() { + // Given + server.setCaName(null); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenIssuerDnIsNull() { + // Given + server.setIssuerDN(null); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenCaModeIsNull() { + // Given + server.setCaMode(null); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenUrlIsNull() { + // Given + server.setUrl(null); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenAuthenticationIsNull() { + // Given + server.setAuthentication(null); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenIakIsNull() { + // Given + authentication.setIak(null); + + // Then + assertExceptionIsThrown(); + } + + @Test + public void shouldThrowExceptionWhenRvIsNull() { + // Given + authentication.setRv(null); + + // Then + assertExceptionIsThrown(); + } - //then + private void assertExceptionIsThrown() { assertThrows(IllegalArgumentException.class, () -> validator.validate(server)); } -- cgit 1.2.3-korg