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.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
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() {
authentication.setRv("testRV");
authentication.setIak("testIAK");
}
-}
+
+}
\ No newline at end of file