diff options
author | Bogumil Zebek <bogumil.zebek@nokia.com> | 2020-03-25 06:03:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-25 06:03:27 +0000 |
commit | 9600d1361dd6e662248fe0704d1436ae56d446a7 (patch) | |
tree | 2b4a65fd0f1fd5b707bef42f251de91705fc6754 /certService/src/test/java | |
parent | 884280dab675f13c48d19b8bda504555b8602a59 (diff) | |
parent | c4047c754b96f63e5c7675969937967aa739bd2f (diff) |
Merge "Add validation for uniqueness of CA names"
Diffstat (limited to 'certService/src/test/java')
-rw-r--r-- | certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java | 7 | ||||
-rw-r--r-- | certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServersConfigurationValidatorTest.java (renamed from certService/src/test/java/org/onap/aaf/certservice/certification/configuration/validation/Cmpv2ServerConfigurationValidatorTest.java) | 40 |
2 files changed, 36 insertions, 11 deletions
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 61970050..87964295 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 @@ -39,7 +39,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; class CmpServersConfigLoaderTest { private static final String EXISTING_CONFIG_FILENAME = "cmpServers.json"; private static final String INVALID_CONFIG_FILENAME = "invalidCmpServers.json"; - private static final String NONEXISTENT_CONFIG_FILENAME = "nonExisting_cmpServers.json"; + private static final String NONEXISTENT_CONFIG_FILENAME = "nonExistingCmpServers.json"; private static final Map<String, String> EXPECTED_FIRST_CMP_SERVER = Map.of( "CA_NAME", "TEST", @@ -99,10 +99,11 @@ class CmpServersConfigLoaderTest { // Then assertThat(exception.getMessage()).contains("Validation of CMPv2 servers configuration failed"); + assertThat(exception.getCause().getMessage()).contains("authentication"); } - private String getResourcePath(String invalidConfigFilename) { - return getClass().getClassLoader().getResource(invalidConfigFilename).getFile(); + private String getResourcePath(String configFilename) { + return getClass().getClassLoader().getResource(configFilename).getFile(); } private void verifyThatCmpServerEquals(Cmpv2Server cmpv2Server, Map<String, String> expected) { 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/Cmpv2ServersConfigurationValidatorTest.java index 1c021b43..6db77753 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/Cmpv2ServersConfigurationValidatorTest.java @@ -20,8 +20,6 @@ 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; @@ -35,28 +33,47 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +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 { +class Cmpv2ServersConfigurationValidatorTest { private static final String EMPTY_STRING = ""; @Autowired - private Cmpv2ServerConfigurationValidator validator; + private Cmpv2ServersConfigurationValidator validator; private Authentication authentication; private Cmpv2Server server; + private List<Cmpv2Server> servers; @BeforeEach private void init() { setAuthentication(); setServerConfiguration(); + servers = new ArrayList<>(); + servers.add(server); } @Test - void shouldNotThrowExceptionWhenServerConfigurationIsValid() { + void shouldThrowExceptionWhenCaNamesAreNotUnique() { + // Given + servers.add(server); + + // When + Exception exception = assertThrows( + InvalidParameterException.class, + () -> validator.validate(servers)); + // Then - assertDoesNotThrow(() -> validator.validate(server)); + assertThat(exception.getMessage()).contains("CA names are not unique within given CMPv2 servers"); } @Test @@ -168,8 +185,14 @@ class Cmpv2ServerConfigurationValidatorTest { assertExceptionIsThrown(); } + @Test + void shouldNotThrowExceptionWhenServerConfigurationIsValid() { + // Then + assertDoesNotThrow(() -> validator.validate(servers)); + } + private void assertExceptionIsThrown() { - assertThrows(IllegalArgumentException.class, () -> validator.validate(server)); + assertThrows(IllegalArgumentException.class, () -> validator.validate(servers)); } private void setServerConfiguration() { @@ -186,4 +209,5 @@ class Cmpv2ServerConfigurationValidatorTest { authentication.setRv("testRV"); authentication.setIak("testIAK"); } -} + +}
\ No newline at end of file |