@Test void testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyButDefaultSecGroupAddedOnly() { Environment environment = new Environment(); environment.setCidr("cidr"); SecurityAccessDto securityAccessDto = SecurityAccessDto.builder() .withDefaultSecurityGroupId("sec-group") .build(); ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment); assertTrue(validationResult.hasError()); assertEquals("1. The CIDR can be replaced with the default and knox security groups, please add to the request", validationResult.getFormattedErrors()); }
public ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> isNotEmpty(securityAccessDto.getCidr()), "The CIDR could not be updated in the environment"); resultBuilder.ifError(() -> isNotEmpty(environment.getCidr()) && isAnySecurityGroupMissing(securityAccessDto), "The CIDR can be replaced with the default and knox security groups, please add to the request"); resultBuilder.ifError(() -> isAllSecurityGroupMissing(securityAccessDto), "Please add the default or knox security groups, we cannot edit with empty value."); return resultBuilder.build(); }
EnvironmentValidatorService { public ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> isNotEmpty(securityAccessDto.getCidr()), "The CIDR could not be updated in the environment"); resultBuilder.ifError(() -> isNotEmpty(environment.getCidr()) && isAnySecurityGroupMissing(securityAccessDto), "The CIDR can be replaced with the default and knox security groups, please add to the request"); resultBuilder.ifError(() -> isAllSecurityGroupMissing(securityAccessDto), "Please add the default or knox security groups, we cannot edit with empty value."); return resultBuilder.build(); } }
EnvironmentValidatorService { public ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> isNotEmpty(securityAccessDto.getCidr()), "The CIDR could not be updated in the environment"); resultBuilder.ifError(() -> isNotEmpty(environment.getCidr()) && isAnySecurityGroupMissing(securityAccessDto), "The CIDR can be replaced with the default and knox security groups, please add to the request"); resultBuilder.ifError(() -> isAllSecurityGroupMissing(securityAccessDto), "Please add the default or knox security groups, we cannot edit with empty value."); return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); }
EnvironmentValidatorService { public ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> isNotEmpty(securityAccessDto.getCidr()), "The CIDR could not be updated in the environment"); resultBuilder.ifError(() -> isNotEmpty(environment.getCidr()) && isAnySecurityGroupMissing(securityAccessDto), "The CIDR can be replaced with the default and knox security groups, please add to the request"); resultBuilder.ifError(() -> isAllSecurityGroupMissing(securityAccessDto), "Please add the default or knox security groups, we cannot edit with empty value."); return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName); ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest); ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment); ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment); ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment); ValidationResult validateFreeIpaCreation(FreeIpaCreationDto freeIpaCreation); }
EnvironmentValidatorService { public ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> isNotEmpty(securityAccessDto.getCidr()), "The CIDR could not be updated in the environment"); resultBuilder.ifError(() -> isNotEmpty(environment.getCidr()) && isAnySecurityGroupMissing(securityAccessDto), "The CIDR can be replaced with the default and knox security groups, please add to the request"); resultBuilder.ifError(() -> isAllSecurityGroupMissing(securityAccessDto), "Please add the default or knox security groups, we cannot edit with empty value."); return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName); ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest); ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment); ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment); ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment); ValidationResult validateFreeIpaCreation(FreeIpaCreationDto freeIpaCreation);  }